Browse Source

small tweaks

Thomas Buck 2 weeks ago
parent
commit
97d9f4a9ef
5 changed files with 47 additions and 17 deletions
  1. 1
    0
      flash.sh
  2. 16
    5
      src/adc.c
  3. 2
    2
      src/lcd.c
  4. 5
    3
      src/main.c
  5. 23
    7
      src/ui.c

+ 1
- 0
flash.sh View File

@@ -26,6 +26,7 @@ if [ ! -e $DISK ]
26 26
 then
27 27
     echo Resetting Raspberry Pi Pico
28 28
     echo -n -e "\\x18" > $SERIAL
29
+    echo -n -e "\\x18" > $SERIAL
29 30
 fi
30 31
 
31 32
 echo -n Waiting for disk to appear

+ 16
- 5
src/adc.c View File

@@ -32,16 +32,27 @@
32 32
 #define BAT_R1 10000.0f
33 33
 #define BAT_R2 18000.0f
34 34
 
35
+#define FILTER_OLD 0.75f
36
+#define FILTER_NEW (1.0f - FILTER_OLD)
37
+
38
+static float filtered = 0.0f;
39
+
40
+static float bat_read(void) {
41
+    float v_adc = adc_read() * ADC_CONVERT;
42
+
43
+    // Vadc = Vbat * R2 / (R1 + R2)
44
+    float v_bat = v_adc / (BAT_R2 / (BAT_R1 + BAT_R2));
45
+    return v_bat;
46
+}
47
+
35 48
 void bat_init(void) {
36 49
     adc_init();
37 50
     adc_gpio_init( ADC_PIN);
38 51
     adc_select_input( ADC_NUM);
52
+    filtered = bat_read();
39 53
 }
40 54
 
41 55
 float bat_get(void) {
42
-    float v_adc = adc_read() * ADC_CONVERT;
43
-
44
-    // Vadc = Vbat * R2 / (R1 + R2)
45
-    float v_bat = v_adc / (BAT_R2 / (BAT_R1 + BAT_R2));
46
-    return v_bat;
56
+    filtered = (filtered * FILTER_OLD) + (bat_read() * FILTER_NEW);
57
+    return filtered;
47 58
 }

+ 2
- 2
src/lcd.c View File

@@ -119,7 +119,7 @@ void lcd_draw(const char *mode, const char *val, const char *bat) {
119 119
 
120 120
 void lcd_draw_bye(void) {
121 121
     ssd1306_clear(&disp);
122
-    ssd1306_draw_string(&disp, 0, 0, 3, "Boot");
123
-    ssd1306_draw_string(&disp, 0, LCD_HEIGHT / 2, 3, "loader");
122
+    ssd1306_draw_string(&disp, 6, 5, 3, " Boot-");
123
+    ssd1306_draw_string(&disp, 8, LCD_HEIGHT / 2 + 5, 3, "loader");
124 124
     ssd1306_show(&disp);
125 125
 }

+ 5
- 3
src/main.c View File

@@ -32,7 +32,7 @@
32 32
 #include "main.h"
33 33
 
34 34
 #define WATCHDOG_PERIOD_MS 100
35
-#define LOGO_INIT_MS 1500
35
+#define LOGO_INIT_MS 1000
36 36
 
37 37
 static const uint gpio_hw_detect = 21;
38 38
 
@@ -89,9 +89,11 @@ int main(void) {
89 89
         sleep_ms(1);
90 90
     }
91 91
 
92
-    if (debug_buttons[BTN_REC]) {
92
+    if (debug_buttons[BTN_REC] && debug_buttons[BTN_CLICK]) {
93 93
         lcd_debug_buttons();
94
-    } else if (!debug_buttons[BTN_H]) {
94
+    } else if (debug_buttons[BTN_REC] && (!debug_buttons[BTN_CLICK])) {
95
+        // skip splash screen
96
+    } else {
95 97
         // show splash for a bit and animate LEDs
96 98
         for (uint i = 0; i < LED_COUNT; i++) {
97 99
             handle_serial_input();

+ 23
- 7
src/ui.c View File

@@ -18,6 +18,7 @@
18 18
 
19 19
 #include <stdio.h>
20 20
 #include <inttypes.h>
21
+#include <math.h>
21 22
 #include "pico/stdlib.h"
22 23
 
23 24
 #include "adc.h"
@@ -27,12 +28,13 @@
27 28
 #include "sequence.h"
28 29
 #include "ui.h"
29 30
 
30
-#define REDRAW_MS 2000
31
+#define BAT_FETCH_MS 66
31 32
 
32 33
 static bool rec_held_down = false;
33 34
 static enum ui_modes ui_mode = 0;
34 35
 static enum machine_modes machine_mode = 0;
35
-static uint32_t last_redraw = 0;
36
+static uint32_t last_bat_fetch = 0;
37
+static float last_voltage = 0.0f;
36 38
 
37 39
 enum machine_modes ui_get_machinemode(void) {
38 40
     return machine_mode;
@@ -97,7 +99,7 @@ static void ui_redraw(void) {
97 99
         }
98 100
     }
99 101
 
100
-    snprintf(bat, sizeof(bat) - 1, "Bat: %.2fV", bat_get());
102
+    snprintf(bat, sizeof(bat) - 1, "Bat: %.2fV", last_voltage);
101 103
     lcd_draw(mode, val, bat);
102 104
 }
103 105
 
@@ -115,11 +117,20 @@ static void ui_buttons_loopstation(enum buttons btn, bool val) {
115 117
             break;
116 118
         }
117 119
 
118
-        case BTN_REC:
120
+        case BTN_REC: {
121
+            // reset sequence
122
+            sequence_init();
123
+            ui_redraw();
124
+            break;
125
+        }
126
+
119 127
         case BTN_D:
120 128
         case BTN_H: {
121 129
             rec_held_down = val;
122 130
             sequence_looptime(!val);
131
+            if (!val) {
132
+                ui_redraw();
133
+            }
123 134
             break;
124 135
         }
125 136
 
@@ -271,8 +282,13 @@ void ui_init(void) {
271 282
 
272 283
 void ui_run(void) {
273 284
     uint32_t now = to_ms_since_boot(get_absolute_time());
274
-    if (now >= (last_redraw + REDRAW_MS)) {
275
-        ui_redraw();
276
-        last_redraw = now;
285
+    if (now >= (last_bat_fetch + BAT_FETCH_MS)) {
286
+        last_bat_fetch = now;
287
+
288
+        float volt = bat_get();
289
+        if (fabsf(volt - last_voltage) >= 0.01f) {
290
+            last_voltage = volt;
291
+            ui_redraw();
292
+        }
277 293
     }
278 294
 }

Loading…
Cancel
Save