-
Notifications
You must be signed in to change notification settings - Fork 1
/
click-test.cpp
62 lines (54 loc) · 1.55 KB
/
click-test.cpp
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
//g++ test/click-test.cpp src/spi_proto_master.cpp src/spi_chunks.cpp -std=c++14 -pthread -x c src/binary_semaphore.c -x c src/spi_proto.c -I. -Isrc/ -x c src/crc16.c -x c src/spi_remote_host.c -o click -g
//causes solenoids to click in strobing sequence. Remote API test
#include <thread>
#include "spi_remote.h"
using namespace spi_proto;
void
click_task(void);
int main(int argc, char *argv[]) {
/* Boilerplate. Start the SPI communication thread after initializing the
* shared data structure. Then start the task thread.
*/
host_remote_init(&remote);
std::thread remote_thread(remote_task);
std::thread click_thread(click_task);
while (1) {
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
return 0;
}
//just a helper function
void
delay_ms(unsigned int ms)
{
std::this_thread::sleep_for(std::chrono::milliseconds(ms));
}
void
click_task(void)
{
puts("enabling 24V!");
/* 15 is the 24V rail on the AMMDK V1. We know this by comparing the table in
* amm-tiny/source/ammdk-carrier/carrier_gpio.cpp to the AMMDK V1 spreadsheet.
*/
remote_set_gpio(15, 1);
int wait = 200;
/* Again, this number arrived at by comparing the carrier_gpio.cpp table with
* the spreadsheet.
*/
uint8_t solenoid_0 = 7;
puts("starting clicking!");
for (;;) {
for (int i = 0; i < SOLENOID_NUM; i++) {
remote_set_gpio(solenoid_0 + i, 1);
delay_ms(wait);
}
delay_ms(wait);
puts("clicked");
for (int i = 0; i < SOLENOID_NUM; i++) {
remote_set_gpio(solenoid_0 + i, 0);
delay_ms(wait);
}
delay_ms(wait);
puts("unclicked");
}
}