forked from Digilent/openscope-mz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLEDs.cpp
197 lines (171 loc) · 6.11 KB
/
LEDs.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/************************************************************************/
/* */
/* LEDs.cpp */
/* */
/* LEDs State machine */
/* */
/************************************************************************/
/* Author: Keith Vogel */
/* Copyright 2016, Digilent Inc. */
/************************************************************************/
/* Revision History: */
/* 6/16/2016(KeithV): Created */
/************************************************************************/
#include <OpenScope.h>
STATE LEDTask(void)
{
static uint32_t tBtn = 0;
static bool fBtn = false;
static uint32_t tLed = SYSGetMilliSecond();
static uint32_t ip1 = 0;
static uint32_t ip2 = 0;
static uint32_t ip3 = 0;
static IPv4 ipOpenScope = {0};
static uint32_t i = 0;
static bool fBlockIOBusL = false;
static bool fNoLEDs = false;
bool fBlink = false;
bool fStopBlink = pjcmd.trigger.state.processing == Run || pjcmd.trigger.state.processing == Armed ||
pjcmd.iCal.state.processing == JSPARCalibrationStart ||
pjcmd.iALog1.state.processing == Running || pjcmd.iALog2.state.processing == Running;
/* ------------------------------------------------------------ */
/* Button Processing */
/* ------------------------------------------------------------ */
// someone hit the button
if(!fBtn && GetGPIO(PIN_BTN1))
{
// stop logging if we are logging
if(pjcmd.iALog1.state.processing == Running) ALOGStop(&pjcmd.iALog1);
if(pjcmd.iALog2.state.processing == Running) ALOGStop(&pjcmd.iALog2);
tBtn = SYSGetMilliSecond();
fBtn = true;
}
// debounce, if the button is pressed, refresh the timer
else if(fBtn && GetGPIO(PIN_BTN1))
{
tBtn = SYSGetMilliSecond();
}
// if the timer expired
else if(fBtn && (SYSGetMilliSecond() - tBtn) > 500)
{
fBtn = false;
}
/* ------------------------------------------------------------ */
/* LED Processing */
/* ------------------------------------------------------------ */
if(fStopBlink != fNoLEDs)
{
fNoLEDs = fStopBlink;
if(fNoLEDs)
{
SetGPIO(PIN_LED_1, 1);
}
else
{
SetGPIO(PIN_LED_1, 0);
tLed = SYSGetMilliSecond();
fBlink = false;
}
SetGPIO(PIN_LED_2, 0);
SetGPIO(PIN_LED_3, 0);
SetGPIO(PIN_LED_4, 0);
}
if(fNoLEDs)
{
return(Idle);
}
// see if we are on a blink boundary
if ((SYSGetMilliSecond() - tLed) >= 500)
{
tLed = SYSGetMilliSecond();
fBlink = true;
}
// see if our bus state has changed
if(fBlockIOBusL != fBlockIOBus)
{
fBlockIOBusL = fBlockIOBus;
// going to run the Logic Analyzer
if(fBlockIOBus)
{
SetGPIO(PIN_LED_1, 1); // say we are in the Logic Analyzer
SetGPIO(PIN_LED_2, 0);
SetGPIO(PIN_LED_3, 0);
SetGPIO(PIN_LED_4, (MState == MLoop)); // say we are running
}
// done running the logic analyzer
else
{
i = 0; // reset the IP counter
SetGPIO(PIN_LED_1, 0);
SetGPIO(PIN_LED_2, 0);
SetGPIO(PIN_LED_3, 0);
SetGPIO(PIN_LED_4, MState == MLoop && GetGPIO(PIN_INT_MRF));
}
}
// if the IO
if(!fBlockIOBus && fBlink)
{
// if we are up and running
if(MState == MLoop)
{
// if wifi is ready
if(deIPcK.isIPReady())
{
uint32_t j;
uint32_t k;
if(ipOpenScope.u32 == 0)
{
deIPcK.getMyIP(ipOpenScope);
ip1 = ipOpenScope.u8[3] / 100;
ip2 = ipOpenScope.u8[3] % 100;
ip3 = ip2 % 10;
ip2 /= 10;
i = 0;
}
// check to see if the MRF int pin is high,
// for the most part it should be
else
{
SetGPIO(PIN_LED_4, GetGPIO(PIN_INT_MRF));
}
j = i / 2;
k = i % 2;
if(k == 0)
{
SetGPIO(PIN_LED_1, 0);
SetGPIO(PIN_LED_2, 0);
SetGPIO(PIN_LED_3, 0);
}
else
{
if(j < ip1) SetGPIO(PIN_LED_1, 1);
if(j < ip2) SetGPIO(PIN_LED_2, 1);
if(j < ip3) SetGPIO(PIN_LED_3, 1);
}
if(j>=ip1 && j>=ip2 && j>=ip3)
{
i = 0;
}
else
{
i++;
}
}
// no wifi, but we are ready over COM
else
{
SetGPIO(PIN_LED_4, !GetGPIO(PIN_LED_4));
}
}
// not ready
else
{
ipOpenScope.u32 = 0;
SetGPIO(PIN_LED_1, 0);
SetGPIO(PIN_LED_2, 0);
SetGPIO(PIN_LED_3, 0);
SetGPIO(PIN_LED_4, 0);
}
}
return(Idle);
}