Browse Source

only auto connect when device is visible within 10s of boot

Thomas Buck 2 months ago
parent
commit
11483f370b
8 changed files with 34 additions and 22 deletions
  1. 1
    0
      include/config.h
  2. 3
    0
      include/lcd.h
  3. 2
    1
      src/buttons.c
  4. 8
    0
      src/console.c
  5. 2
    2
      src/lcd.c
  6. 0
    7
      src/mem.c
  7. 9
    2
      src/state_scan.c
  8. 9
    10
      src/text.c

+ 1
- 0
include/config.h View File

@@ -31,6 +31,7 @@
31 31
 
32 32
 #ifdef MENU_PREFER_VOLCANO
33 33
 #define VOLCANO_AUTO_CONNECT_TIMEOUT_MS 2000
34
+#define VOLCANO_AUTO_CONNECT_WITHIN_MS 10000
34 35
 #endif // MENU_PREFER_VOLCANO
35 36
 
36 37
 #endif // NDEBUG

+ 3
- 0
include/lcd.h View File

@@ -21,6 +21,9 @@
21 21
 
22 22
 #include <stdint.h>
23 23
 
24
+#define LCD_WIDTH 240
25
+#define LCD_HEIGHT 240
26
+
24 27
 #define RGB_565(r, g, b) ( \
25 28
       (((r) >> 3) << 11)   \
26 29
     | (((g) >> 2) << 5)    \

+ 2
- 1
src/buttons.c View File

@@ -69,8 +69,9 @@ void buttons_run(void) {
69 69
 
70 70
         if ((now - buttons[i].last_time) > DEBOUNCE_DELAY_MS) {
71 71
             if (state != buttons[i].current_state) {
72
+                //debug("btn %d now %s", i, state ? "pressed" : "released");
73
+
72 74
                 buttons[i].current_state = state;
73
-                debug("btn %d now %s", i, state ? "pressed" : "released");
74 75
                 if (callback) {
75 76
                     callback(i, state);
76 77
                 }

+ 8
- 0
src/console.c View File

@@ -171,6 +171,14 @@ static void cnsl_interpret(const char *line) {
171 171
                         bd_addr_to_str(results[i].addr),
172 172
                         results[i].type, results[i].rssi,
173 173
                         age / 1000.0, results[i].name, info);
174
+
175
+                if (results[i].data_len > 0) {
176
+                    hexdump(results[i].data, results[i].data_len);
177
+                }
178
+
179
+                if (i < (n - 1)) {
180
+                    println();
181
+                }
174 182
             }
175 183
         }
176 184
     } else if (str_startswith(line, "con ")) {

+ 2
- 2
src/lcd.c View File

@@ -34,8 +34,8 @@
34 34
 #define LCD_PIN_RST 12
35 35
 #define LCD_PIN_BL 13
36 36
 
37
-#define ST7789_PICO_COLUMN                             240
38
-#define ST7789_PICO_ROW                                ST7789_PICO_COLUMN
37
+#define ST7789_PICO_COLUMN                             LCD_HEIGHT
38
+#define ST7789_PICO_ROW                                LCD_WIDTH
39 39
 
40 40
 #define ST7789_PICO_ACCESS                            (ST7789_ORDER_PAGE_TOP_TO_BOTTOM | \
41 41
                                                        ST7789_ORDER_COLUMN_LEFT_TO_RIGHT | \

+ 0
- 7
src/mem.c View File

@@ -79,10 +79,8 @@ static uint32_t calc_checksum(const struct mem_contents *data) {
79 79
 
80 80
 void mem_load_defaults(void) {
81 81
     data_ram.data.wf_count = wf_default_count;
82
-    debug("preparing %d default workflows", data_ram.data.wf_count);
83 82
     for (uint16_t i = 0; i < wf_default_count; i++) {
84 83
         data_ram.data.wf[i] = wf_default_data[i];
85
-        debug("\"%s\" by \"%s\"", data_ram.data.wf[i].name, data_ram.data.wf[i].author);
86 84
     }
87 85
 }
88 86
 
@@ -108,11 +106,6 @@ void mem_init(void) {
108 106
     } else {
109 107
         debug("invalid config (0x%02X != 0x%02X)", flash_ptr->version, MEM_VERSION);
110 108
     }
111
-
112
-    debug("found %d workflows", data_ram.data.wf_count);
113
-    for (uint16_t i = 0; i < data_ram.data.wf_count; i++) {
114
-        debug("\"%s\" by \"%s\"", data_ram.data.wf[i].name, data_ram.data.wf[i].author);
115
-    }
116 109
 }
117 110
 
118 111
 static void mem_write_flash(void *param) {

+ 9
- 2
src/state_scan.c View File

@@ -100,9 +100,16 @@ static void draw(struct menu_state *menu) {
100 100
 #ifdef MENU_PREFER_VOLCANO
101 101
             if (dev == DEV_VOLCANO) {
102 102
                 menu->selection = devs - 1;
103
+
103 104
 #ifdef VOLCANO_AUTO_CONNECT_TIMEOUT_MS
104
-                auto_connect_time = to_ms_since_boot(get_absolute_time());
105
-                auto_connect_idx = i;
105
+#ifdef VOLCANO_AUTO_CONNECT_WITHIN_MS
106
+                if (to_ms_since_boot(get_absolute_time()) <= VOLCANO_AUTO_CONNECT_WITHIN_MS) {
107
+#endif // VOLCANO_AUTO_CONNECT_WITHIN_MS
108
+                    auto_connect_time = to_ms_since_boot(get_absolute_time());
109
+                    auto_connect_idx = i;
110
+#ifdef VOLCANO_AUTO_CONNECT_WITHIN_MS
111
+                }
112
+#endif // VOLCANO_AUTO_CONNECT_WITHIN_MS
106 113
 #endif // VOLCANO_AUTO_CONNECT_TIMEOUT_MS
107 114
             }
108 115
 #endif // MENU_PREFER_VOLCANO

+ 9
- 10
src/text.c View File

@@ -166,16 +166,16 @@ void text_box(const char *s, bool centered) {
166 166
         text_prepare_font(&font);
167 167
     }
168 168
 
169
-    int x = 0;
170
-    int width = 240;
169
+    int x_off = 0;
170
+    int width = LCD_WIDTH;
171 171
 
172
-    int y = 50;
173
-    int height = MENU_MAX_LINES * (20 + 2);
172
+    int y_off = 50;
173
+    int height = (MENU_MAX_LINES * 20) + ((MENU_MAX_LINES - 1) * 2);
174 174
 
175 175
     struct text_conf text = {
176 176
         .text = "",
177
-        .x = x,
178
-        .y = y,
177
+        .x = x_off,
178
+        .y = y_off,
179 179
         .justify = false,
180 180
         .alignment = centered ? MF_ALIGN_CENTER : MF_ALIGN_LEFT,
181 181
         .width = width,
@@ -186,10 +186,9 @@ void text_box(const char *s, bool centered) {
186 186
         .font = &font,
187 187
     };
188 188
 
189
-    lcd_write_rect(x,
190
-                   y,
191
-                   x + width - 1,
192
-                   y + height - 1,
189
+    lcd_write_rect(x_off, y_off,
190
+                   x_off + width - 1,
191
+                   y_off + height - 1,
193 192
                    RGB_565(0x00, 0x00, 0x00));
194 193
 
195 194
     text.text = s;

Loading…
Cancel
Save