Browse Source

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

Thomas Buck 11 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
 
31
 
32
 #ifdef MENU_PREFER_VOLCANO
32
 #ifdef MENU_PREFER_VOLCANO
33
 #define VOLCANO_AUTO_CONNECT_TIMEOUT_MS 2000
33
 #define VOLCANO_AUTO_CONNECT_TIMEOUT_MS 2000
34
+#define VOLCANO_AUTO_CONNECT_WITHIN_MS 10000
34
 #endif // MENU_PREFER_VOLCANO
35
 #endif // MENU_PREFER_VOLCANO
35
 
36
 
36
 #endif // NDEBUG
37
 #endif // NDEBUG

+ 3
- 0
include/lcd.h View File

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

+ 2
- 1
src/buttons.c View File

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

+ 8
- 0
src/console.c View File

171
                         bd_addr_to_str(results[i].addr),
171
                         bd_addr_to_str(results[i].addr),
172
                         results[i].type, results[i].rssi,
172
                         results[i].type, results[i].rssi,
173
                         age / 1000.0, results[i].name, info);
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
     } else if (str_startswith(line, "con ")) {
184
     } else if (str_startswith(line, "con ")) {

+ 2
- 2
src/lcd.c View File

34
 #define LCD_PIN_RST 12
34
 #define LCD_PIN_RST 12
35
 #define LCD_PIN_BL 13
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
 #define ST7789_PICO_ACCESS                            (ST7789_ORDER_PAGE_TOP_TO_BOTTOM | \
40
 #define ST7789_PICO_ACCESS                            (ST7789_ORDER_PAGE_TOP_TO_BOTTOM | \
41
                                                        ST7789_ORDER_COLUMN_LEFT_TO_RIGHT | \
41
                                                        ST7789_ORDER_COLUMN_LEFT_TO_RIGHT | \

+ 0
- 7
src/mem.c View File

79
 
79
 
80
 void mem_load_defaults(void) {
80
 void mem_load_defaults(void) {
81
     data_ram.data.wf_count = wf_default_count;
81
     data_ram.data.wf_count = wf_default_count;
82
-    debug("preparing %d default workflows", data_ram.data.wf_count);
83
     for (uint16_t i = 0; i < wf_default_count; i++) {
82
     for (uint16_t i = 0; i < wf_default_count; i++) {
84
         data_ram.data.wf[i] = wf_default_data[i];
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
     } else {
106
     } else {
109
         debug("invalid config (0x%02X != 0x%02X)", flash_ptr->version, MEM_VERSION);
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
 static void mem_write_flash(void *param) {
111
 static void mem_write_flash(void *param) {

+ 9
- 2
src/state_scan.c View File

100
 #ifdef MENU_PREFER_VOLCANO
100
 #ifdef MENU_PREFER_VOLCANO
101
             if (dev == DEV_VOLCANO) {
101
             if (dev == DEV_VOLCANO) {
102
                 menu->selection = devs - 1;
102
                 menu->selection = devs - 1;
103
+
103
 #ifdef VOLCANO_AUTO_CONNECT_TIMEOUT_MS
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
 #endif // VOLCANO_AUTO_CONNECT_TIMEOUT_MS
113
 #endif // VOLCANO_AUTO_CONNECT_TIMEOUT_MS
107
             }
114
             }
108
 #endif // MENU_PREFER_VOLCANO
115
 #endif // MENU_PREFER_VOLCANO

+ 9
- 10
src/text.c View File

166
         text_prepare_font(&font);
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
     struct text_conf text = {
175
     struct text_conf text = {
176
         .text = "",
176
         .text = "",
177
-        .x = x,
178
-        .y = y,
177
+        .x = x_off,
178
+        .y = y_off,
179
         .justify = false,
179
         .justify = false,
180
         .alignment = centered ? MF_ALIGN_CENTER : MF_ALIGN_LEFT,
180
         .alignment = centered ? MF_ALIGN_CENTER : MF_ALIGN_LEFT,
181
         .width = width,
181
         .width = width,
186
         .font = &font,
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
                    RGB_565(0x00, 0x00, 0x00));
192
                    RGB_565(0x00, 0x00, 0x00));
194
 
193
 
195
     text.text = s;
194
     text.text = s;

Loading…
Cancel
Save