-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvalve.cpp
More file actions
54 lines (47 loc) · 1.05 KB
/
valve.cpp
File metadata and controls
54 lines (47 loc) · 1.05 KB
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
#include "stdint.h"
#include "stddef.h"
#include "fsl_gpio.h"
#include "ammdk-carrier/solenoid.h"
#include "valve.h"
#include "spi_remote_api.h"
unsigned int valve_bad_chunks = 0;
void valve_close(struct solenoid::solenoid &v);
void valve_open(struct solenoid::solenoid &v);
void
valve_handle_slave(struct valve_command *cmd,
struct solenoid::solenoid *valves,
size_t valve_num)
{
//TODO
//whole point of spi proto stuff was to be able to send deltas, so the command will be a valve id and a new state
if (cmd->valve_id < valve_num) {
if (cmd->valve_command == VALVE_CLOSED) {
valve_close(valves[cmd->valve_id]);
} else if (cmd->valve_command == VALVE_OPEN) {
valve_open(valves[cmd->valve_id]);
} else {
valve_bad_chunks++;
}
} else {
valve_bad_chunks++;
}
}
#define POLARITY_ON_IS_OPEN 1
void
valve_close(struct solenoid::solenoid &v)
{
#if POLARITY_ON_IS_OPEN
solenoid::off(v);
#else
solenoid::on(v);
#endif
}
void
valve_open(struct solenoid::solenoid &v)
{
#if POLARITY_ON_IS_OPEN
solenoid::on(v);
#else
solenoid::off(v);
#endif
}