Browse Source

small tweaks

Thomas Buck 7 months 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
 then
26
 then
27
     echo Resetting Raspberry Pi Pico
27
     echo Resetting Raspberry Pi Pico
28
     echo -n -e "\\x18" > $SERIAL
28
     echo -n -e "\\x18" > $SERIAL
29
+    echo -n -e "\\x18" > $SERIAL
29
 fi
30
 fi
30
 
31
 
31
 echo -n Waiting for disk to appear
32
 echo -n Waiting for disk to appear

+ 16
- 5
src/adc.c View File

32
 #define BAT_R1 10000.0f
32
 #define BAT_R1 10000.0f
33
 #define BAT_R2 18000.0f
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
 void bat_init(void) {
48
 void bat_init(void) {
36
     adc_init();
49
     adc_init();
37
     adc_gpio_init( ADC_PIN);
50
     adc_gpio_init( ADC_PIN);
38
     adc_select_input( ADC_NUM);
51
     adc_select_input( ADC_NUM);
52
+    filtered = bat_read();
39
 }
53
 }
40
 
54
 
41
 float bat_get(void) {
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
 
119
 
120
 void lcd_draw_bye(void) {
120
 void lcd_draw_bye(void) {
121
     ssd1306_clear(&disp);
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
     ssd1306_show(&disp);
124
     ssd1306_show(&disp);
125
 }
125
 }

+ 5
- 3
src/main.c View File

32
 #include "main.h"
32
 #include "main.h"
33
 
33
 
34
 #define WATCHDOG_PERIOD_MS 100
34
 #define WATCHDOG_PERIOD_MS 100
35
-#define LOGO_INIT_MS 1500
35
+#define LOGO_INIT_MS 1000
36
 
36
 
37
 static const uint gpio_hw_detect = 21;
37
 static const uint gpio_hw_detect = 21;
38
 
38
 
89
         sleep_ms(1);
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
         lcd_debug_buttons();
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
         // show splash for a bit and animate LEDs
97
         // show splash for a bit and animate LEDs
96
         for (uint i = 0; i < LED_COUNT; i++) {
98
         for (uint i = 0; i < LED_COUNT; i++) {
97
             handle_serial_input();
99
             handle_serial_input();

+ 23
- 7
src/ui.c View File

18
 
18
 
19
 #include <stdio.h>
19
 #include <stdio.h>
20
 #include <inttypes.h>
20
 #include <inttypes.h>
21
+#include <math.h>
21
 #include "pico/stdlib.h"
22
 #include "pico/stdlib.h"
22
 
23
 
23
 #include "adc.h"
24
 #include "adc.h"
27
 #include "sequence.h"
28
 #include "sequence.h"
28
 #include "ui.h"
29
 #include "ui.h"
29
 
30
 
30
-#define REDRAW_MS 2000
31
+#define BAT_FETCH_MS 66
31
 
32
 
32
 static bool rec_held_down = false;
33
 static bool rec_held_down = false;
33
 static enum ui_modes ui_mode = 0;
34
 static enum ui_modes ui_mode = 0;
34
 static enum machine_modes machine_mode = 0;
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
 enum machine_modes ui_get_machinemode(void) {
39
 enum machine_modes ui_get_machinemode(void) {
38
     return machine_mode;
40
     return machine_mode;
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
     lcd_draw(mode, val, bat);
103
     lcd_draw(mode, val, bat);
102
 }
104
 }
103
 
105
 
115
             break;
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
         case BTN_D:
127
         case BTN_D:
120
         case BTN_H: {
128
         case BTN_H: {
121
             rec_held_down = val;
129
             rec_held_down = val;
122
             sequence_looptime(!val);
130
             sequence_looptime(!val);
131
+            if (!val) {
132
+                ui_redraw();
133
+            }
123
             break;
134
             break;
124
         }
135
         }
125
 
136
 
271
 
282
 
272
 void ui_run(void) {
283
 void ui_run(void) {
273
     uint32_t now = to_ms_since_boot(get_absolute_time());
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