-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
94 lines (76 loc) · 2.46 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include "uart.h"
#include "servos.h"
#include "pumps.h"
#include "config.h"
#include "steppers.h"
int main(void) {
uart_init();
servos_init();
steppers_init();
pumps_init();
*idle_ddr &= ~idle_mask;
*idle_port |= idle_mask;
*setup_ddr &= ~setup_mask;
*setup_port |= setup_mask;
*ready_ddr |= ready_mask;
*ready_port &= ~(ready_mask);
sei();
uart_puts("PumpControl 0.1 ready\n\r");
uint8_t active_pump = 0;
while(1) {
pumps_run();
// Setup is active low
if(!(*setup_pin & setup_mask)) {
for(uint8_t i = 0; i < PumpCount; i++) {
if(pump_states[i] != PUMP_SETUP) {
pump_enter_setup(i);
}
}
}
// We only activate extruders if we are idle
if(*idle_pin & idle_mask) {
/*
* Check if we need a new active pump
* if full -> nice we've got a fresh one
* if dispense -> still some stuff left in this one
*/
if(pump_states[active_pump] != PUMP_FULL &&
pump_states[active_pump] != PUMP_DISPENSE) {
for(uint8_t i = 0; i < PumpCount; i++) {
if(pump_states[i] == PUMP_FULL) {
active_pump = i;
break;
}
}
}
// We've selected a new active pump, now we need to start it
if(pump_states[active_pump] == PUMP_FULL) {
uart_debug_pump(active_pump, "is new acitve pump");
pump_enter_dispense(active_pump);
}
}
/*
* We are ready if we picked a new active pump and set it to dispense,
* or if the old one still has stuff left in it and is in dispense.
*/
if(pump_states[active_pump] == PUMP_DISPENSE) {
*ready_port |= ready_mask;
}
else {
*ready_port &= ~(ready_mask);
}
/*
* If we are idle, try to fill all pumps
* If the active pump is also refilled, a other full one will be chosen
* in the next iteration.
*/
if(!(*idle_pin & idle_mask)) {
for(uint8_t i = 0; i < PumpCount; i++) {
if(pump_states[i] == PUMP_DISPENSE) {
uart_debug("Idle state detected, refilling");
pump_enter_fill(i);
}
}
}
}
}