Browse Source

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

Thomas Buck 1 year ago
parent
commit
01259255e8
4 changed files with 47 additions and 44 deletions
  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 View File

491
 
491
 
492
     bool v = (state == TC_READY)
492
     bool v = (state == TC_READY)
493
              || (state == TC_W4_READ)
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
     cyw43_thread_exit();
500
     cyw43_thread_exit();
497
     return v;
501
     return v;

+ 16
- 3
src/state_volcano_run.c View File

20
 #include <string.h>
20
 #include <string.h>
21
 
21
 
22
 #include "config.h"
22
 #include "config.h"
23
+#include "log.h"
23
 #include "workflow.h"
24
 #include "workflow.h"
24
 #include "state.h"
25
 #include "state.h"
25
 #include "state_volcano_run.h"
26
 #include "state_volcano_run.h"
30
 static bd_addr_t ble_addr;
31
 static bd_addr_t ble_addr;
31
 static bd_addr_type_t ble_type;
32
 static bd_addr_type_t ble_type;
32
 static bool wait_for_connect = false;
33
 static bool wait_for_connect = false;
34
+static bool wait_for_disconnect = false;
33
 
35
 
34
 void state_volcano_run_index(uint16_t index) {
36
 void state_volcano_run_index(uint16_t index) {
35
     wf_index = index;
37
     wf_index = index;
41
 }
43
 }
42
 
44
 
43
 void state_volcano_run_enter(void) {
45
 void state_volcano_run_enter(void) {
46
+    debug("workflow connect");
44
     ble_connect(ble_addr, ble_type);
47
     ble_connect(ble_addr, ble_type);
45
     wait_for_connect = true;
48
     wait_for_connect = true;
46
 }
49
 }
47
 
50
 
48
 void state_volcano_run_exit(void) {
51
 void state_volcano_run_exit(void) {
49
     wf_reset();
52
     wf_reset();
50
-    ble_disconnect();
51
 }
53
 }
52
 
54
 
53
 static void draw(struct menu_state *menu) {
55
 static void draw(struct menu_state *menu) {
58
 void state_volcano_run_run(void) {
60
 void state_volcano_run_run(void) {
59
     if (wait_for_connect && ble_is_connected()) {
61
     if (wait_for_connect && ble_is_connected()) {
60
         wait_for_connect = false;
62
         wait_for_connect = false;
63
+        debug("workflow start");
61
         wf_start(wf_index);
64
         wf_start(wf_index);
62
     }
65
     }
63
 
66
 
64
     menu_run(draw);
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
         state_switch(STATE_SCAN);
81
         state_switch(STATE_SCAN);
69
     }
82
     }
70
 }
83
 }

+ 15
- 5
src/text.c View File

161
         text_prepare_font(&font);
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
     struct text_conf text = {
170
     struct text_conf text = {
165
         .text = "",
171
         .text = "",
166
-        .x = 0,
167
-        .y = 50,
172
+        .x = x,
173
+        .y = y,
168
         .justify = false,
174
         .justify = false,
169
         .alignment = MF_ALIGN_CENTER,
175
         .alignment = MF_ALIGN_CENTER,
170
-        .width = 240,
171
-        .height = 240 - 80,
176
+        .width = width,
177
+        .height = height,
172
         .margin = 2,
178
         .margin = 2,
173
         .fg = RGB_565(0xFF, 0xFF, 0xFF),
179
         .fg = RGB_565(0xFF, 0xFF, 0xFF),
174
         .bg = RGB_565(0x00, 0x00, 0x00),
180
         .bg = RGB_565(0x00, 0x00, 0x00),
175
         .font = &font,
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
     text.text = s;
190
     text.text = s;
181
     text_draw(&text);
191
     text_draw(&text);

+ 11
- 35
src/workflow.c View File

43
     uint16_t count;
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
 static const struct workflow wf[WF_MAX_FLOWS] = {
50
 static const struct workflow wf[WF_MAX_FLOWS] = {
47
     {
51
     {
48
         .name = "Default",
52
         .name = "Default",
60
             { .op = OP_WAIT_TIME, .val = 5000 },
64
             { .op = OP_WAIT_TIME, .val = 5000 },
61
             { .op = OP_PUMP_TIME, .val = 20000 },
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
             { .op = OP_SET_TEMPERATURE, .val = 1900 },
69
             { .op = OP_SET_TEMPERATURE, .val = 1900 },
76
         },
70
         },
112
             { .op = OP_WAIT_TIME, .val = 5000 },
106
             { .op = OP_WAIT_TIME, .val = 5000 },
113
             { .op = OP_PUMP_TIME, .val = 20000 },
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
             { .op = OP_SET_TEMPERATURE, .val = 1900 },
111
             { .op = OP_SET_TEMPERATURE, .val = 1900 },
128
         },
112
         },
129
         .count = 18,
113
         .count = 18,
130
     }, {
114
     }, {
131
-        .name = "Hardcore",
115
+        .name = "Hotty",
132
         .author = "xythobuz",
116
         .author = "xythobuz",
133
         .steps = {
117
         .steps = {
134
             { .op = OP_WAIT_TEMPERATURE, .val = 1900 },
118
             { .op = OP_WAIT_TEMPERATURE, .val = 1900 },
143
             { .op = OP_WAIT_TIME, .val = 5000 },
127
             { .op = OP_WAIT_TIME, .val = 5000 },
144
             { .op = OP_PUMP_TIME, .val = 20000 },
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
             { .op = OP_SET_TEMPERATURE, .val = 1900 },
132
             { .op = OP_SET_TEMPERATURE, .val = 1900 },
159
         },
133
         },
178
 
152
 
179
     case OP_PUMP_TIME:
153
     case OP_PUMP_TIME:
180
         volcano_set_pump_state(true);
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
     case OP_WAIT_TIME:
159
     case OP_WAIT_TIME:
184
         start_t = to_ms_since_boot(get_absolute_time());
160
         start_t = to_ms_since_boot(get_absolute_time());

Loading…
Cancel
Save