Browse Source

can also edit workflow steps

Thomas Buck 1 year ago
parent
commit
e1bfb1b191
7 changed files with 69 additions and 27 deletions
  1. 2
    1
      include/state_value.h
  2. 3
    3
      include/workflow.h
  3. 32
    2
      src/state_edit_workflow.c
  4. 4
    2
      src/state_settings.c
  5. 15
    6
      src/state_value.c
  6. 3
    3
      src/state_volcano_run.c
  7. 10
    10
      src/workflow.c

+ 2
- 1
include/state_value.h View File

@@ -29,7 +29,8 @@ enum value_step_mode {
29 29
 
30 30
 void state_value_set(void *value, size_t length,
31 31
                      ssize_t min, ssize_t max,
32
-                     enum value_step_mode mode, ssize_t step);
32
+                     enum value_step_mode mode, ssize_t step,
33
+                     const char *name);
33 34
 void state_value_return(enum system_state state);
34 35
 
35 36
 void state_value_enter(void);

+ 3
- 3
include/workflow.h View File

@@ -54,7 +54,7 @@ struct wf_state {
54 54
 
55 55
     uint16_t index;
56 56
     uint16_t count;
57
-    struct wf_step step;
57
+    struct wf_step *step;
58 58
     uint16_t start_val, curr_val;
59 59
 };
60 60
 
@@ -71,8 +71,8 @@ uint16_t wf_steps(uint16_t index);
71 71
 void wf_move_step_down(uint16_t index, uint16_t step);
72 72
 void wf_move_step_up(uint16_t index, uint16_t step);
73 73
 
74
-struct wf_step wf_get_step(uint16_t index, uint16_t step);
75
-const char *wf_step_str(struct wf_step step);
74
+struct wf_step *wf_get_step(uint16_t index, uint16_t step);
75
+const char *wf_step_str(struct wf_step *step);
76 76
 
77 77
 struct wf_state wf_status(void);
78 78
 void wf_start(uint16_t index);

+ 32
- 2
src/state_edit_workflow.c View File

@@ -20,16 +20,46 @@
20 20
 #include <string.h>
21 21
 
22 22
 #include "config.h"
23
+#include "mem.h"
23 24
 #include "menu.h"
24 25
 #include "workflow.h"
25 26
 #include "state.h"
27
+#include "state_value.h"
26 28
 #include "state_edit_workflow.h"
27 29
 
28 30
 static uint16_t wf_index = 0;
29 31
 
30 32
 static void enter_cb(int selection) {
33
+    static char buff[20];
34
+
31 35
     if ((selection >= 0) && (selection < wf_steps(wf_index))) {
32
-        // TODO edit value
36
+        struct wf_step *step = wf_get_step(wf_index, selection);
37
+        switch (step->op) {
38
+        case OP_SET_TEMPERATURE:
39
+        case OP_WAIT_TEMPERATURE:
40
+            snprintf(buff, sizeof(buff),
41
+                     "%s Temp.",
42
+                     step->op == OP_WAIT_TEMPERATURE ? "Wait" : "Set");
43
+            state_value_set(&step->val,
44
+                            sizeof(step->val),
45
+                            400, 2300, VAL_STEP_INCREMENT, 10,
46
+                            buff);
47
+            break;
48
+
49
+        case OP_WAIT_TIME:
50
+        case OP_PUMP_TIME:
51
+            snprintf(buff, sizeof(buff),
52
+                     "%s Time",
53
+                     step->op == OP_WAIT_TIME ? "Wait" : "Pump");
54
+            state_value_set(&step->val,
55
+                            sizeof(step->val),
56
+                            0, 60000, VAL_STEP_INCREMENT, 1000,
57
+                            buff);
58
+            break;
59
+        }
60
+
61
+        state_value_return(STATE_EDIT_WORKFLOW);
62
+        state_switch(STATE_VALUE);
33 63
     }
34 64
 }
35 65
 
@@ -77,7 +107,7 @@ static void draw(struct menu_state *menu) {
77 107
             pos += snprintf(menu->buff + pos, MENU_MAX_LEN - pos, "  ");
78 108
         }
79 109
 
80
-        struct wf_step step = wf_get_step(wf_index, i);
110
+        struct wf_step *step = wf_get_step(wf_index, i);
81 111
         pos += snprintf(menu->buff + pos, MENU_MAX_LEN - pos,
82 112
                         "% 2d: %s\n", i, wf_step_str(step));
83 113
     }

+ 4
- 2
src/state_settings.c View File

@@ -34,7 +34,8 @@ static void enter_cb(int selection) {
34 34
         // Auto Connect
35 35
         state_value_set(&mem_data()->wf_auto_connect,
36 36
                         sizeof(mem_data()->wf_auto_connect),
37
-                        0, 1, VAL_STEP_INCREMENT, 1);
37
+                        0, 1, VAL_STEP_INCREMENT, 1,
38
+                        "Auto Connect");
38 39
         state_value_return(STATE_SETTINGS);
39 40
         state_switch(STATE_VALUE);
40 41
         break;
@@ -43,7 +44,8 @@ static void enter_cb(int selection) {
43 44
         // Brightness
44 45
         state_value_set(&mem_data()->backlight,
45 46
                         sizeof(mem_data()->backlight),
46
-                        0x00FF, 0xFF00, VAL_STEP_SHIFT, 1);
47
+                        0x00FF, 0xFF00, VAL_STEP_SHIFT, 1,
48
+                        "Brightness");
47 49
         state_value_return(STATE_SETTINGS);
48 50
         state_switch(STATE_VALUE);
49 51
         break;

+ 15
- 6
src/state_value.c View File

@@ -30,6 +30,7 @@ static size_t val_len = 0;
30 30
 static ssize_t val_min = 0;
31 31
 static ssize_t val_max = 0;
32 32
 static ssize_t val_step = 0;
33
+static const char *val_name = NULL;
33 34
 
34 35
 static enum value_step_mode val_mode = VAL_STEP_INCREMENT;
35 36
 static enum system_state val_ret_state = STATE_SCAN;
@@ -38,13 +39,15 @@ static ssize_t val = 0;
38 39
 
39 40
 void state_value_set(void *value, size_t length,
40 41
                      ssize_t min, ssize_t max,
41
-                     enum value_step_mode mode, ssize_t step) {
42
+                     enum value_step_mode mode, ssize_t step,
43
+                     const char *name) {
42 44
     val_p = value;
43 45
     val_len = length;
44 46
     val_min = min;
45 47
     val_max = max;
46 48
     val_mode = mode;
47 49
     val_step = step;
50
+    val_name = name;
48 51
 }
49 52
 
50 53
 void state_value_return(enum system_state state) {
@@ -55,15 +58,22 @@ static void draw(void) {
55 58
     static char buff[100];
56 59
     static size_t pos = 0;
57 60
 
58
-    if ((val_p == NULL) || (val_len <= 0)) {
61
+    if ((val_p == NULL) || (val_len <= 0) || (val_name == NULL)) {
59 62
         pos += snprintf(buff, sizeof(buff),
60 63
                         "error");
61 64
     } else {
62
-        pos += snprintf(buff, sizeof(buff),
63
-                        "%d", val);
65
+        if (val_mode == VAL_STEP_INCREMENT) {
66
+            pos += snprintf(buff, sizeof(buff),
67
+                            "%s:\n%d -> %d -> %d",
68
+                            val_name, val_min / val_step, val / val_step, val_max / val_step);
69
+        } else {
70
+            pos += snprintf(buff, sizeof(buff),
71
+                            "%s:\n%04X -> %04X -> %04X",
72
+                            val_name, val_min, val, val_max);
73
+        }
64 74
     }
65 75
 
66
-    text_box(buff, false,
76
+    text_box(buff, true,
67 77
              "fixed_10x20",
68 78
              0, LCD_WIDTH,
69 79
              50, TEXT_BOX_HEIGHT(20, 2),
@@ -103,7 +113,6 @@ static void step(ssize_t v) {
103 113
 
104 114
     if (((v > 0) && (val >= val_max))
105 115
         || ((v < 0) && (val <= val_min))) {
106
-        debug("val=%d v=%d", val, v);
107 116
         return;
108 117
     }
109 118
 

+ 3
- 3
src/state_volcano_run.c View File

@@ -91,7 +91,7 @@ static void draw(struct menu_state *menu) {
91 91
     pos += snprintf(menu->buff + pos, MENU_MAX_LEN - pos,
92 92
                     "step %d / %d\n", state.index, state.count);
93 93
 
94
-    switch (state.step.op) {
94
+    switch (state.step->op) {
95 95
     case OP_SET_TEMPERATURE:
96 96
         pos += snprintf(menu->buff + pos, MENU_MAX_LEN - pos,
97 97
                         "\n%s", wf_step_str(state.step));
@@ -104,7 +104,7 @@ static void draw(struct menu_state *menu) {
104 104
                         "%.1f -> %.1f -> %.1f",
105 105
                         state.start_val / 10.0f,
106 106
                         state.curr_val / 10.0f,
107
-                        state.step.val / 10.0f);
107
+                        state.step->val / 10.0f);
108 108
         break;
109 109
 
110 110
     case OP_WAIT_TIME:
@@ -115,7 +115,7 @@ static void draw(struct menu_state *menu) {
115 115
                         "%.0f -> %.0f -> %.0f",
116 116
                         state.start_val / 1000.0f,
117 117
                         state.curr_val / 1000.0f,
118
-                        state.step.val / 1000.0f);
118
+                        state.step->val / 1000.0f);
119 119
         break;
120 120
     }
121 121
 

+ 10
- 10
src/workflow.c View File

@@ -134,34 +134,34 @@ void wf_move_step_up(uint16_t index, uint16_t step) {
134 134
     mem_data()->wf[index].steps[step] = tmp;
135 135
 }
136 136
 
137
-struct wf_step wf_get_step(uint16_t index, uint16_t step) {
137
+struct wf_step *wf_get_step(uint16_t index, uint16_t step) {
138 138
     if (index >= mem_data()->wf_count) {
139 139
         debug("invalid index %d", index);
140
-        return mem_data()->wf[0].steps[0];
140
+        return NULL;
141 141
     }
142
-    return mem_data()->wf[index].steps[step];
142
+    return &mem_data()->wf[index].steps[step];
143 143
 }
144 144
 
145
-const char *wf_step_str(struct wf_step step) {
145
+const char *wf_step_str(struct wf_step *step) {
146 146
     static char buff[20];
147 147
 
148
-    switch (step.op) {
148
+    switch (step->op) {
149 149
     case OP_SET_TEMPERATURE:
150 150
         snprintf(buff, sizeof(buff),
151
-                 "set temp %.1f C", step.val / 10.0f);
151
+                 "set temp %.1f C", step->val / 10.0f);
152 152
         break;
153 153
 
154 154
     case OP_WAIT_TEMPERATURE:
155 155
         snprintf(buff, sizeof(buff),
156
-                 "wait temp %.1f C", step.val / 10.0f);
156
+                 "wait temp %.1f C", step->val / 10.0f);
157 157
         break;
158 158
 
159 159
     case OP_WAIT_TIME:
160 160
     case OP_PUMP_TIME:
161 161
         snprintf(buff, sizeof(buff),
162 162
                  "%s time %.1f s",
163
-                 (step.op == OP_WAIT_TIME) ? "wait" : "pump",
164
-                 step.val / 1000.0f);
163
+                 (step->op == OP_WAIT_TIME) ? "wait" : "pump",
164
+                 step->val / 1000.0f);
165 165
         break;
166 166
     }
167 167
 
@@ -189,7 +189,7 @@ struct wf_state wf_status(void) {
189 189
         .status = status,
190 190
         .index = step,
191 191
         .count = mem_data()->wf[wf_i].count,
192
-        .step = mem_data()->wf[wf_i].steps[step],
192
+        .step = &mem_data()->wf[wf_i].steps[step],
193 193
         .start_val = start_val,
194 194
         .curr_val = curr_val,
195 195
     };

Loading…
Cancel
Save