Ver código fonte

clear text box bg. fix ble disconnect and workflow notify.

Thomas Buck 1 ano atrás
pai
commit
01259255e8
4 arquivos alterados com 47 adições e 44 exclusões
  1. 5
    1
      src/ble.c
  2. 16
    3
      src/state_volcano_run.c
  3. 15
    5
      src/text.c
  4. 11
    35
      src/workflow.c

+ 5
- 1
src/ble.c Ver arquivo

@@ -491,7 +491,11 @@ bool ble_is_connected(void) {
491 491
 
492 492
     bool v = (state == TC_READY)
493 493
              || (state == TC_W4_READ)
494
-             || (state == TC_READ_COMPLETE);
494
+             || (state == TC_READ_COMPLETE)
495
+             || (state == TC_W4_SERVICE)
496
+             || (state == TC_W4_CHARACTERISTIC)
497
+             || (state == TC_W4_WRITE)
498
+             || (state == TC_WRITE_COMPLETE);
495 499
 
496 500
     cyw43_thread_exit();
497 501
     return v;

+ 16
- 3
src/state_volcano_run.c Ver arquivo

@@ -20,6 +20,7 @@
20 20
 #include <string.h>
21 21
 
22 22
 #include "config.h"
23
+#include "log.h"
23 24
 #include "workflow.h"
24 25
 #include "state.h"
25 26
 #include "state_volcano_run.h"
@@ -30,6 +31,7 @@ static uint16_t wf_index;
30 31
 static bd_addr_t ble_addr;
31 32
 static bd_addr_type_t ble_type;
32 33
 static bool wait_for_connect = false;
34
+static bool wait_for_disconnect = false;
33 35
 
34 36
 void state_volcano_run_index(uint16_t index) {
35 37
     wf_index = index;
@@ -41,13 +43,13 @@ void state_volcano_run_target(bd_addr_t addr, bd_addr_type_t type) {
41 43
 }
42 44
 
43 45
 void state_volcano_run_enter(void) {
46
+    debug("workflow connect");
44 47
     ble_connect(ble_addr, ble_type);
45 48
     wait_for_connect = true;
46 49
 }
47 50
 
48 51
 void state_volcano_run_exit(void) {
49 52
     wf_reset();
50
-    ble_disconnect();
51 53
 }
52 54
 
53 55
 static void draw(struct menu_state *menu) {
@@ -58,13 +60,24 @@ static void draw(struct menu_state *menu) {
58 60
 void state_volcano_run_run(void) {
59 61
     if (wait_for_connect && ble_is_connected()) {
60 62
         wait_for_connect = false;
63
+        debug("workflow start");
61 64
         wf_start(wf_index);
62 65
     }
63 66
 
64 67
     menu_run(draw);
65 68
 
66
-    struct wf_state state = wf_status();
67
-    if (state.status == WF_IDLE) {
69
+    if (!wait_for_connect) {
70
+        struct wf_state state = wf_status();
71
+        if (state.status == WF_IDLE) {
72
+            debug("workflow disconnect");
73
+            ble_disconnect();
74
+            wait_for_disconnect = true;
75
+        }
76
+    }
77
+
78
+    if (wait_for_disconnect && !ble_is_connected()) {
79
+        wait_for_disconnect = false;
80
+        debug("workflow done");
68 81
         state_switch(STATE_SCAN);
69 82
     }
70 83
 }

+ 15
- 5
src/text.c Ver arquivo

@@ -161,21 +161,31 @@ void text_box(const char *s) {
161 161
         text_prepare_font(&font);
162 162
     }
163 163
 
164
+    int x = 0;
165
+    int width = 240;
166
+
167
+    int y = 50;
168
+    int height = 120;
169
+
164 170
     struct text_conf text = {
165 171
         .text = "",
166
-        .x = 0,
167
-        .y = 50,
172
+        .x = x,
173
+        .y = y,
168 174
         .justify = false,
169 175
         .alignment = MF_ALIGN_CENTER,
170
-        .width = 240,
171
-        .height = 240 - 80,
176
+        .width = width,
177
+        .height = height,
172 178
         .margin = 2,
173 179
         .fg = RGB_565(0xFF, 0xFF, 0xFF),
174 180
         .bg = RGB_565(0x00, 0x00, 0x00),
175 181
         .font = &font,
176 182
     };
177 183
 
178
-    // TODO clear background?!
184
+    lcd_write_rect(240 - y - 1 - height,
185
+                   x,
186
+                   240 - y - 1,
187
+                   x + width - 1,
188
+                   text.bg);
179 189
 
180 190
     text.text = s;
181 191
     text_draw(&text);

+ 11
- 35
src/workflow.c Ver arquivo

@@ -43,6 +43,10 @@ struct workflow {
43 43
     uint16_t count;
44 44
 };
45 45
 
46
+#define NOTIFY \
47
+    { .op = OP_WAIT_TIME, .val = 1000 }, \
48
+    { .op = OP_PUMP_TIME, .val = 1000 }
49
+
46 50
 static const struct workflow wf[WF_MAX_FLOWS] = {
47 51
     {
48 52
         .name = "Default",
@@ -60,17 +64,7 @@ static const struct workflow wf[WF_MAX_FLOWS] = {
60 64
             { .op = OP_WAIT_TIME, .val = 5000 },
61 65
             { .op = OP_PUMP_TIME, .val = 20000 },
62 66
 
63
-            { .op = OP_PUMP_TIME, .val = 1000 },
64
-            { .op = OP_WAIT_TIME, .val = 1000 },
65
-
66
-            { .op = OP_PUMP_TIME, .val = 1000 },
67
-            { .op = OP_WAIT_TIME, .val = 1000 },
68
-
69
-            { .op = OP_PUMP_TIME, .val = 1000 },
70
-            { .op = OP_WAIT_TIME, .val = 1000 },
71
-
72
-            { .op = OP_PUMP_TIME, .val = 1000 },
73
-            { .op = OP_WAIT_TIME, .val = 1000 },
67
+            NOTIFY, NOTIFY, NOTIFY, NOTIFY,
74 68
 
75 69
             { .op = OP_SET_TEMPERATURE, .val = 1900 },
76 70
         },
@@ -112,23 +106,13 @@ static const struct workflow wf[WF_MAX_FLOWS] = {
112 106
             { .op = OP_WAIT_TIME, .val = 5000 },
113 107
             { .op = OP_PUMP_TIME, .val = 20000 },
114 108
 
115
-            { .op = OP_PUMP_TIME, .val = 1000 },
116
-            { .op = OP_WAIT_TIME, .val = 1000 },
117
-
118
-            { .op = OP_PUMP_TIME, .val = 1000 },
119
-            { .op = OP_WAIT_TIME, .val = 1000 },
120
-
121
-            { .op = OP_PUMP_TIME, .val = 1000 },
122
-            { .op = OP_WAIT_TIME, .val = 1000 },
123
-
124
-            { .op = OP_PUMP_TIME, .val = 1000 },
125
-            { .op = OP_WAIT_TIME, .val = 1000 },
109
+            NOTIFY, NOTIFY, NOTIFY, NOTIFY,
126 110
 
127 111
             { .op = OP_SET_TEMPERATURE, .val = 1900 },
128 112
         },
129 113
         .count = 18,
130 114
     }, {
131
-        .name = "Hardcore",
115
+        .name = "Hotty",
132 116
         .author = "xythobuz",
133 117
         .steps = {
134 118
             { .op = OP_WAIT_TEMPERATURE, .val = 1900 },
@@ -143,17 +127,7 @@ static const struct workflow wf[WF_MAX_FLOWS] = {
143 127
             { .op = OP_WAIT_TIME, .val = 5000 },
144 128
             { .op = OP_PUMP_TIME, .val = 20000 },
145 129
 
146
-            { .op = OP_PUMP_TIME, .val = 1000 },
147
-            { .op = OP_WAIT_TIME, .val = 1000 },
148
-
149
-            { .op = OP_PUMP_TIME, .val = 1000 },
150
-            { .op = OP_WAIT_TIME, .val = 1000 },
151
-
152
-            { .op = OP_PUMP_TIME, .val = 1000 },
153
-            { .op = OP_WAIT_TIME, .val = 1000 },
154
-
155
-            { .op = OP_PUMP_TIME, .val = 1000 },
156
-            { .op = OP_WAIT_TIME, .val = 1000 },
130
+            NOTIFY, NOTIFY, NOTIFY, NOTIFY,
157 131
 
158 132
             { .op = OP_SET_TEMPERATURE, .val = 1900 },
159 133
         },
@@ -178,7 +152,9 @@ static void do_step(void) {
178 152
 
179 153
     case OP_PUMP_TIME:
180 154
         volcano_set_pump_state(true);
181
-        __attribute__((fallthrough));
155
+        start_t = to_ms_since_boot(get_absolute_time());
156
+        debug("workflow pump %.3f s", wf[wf_i].steps[step].val / 1000.0);
157
+        break;
182 158
 
183 159
     case OP_WAIT_TIME:
184 160
         start_t = to_ms_since_boot(get_absolute_time());

Carregando…
Cancelar
Salvar