Debian Codegraph @

thirdparty/analogdevicesinc/no-OS/ad-dyno1-ebz/src/Menu.c

raw symbols SCIP
1 /***************************************************************************//**
2 * @file Menu.c
3 * @brief Menu implementation.
4 * @author Mihai Bancisor ([email protected])
5 ********************************************************************************
6 * Copyright 2014(c) Analog Devices, Inc.
7 *
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are met:
12 * - Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * - Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
17 * distribution.
18 * - Neither the name of Analog Devices, Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 * - The use of this software may or may not infringe the patent rights
22 * of one or more patent holders. This license does not release you
23 * from the requirement that you obtain separate licenses from these
24 * patent holders to use this software.
25 * - Use of the software either in source or binary form, must be run
26 * on or directly connected to an Analog Devices Inc. component.
27 *
28 * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
29 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
30 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
31 * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
32 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33 * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
34 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
35 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
36 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 *******************************************************************************/
39
40 /******************************************************************************/
41 /***************************** Include Files **********************************/
42 /******************************************************************************/
43 #include "menu.h"
44 #include "ST7565R.h"
45 #include "math.h"
46 #include "dyno.h"
47
48 /******************************************************************************/
49 /**************************** Global Variables ********************************/
50 /******************************************************************************/
51 extern volatile unsigned int ct10Ms;
52 extern volatile unsigned char btMin;
53 extern volatile unsigned char btEnt;
54 extern volatile unsigned char btPlu;
55 extern volatile unsigned char prevBtEnt;
56 extern volatile unsigned char debounceCt;
57
58 extern volatile unsigned long delay25Us;
59
60 extern volatile unsigned short lcdUpdateCt;
61
62 extern volatile unsigned char dutyCycle;
63 extern volatile unsigned char maxDutyCycle;
64 extern volatile unsigned char minDutyCycle;
65 extern volatile unsigned char dutyCycleStep;
66
67 extern unsigned char rampTime;
68
69 extern volatile unsigned long long c1SquareSumRMS;
70 volatile float c1RMS = 0;
71 volatile unsigned char sampleADC = 1;
72
73 extern volatile int adc[];
74 int ct = 0;
75
76 extern volatile int adc1;
77
78 extern volatile short filteredOffset;
79
80 extern unsigned short hallTime[];
81 extern volatile unsigned short hallCounter;
82 extern volatile unsigned short hallStoppedCounter;
83 unsigned long rpm = 0;
84 unsigned short hallAverageCt = 0;
85
86 /******************************************************************************/
87 /******************************* Functions ************************************/
88 /******************************************************************************/
89
90 /***************************************************************************//**
91 * @brief Adds a submenu.
92 *
93 * @param pMainMenu - The menu where the submenu needs to be added.
94 *
95 * @param pSubMenu - The submenu.
96 *
97 * @return None
98 *
99 *******************************************************************************/
100 void AddSubmenu(menuType* pMainMenu, menuType* pSubMenu)
101 {
102 if(pMainMenu->parent && pMainMenu->submenuCount == 0)
103 {
104 pMainMenu->submenu[pMainMenu->submenuCount] = pMainMenu->parent;
105 pMainMenu->submenuCount++;
106 }
107
108 pMainMenu->submenu[pMainMenu->submenuCount] = pSubMenu;
109 pMainMenu->submenuCount++;
110
111 pSubMenu->parent = pMainMenu;
112 }
113
114 /***************************************************************************//**
115 * @brief Scroll menu up.
116 *
117 * @param pMenu - Current menu.
118 *
119 * @return None
120 *
121 *******************************************************************************/
122 void StepMenuUp(menuType* pMenu)
123 {
124 if(pMenu->activeSubmenu < pMenu->submenuCount - 1)
125 pMenu->activeSubmenu++;
126 }
127
128 /***************************************************************************//**
129 * @brief Scroll menu down.
130 *
131 * @param pMenu - Current menu.
132 *
133 * @return None
134 *
135 *******************************************************************************/
136 void StepMenuDown(menuType* pMenu)
137 {
138 if(pMenu->activeSubmenu > 0)
139 pMenu->activeSubmenu--;
140 }
141
142 menuType* GetActiveMenu(menuType* pMenu)
143 {
144 return pMenu->submenu[pMenu->activeSubmenu];
145 }
146
147 /***************************************************************************//**
148 * @brief Measurement function.
149 *
150 * @param up - Up button state.
151 *
152 * @param down - Down button state.
153 *
154 * @return None
155 *
156 *******************************************************************************/
157 void pfnMeasurements(char up, char down)
158 {
159 if(lcdUpdateCt > 20000)
160 {
161 sampleADC = 0;
162 c1RMS = (sqrt(c1SquareSumRMS/4000))/151.55F;
163 lcdUpdateCt = 0;
164 ST7565R_String(0, 0, "Current: A", 0);
165 ST7565R_FloatNumber(0, 50, c1RMS,2,0);
166 ST7565R_String(1, 0, "Speed: RPM", 0);
167 rpm = 0;
168 // compute speed only if > 60rpm
169 if((hallCounter < 5000) && (hallStoppedCounter < 5000))
170 {
171 for(hallAverageCt = 0; hallAverageCt < 10; hallAverageCt++)
172 {
173 rpm +=hallTime[hallAverageCt];
174 }
175 rpm = 3000000 / rpm;
176 }
177 ST7565R_Number(1, 50, rpm, 0);
178 ST7565R_String(3, 0, "Duty Cycle", 0);
179 ST7565R_String(3, 105, "%", 0);
180 sampleADC = 1;
181 }
182 if(up)
183 {
184 ST7565R_String(3, 80, " ", 0);
185 if(dutyCycle + dutyCycleStep <= 100)
186 dutyCycle+=dutyCycleStep;
187 else
188 dutyCycle = 100;
189 ST7565R_Number(3, 80, dutyCycle, 0);
190 }
191 else if(down)
192 {
193 ST7565R_String(3, 80, " ", 0);
194 if(dutyCycle - dutyCycleStep >= 0)
195 dutyCycle -= dutyCycleStep;
196 else
197 dutyCycle = 0;
198 ST7565R_Number(3, 80, dutyCycle, 0);
199 }
200 else
201 ST7565R_Number(3, 80, dutyCycle, 0);
202 }
203
204 /***************************************************************************//**
205 * @brief Step load function.
206 *
207 * @param up - Up button state.
208 *
209 * @param down - Down button state.
210 *
211 * @return None
212 *
213 *******************************************************************************/
214 void pfnStep(char up, char down)
215 {
216 static unsigned char stateFlag = 0;
217 if(stateFlag)
218 {
219 dutyCycle = maxDutyCycle;
220 }
221 else
222 {
223 dutyCycle = minDutyCycle;
224 }
225
226 ST7565R_String(1, 20, "Duty Cycle:", 0);
227 ST7565R_String(1, 114, "%", 0);
228
229 if(up || down)
230 {
231 stateFlag = !stateFlag;
232 if(stateFlag)
233 {
234 ST7565R_String(1, 90, " ", 0);
235 }
236 else
237 {
238 ST7565R_String(1, 90, " ", 0);
239 }
240 }
241 else
242 {
243 ST7565R_Number(1, 90, dutyCycle, 0);
244 }
245 if(stateFlag)
246 {
247 dutyCycle = maxDutyCycle;
248 ST7565R_Number(1, 90, dutyCycle, 0);
249 }
250 else
251 {
252 dutyCycle = minDutyCycle;
253 ST7565R_Number(1, 90, dutyCycle, 0);
254 }
255 }
256
257 /***************************************************************************//**
258 * @brief Set maximum duty cycle function.
259 *
260 * @param up - Up button state.
261 *
262 * @param down - Down button state.
263 *
264 * @return None
265 *
266 *******************************************************************************/
267 void pfnSetMax(char up, char down)
268 {
269 ST7565R_String(0, 0, "Set upper duty cycle", 0);
270 ST7565R_String(2, 80, "%", 0);
271 if(up && (maxDutyCycle < 100))
272 {
273 ST7565R_String(2, 60, " ", 0);
274 if(maxDutyCycle + dutyCycleStep <= 100)
275 maxDutyCycle+=dutyCycleStep;
276 else
277 maxDutyCycle = 100;
278 ST7565R_Number(2, 60, maxDutyCycle, 0);
279 }
280 else if(down && (maxDutyCycle > 0))
281 {
282 ST7565R_String(2, 60, " ", 0);
283 if((maxDutyCycle - dutyCycleStep >= 0) && (maxDutyCycle - dutyCycleStep >= minDutyCycle))
284 maxDutyCycle-=dutyCycleStep;
285
286 ST7565R_Number(2, 60, maxDutyCycle, 0);
287 }
288 else
289 ST7565R_Number(2, 60, maxDutyCycle, 0);
290
291 }
292
293 /***************************************************************************//**
294 * @brief Set minimum duty cycle function.
295 *
296 * @param up - Up button state.
297 *
298 * @param down - Down button state.
299 *
300 * @return None
301 *
302 *******************************************************************************/
303 void pfnSetMin(char up, char down)
304 {
305 ST7565R_String(0, 0, "Set lower duty cycle", 0);
306 ST7565R_String(2, 80, "%", 0);
307 if(up)
308 {
309 ST7565R_String(2, 60, " ", 0);
310 if((minDutyCycle + dutyCycleStep <= 100) && (minDutyCycle + dutyCycleStep <= maxDutyCycle))
311 minDutyCycle+=dutyCycleStep;
312 ST7565R_Number(2, 60, minDutyCycle, 0);
313 }
314 else if(down)
315 {
316 ST7565R_String(2, 60, " ", 0);
317 if(minDutyCycle - dutyCycleStep >= 0)
318 minDutyCycle -= dutyCycleStep;
319 else
320 minDutyCycle = 0;
321 ST7565R_Number(2, 60, minDutyCycle, 0);
322 }
323 else
324 ST7565R_Number(2, 60, minDutyCycle, 0);
325 }
326
327 /***************************************************************************//**
328 * @brief Ramp load function.
329 *
330 * @param up - Up button state.
331 *
332 * @param down - Down button state.
333 *
334 * @return None
335 *
336 *******************************************************************************/
337 void pfnRamp(char up, char down)
338 {
339
340 ST7565R_String(1, 0, "Ramp period:", 0);
341 ST7565R_String(1, 94, "sec", 0);
342 if(up)
343 {
344 ST7565R_String(1, 80, " ", 0);
345 if(rampTime + 1 <= 10)
346 rampTime += 1;
347 else
348 rampTime = 10;
349 ST7565R_Number(1, 80, rampTime, 0);
350 }
351 else if(down)
352 {
353 ST7565R_String(1, 80, " ", 0);
354 if(rampTime - 1 >= 1)
355 rampTime -= 1;
356 else
357 rampTime = 1;
358 ST7565R_Number(1, 80, rampTime, 0);
359 }
360 else
361 ST7565R_Number(1, 80, rampTime, 0);
362 }
363
364 /***************************************************************************//**
365 * @brief Set duty cycle step function.
366 *
367 * @param up - Up button state.
368 *
369 * @param down - Down button state.
370 *
371 * @return None
372 *
373 *******************************************************************************/
374 void pfnDutyCycleStep(char up, char down)
375 {
376 ST7565R_String(0, 0, "Set duty cycle step", 0);
377 if(up && (dutyCycleStep < 25))
378 {
379 ST7565R_String(2, 60, " ", 0);
380 ST7565R_Number(2, 60, ++dutyCycleStep, 0);
381 }
382 else if(down && (dutyCycleStep > 1))
383 {
384 ST7565R_String(2, 60, " ", 0);
385 ST7565R_Number(2, 60, --dutyCycleStep, 0);
386 }
387 else
388 ST7565R_Number(2, 60, dutyCycleStep, 0);
389 }
390
391 /***************************************************************************//**
392 * @brief About function.
393 *
394 * @param up - Up button state.
395 *
396 * @param down - Down button state.
397 *
398 * @return None
399 *
400 *******************************************************************************/
401 void pfnAbout(char up, char down)
402 {
403 ST7565R_String(1, 10, "AD-DYNO1-EBZ REV A", 0);
404 ST7565R_String(2, 30, "SW REV 0.1", 0);
405 }