-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainFn.cpp
147 lines (123 loc) · 2.77 KB
/
mainFn.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
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/*
* mainFn.cpp
*
* Created on: Jul 5, 2016
* Author: arri-c
*/
//Summary of todo stuff
/*
* timer: basis for timer is below, but the <chrono> implementation needs to be tested on the pi
*
* GPIOs:
* settings for the in/out pins to be finalized when integrating pi with DAC.
* this applies to changing value/type/power. once again, the base code is below
*
*/
#include <iostream>
#include <chrono>
struct Electrode{
unsigned long interval; //interval in ns
unsigned long long timestamp; //timestamp in ns since epoch
int value; //high or low
int type; //waveform shape (if customizable)
bool running;
int start_pin; //so we can find GPIO relatively for each electrode
};
int main() {
/*
* cmd line usage
* ./dep interval_e1 type_e1 run_e1... interval_e4 type_e4 run_e4 total_runtime
*/
//init
struct Electrode e1; //NW
struct Electrode e2; //NE
struct Electrode e3; //SE
struct Electrode e4; //SW
setInterval(&e1,0); //replace with arg
setWavetype(&e1,0); //replace with arg
if(true){on(&e1);} else{off(&e1);} //replacing 'true' with arg
setInterval(&e2,0); //replace with arg
setWavetype(&e2,0); //replace with arg
if(true){on(&e2);} else{off(&e2);} //replacing 'true' with arg
setInterval(&e3,0); //replace with arg
setWavetype(&e3,0); //replace with arg
if(true){on(&e3);} else{off(&e3);} //replacing 'true' with arg
setInterval(&e4,0); //replace with arg
setWavetype(&e4,0); //replace with arg
if(true){on(&e4);} else{off(&e4);} //replacing 'true' with arg
//end init
e1.timestamp = std::chrono::system_clock::now();
e2.timestamp = std::chrono::system_clock::now();
e3.timestamp = std::chrono::system_clock::now();
e4.timestamp = std::chrono::system_clock::now();
while(true)
{
if(checkTime(&e1))
{
//switch value
}
if(checkTime(&e2))
{
//switch value
}
if(checkTime(&e3))
{
//switch value
}
if(checkTime(&e4))
{
//switch value
}
}
}
void setInterval(Electrode* e, unsigned long interval)
{
e->interval = interval;
}
void setWavetype(Electrode* e, int type)
{
e->type = type;
//GPIO change
}
void on(Electrode* e)
{
e->running = true;
//GPIO change
}
void off(Electrode* e)
{
e->running = false;
//GPIO change
}
void switch_val(Electrode* e)
{
if(e->value == true)
{
e->value = false;
//GPIO change
}
else
{
e->value = true;
//GPIO change
}
}
bool checkTime(Electrode* e)
{
if(e->timestamp + e->interval == std::chrono::system_clock::now())
{
//good run.
return true;
}
else if(e->timestamp + e->interval < std::chrono::system_clock::now())
{
//miss. time now is greater than latest run + interval
//need this for testing accuracy
//return true but log error
return true;
}
else
{
return false;
}
}