Revision e2a3c71f
ID | e2a3c71f71fc38f72a7175df2e257c5b024bee41 |
Parent | 2dde134c |
Added shutoff when current is sensed when enabling tool
Also made a number of fixes to current sensing, which was quite broken.
toolbox/main.c | ||
---|---|---|
21 | 21 |
TS_DENY, |
22 | 22 |
TS_REQ_DIS, |
23 | 23 |
TS_MISSING_ID, |
24 |
TS_ON |
|
24 |
TS_ON, |
|
25 |
TS_OVER_CURRENT |
|
25 | 26 |
}; |
26 | 27 |
|
27 | 28 |
static enum toolstate_t toolstate = TS_INIT; |
... | ... | |
31 | 32 |
static uint16_t current; |
32 | 33 |
//static uint16_t current_max_warn, current_max_hard; |
33 | 34 |
|
35 |
// watch for current spike when tool turns on |
|
36 |
#define CURRENT_STARTUP_THRESH 10 |
|
37 |
#define CURRENT_STARTUP_TIMEOUT 200 // ms |
|
38 |
static uint8_t current_startup_timeout; |
|
39 |
static uint16_t current_startup_value; |
|
40 |
|
|
34 | 41 |
static inline void set_coil(char coil, char bit) { |
35 | 42 |
coils = (coils & ~(1 << coil)) | (bit << coil); |
36 | 43 |
} |
... | ... | |
92 | 99 |
if (get_coil(MB_COIL_EN)) { |
93 | 100 |
tool_enable(); |
94 | 101 |
toolstate = TS_ON; |
102 |
current_startup_timeout = CURRENT_STARTUP_TIMEOUT / TICK_MS; |
|
103 |
current_startup_value = current + CURRENT_STARTUP_THRESH; |
|
95 | 104 |
} else if (!get_coil(MB_COIL_NEW)) { |
96 | 105 |
toolstate = TS_DENY; |
97 | 106 |
} else if (!serno_equal(current_user, latest_reading)) { |
... | ... | |
125 | 134 |
break; |
126 | 135 |
|
127 | 136 |
case TS_MISSING_ID: |
128 |
if (!get_coil(MB_COIL_EN)) { |
|
137 |
if (current_startup_timeout > 0 && current > current_startup_value) { |
|
138 |
tool_disable(); |
|
139 |
set_coil(MB_COIL_EN, 0); |
|
140 |
toolstate = TS_OVER_CURRENT; |
|
141 |
led_blink_start(500, 16, RED); |
|
142 |
} else if (!get_coil(MB_COIL_EN)) { |
|
129 | 143 |
tool_disable(); |
130 | 144 |
toolstate = TS_OFF; |
131 | 145 |
} else if (get_coil(MB_COIL_REQ_DIS)) { |
... | ... | |
138 | 152 |
serno_zero(current_user); |
139 | 153 |
toolstate = TS_OFF; |
140 | 154 |
} |
155 |
if (current_startup_timeout > 0) { |
|
156 |
current_startup_timeout--; |
|
157 |
} |
|
141 | 158 |
break; |
142 | 159 |
|
143 | 160 |
case TS_ON: |
144 | 161 |
led_green(); |
145 |
if (!get_coil(MB_COIL_EN)) { |
|
162 |
if (current_startup_timeout > 0 && current > current_startup_value) { |
|
163 |
tool_disable(); |
|
164 |
set_coil(MB_COIL_EN, 0); |
|
165 |
toolstate = TS_OVER_CURRENT; |
|
166 |
led_blink_start(500, 16, RED); |
|
167 |
} else if (!get_coil(MB_COIL_EN)) { |
|
146 | 168 |
tool_disable(); |
147 | 169 |
serno_zero(current_user); |
148 | 170 |
toolstate = TS_OFF; |
... | ... | |
150 | 172 |
toolstate = TS_REQ_DIS; |
151 | 173 |
} else if (!serno_equal(current_user, latest_reading)) { |
152 | 174 |
toolstate = TS_MISSING_ID; |
153 |
led_blink_start(500, 6, YELLOW); // TODO made 10 seconds |
|
175 |
led_blink_start(500, 16, YELLOW); |
|
176 |
} |
|
177 |
if (current_startup_timeout > 0) { |
|
178 |
current_startup_timeout--; |
|
179 |
} |
|
180 |
break; |
|
181 |
|
|
182 |
case TS_OVER_CURRENT: |
|
183 |
if (led_blink_done() && !serno_equal(current_user, latest_reading)) { |
|
184 |
toolstate = TS_OFF; |
|
185 |
serno_zero(current_user); |
|
154 | 186 |
} |
155 | 187 |
break; |
156 | 188 |
|
Also available in: Unified diff