Browse Source

fix read/write of special symbols via I2C

Thomas Buck 3 weeks ago
parent
commit
9b3b5e21b4
1 changed files with 12 additions and 12 deletions
  1. 12
    12
      src/Functionality.cpp

+ 12
- 12
src/Functionality.cpp View File

@@ -196,7 +196,7 @@ void input_serial(void) {
196 196
 
197 197
 void ui_i2c_request(void) {
198 198
     if (keybuffer.isEmpty()) {
199
-        Wire.write(-4);
199
+        Wire.write(252);
200 200
         return;
201 201
     }
202 202
     
@@ -205,11 +205,12 @@ void ui_i2c_request(void) {
205 205
     while (!keybuffer.isEmpty()) {
206 206
         int n = keybuffer.shift();
207 207
         
208
-        // for some reason it seems as if we always get -1 here,
209
-        // so we cant send our input (-2 to 9) as is.
210
-        // so -4 is no-data, -3 is -1, and the rest as-is.
211 208
         if (n == -1) {
212
-            n = -3;
209
+            n = 254;
210
+        } else if (n == -2) {
211
+            n = 253;
212
+        } else if ((n < 0) || (n > 9)) {
213
+            continue;
213 214
         }
214 215
         
215 216
         debug.print(n);
@@ -460,20 +461,19 @@ void control_run(void) {
460 461
     
461 462
     Wire.requestFrom(OWN_I2C_ADDRESS, I2C_BUF_SIZE);
462 463
     while (Wire.available()) {
463
-        char c = Wire.read();
464
+        int c = Wire.read();
464 465
         
466
+        if (((c >= 0) && (c <= 9)) || (c == 254) || (c == 253)) {
465 467
             debug.print("control_run: got input '");
466 468
             debug.print(c);
467 469
             debug.println("'");
468
-        // for some reason it seems as if we always get -1 here,
469
-        // so we cant send our input (-2 to 9) as is.
470
-        // so -4 is no-data, -3 is -1, and the rest as-is.
471
-        if ((c >= -3) && (c <= 9) && (c != -1)) {
472
-            if (c == -3) {
470
+            
471
+            if (c == 254) {
473 472
                 c = -1;
473
+            } else if (c == 253) {
474
+                c = -2;
474 475
             }
475 476
         
476
-        
477 477
             sm.input(c);
478 478
         }
479 479
     }

Loading…
Cancel
Save