Browse Source

differentiate errors while printing or detecting printer

Thomas B 3 weeks ago
parent
commit
a6e0daf325
4 changed files with 11 additions and 5 deletions
  1. 1
    1
      src/gbprinter.c
  2. 3
    0
      src/gbprinter.h
  3. 6
    3
      src/gbprinter_error.c
  4. 1
    1
      src/main.c

+ 1
- 1
src/gbprinter.c View File

172
 #ifdef DEBUG
172
 #ifdef DEBUG
173
     EMU_printf("%s: 0x%04x\n",  __func__, (uint16_t)r);
173
     EMU_printf("%s: 0x%04x\n",  __func__, (uint16_t)r);
174
 #endif // DEBUG
174
 #endif // DEBUG
175
-    return r;
175
+    return r | PRN_STATUS_DETECT;
176
 }
176
 }
177
 
177
 
178
 static void win_str_helper(const char *s, uint8_t y_pos) {
178
 static void win_str_helper(const char *s, uint8_t y_pos) {

+ 3
- 0
src/gbprinter.h View File

43
     PRN_STATUS_TIMEOUT     = 0x200, // timeout waiting for printer response
43
     PRN_STATUS_TIMEOUT     = 0x200, // timeout waiting for printer response
44
     PRN_STATUS_NO_MAGIC    = 0x400, // printer did not respond with proper 'alive'
44
     PRN_STATUS_NO_MAGIC    = 0x400, // printer did not respond with proper 'alive'
45
 
45
 
46
+    // status flags for user code
47
+    PRN_STATUS_DETECT      = 0x800, // set in gbprinter_detect
48
+
46
     // masks to check for errors
49
     // masks to check for errors
47
     PRN_STATUS_MASK_ERRORS = 0x7F0,
50
     PRN_STATUS_MASK_ERRORS = 0x7F0,
48
     PRN_STATUS_MASK_ANY    = 0x7FF,
51
     PRN_STATUS_MASK_ANY    = 0x7FF,

+ 6
- 3
src/gbprinter_error.c View File

29
 
29
 
30
 BANKREF(gbprinter_error)
30
 BANKREF(gbprinter_error)
31
 
31
 
32
-#define ERROR_BITS 11
32
+#define ERROR_BITS 12
33
+
34
+static const char str_ok[] = "ok";
33
 
35
 
34
 static const char str_lowbat[] = "battery too low";
36
 static const char str_lowbat[] = "battery too low";
35
 static const char str_er2[] = "unknown error";
37
 static const char str_er2[] = "unknown error";
42
 static const char str_cancel[] = "cancelled";
44
 static const char str_cancel[] = "cancelled";
43
 static const char str_timeout[] = "timeout";
45
 static const char str_timeout[] = "timeout";
44
 static const char str_magic[] = "wrong magic byte";
46
 static const char str_magic[] = "wrong magic byte";
47
+static const char str_detect[] = "@ detection";
45
 
48
 
46
 static const char * const error_strings[ERROR_BITS] = {
49
 static const char * const error_strings[ERROR_BITS] = {
47
     str_sum, str_busy, str_full, str_untran,
50
     str_sum, str_busy, str_full, str_untran,
48
     str_er0, str_er1, str_er2, str_lowbat,
51
     str_er0, str_er1, str_er2, str_lowbat,
49
-    str_cancel, str_timeout, str_magic,
52
+    str_cancel, str_timeout, str_magic, str_detect,
50
 };
53
 };
51
 
54
 
52
 uint8_t gbprinter_error(enum PRN_STATUS status, char *buff) BANKED {
55
 uint8_t gbprinter_error(enum PRN_STATUS status, char *buff) BANKED {
53
     if (status == PRN_STATUS_OK) {
56
     if (status == PRN_STATUS_OK) {
54
-        sprintf(buff, "ok");
57
+        sprintf(buff, str_ok);
55
         return 2;
58
         return 2;
56
     }
59
     }
57
 
60
 

+ 1
- 1
src/main.c View File

94
             break;
94
             break;
95
         } else if (key_pressed(J_SELECT)) {
95
         } else if (key_pressed(J_SELECT)) {
96
             enum PRN_STATUS status = gbprinter_detect();
96
             enum PRN_STATUS status = gbprinter_detect();
97
-            if (status == PRN_STATUS_OK) {
97
+            if ((status & PRN_STATUS_MASK_ANY) == PRN_STATUS_OK) {
98
                 win_score_clear(is_black, 1);
98
                 win_score_clear(is_black, 1);
99
                 list_scores(is_black);
99
                 list_scores(is_black);
100
                 status = gbprinter_screenshot(1, is_black ? PRN_PALETTE_SC_B : PRN_PALETTE_SC_W);
100
                 status = gbprinter_screenshot(1, is_black ? PRN_PALETTE_SC_B : PRN_PALETTE_SC_W);

Loading…
Cancel
Save