-
Notifications
You must be signed in to change notification settings - Fork 1
/
utility.c
606 lines (522 loc) · 17.8 KB
/
utility.c
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
/*
* @file utility.c
*
* @date Jul 24, 2017
* @author hamster
*
* Utility functions
*
*/
#include <hal/nrf_gpio.h>
#include "common.h"
//#include "modules/adc.h"
#define EE_R1 3900
#define EE_R2 10000
#define EE_R3 15000
#define EE_R4 4999
#define EE_TOTR (EE_R1 + EE_R2 + EE_R3 + EE_R4)
#define EE_VOLT(X) (getVccMillivolts() * (X) / EE_TOTR)
APP_PWM_INSTANCE(PWM1,1);
APP_TIMER_DEF(morseID);
volatile static uint32_t systick = 0;
bool morse_running = false;
/**
* Start the local time reference
* It's seeded at bootup from the user storage, if it exists
* @param time
*/
void sysTickStart(void){
systick = 0;
app_timer_create(&sysTickID, APP_TIMER_MODE_REPEATED, sysTickHandler);
app_timer_start(sysTickID, APP_TIMER_TICKS(1000), NULL);
}
/**
* @return number of seconds since we started counting time
*/
uint32_t getSystick(void){
return systick;
}
/**
* Every second, update the systick handler
* @param p_context
*/
void sysTickHandler(void * p_context){
systick++;
}
//SOS RCVED BK MANY HOSTILES BK PLS TRNSMIT CODE 801801 WHEN RDY 4 SUPORT FN
//... --- ... .-. -.-. ...- . -.. -... -.- -- .- -. -.-- .... --- ... - .. .-.. . ... -... -.- .--. .-.. ... - .-. -. ... -- .. - -.-. --- -.. . ---.. ----- .---- ---.. ----- .---- .-- .... . -. .-. -.. -.-- ....- ... ..- .--. --- .-. - ..-. -.
const uint8_t morseMessage[] = {1, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 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 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
uint16_t morseIdx =0;
uint8_t ls;
void morseTickHandler(void * p_context) {
uint8_t s = morseMessage[morseIdx];
if (s != ls){
if (s)
ledOn(LED_SIGNAL);
else
ledOff(LED_SIGNAL);
}
ls=s;
morseIdx = ((morseIdx+1) % sizeof(morseMessage));
}
void morseInit(void ) {
app_timer_create(&morseID, APP_TIMER_MODE_REPEATED, morseTickHandler);
}
void morseStart(void) {
morseIdx=0;
ls = 2;
app_timer_start(morseID, APP_TIMER_TICKS(80), NULL); //15WPM
morse_running = true;
}
void morseStop(void) {
app_timer_stop(morseID);
ledOff(LED_SIGNAL);
morse_running = false;
}
bool morseGetRunning(void){
return morse_running;
}
/**
* @brief Determine if a button is being pressed.
* @param waitForLongPress true if we want to wait to see if a button is long pressed
* @return Button pressed, with long press mask if long pressed
*
* Buttons are debounced for a few milliseconds
* Buttons held down for longer than the defined long press duration are sent
* as a long press button
*/
uint8_t getButton(bool waitForLongPress){
int longPress = 0;
int button = 0;
if(isButtonDown(USER_BUTTON_UP)){
// Debounce
nrf_delay_ms(BUTTON_DEBOUNCE_MS);
if(isButtonDown(USER_BUTTON_UP)) {
button = USER_BUTTON_UP;
if (waitForLongPress){
while (isButtonDown(USER_BUTTON_UP)) {
nrf_delay_ms(1);
longPress++;
if (longPress > BUTTON_LONG_PRESS_MS) {
break;
}
}
}
}
}
if(isButtonDown(USER_BUTTON_DOWN)){
// Debounce
nrf_delay_ms(BUTTON_DEBOUNCE_MS);
if(isButtonDown(USER_BUTTON_DOWN)){
button = USER_BUTTON_DOWN;
if (waitForLongPress) {
while (isButtonDown(USER_BUTTON_DOWN)) {
nrf_delay_ms(1);
longPress++;
if (longPress > BUTTON_LONG_PRESS_MS) {
break;
}
}
}
}
}
if(isButtonDown(USER_BUTTON_LEFT)){
// Debounce
nrf_delay_ms(BUTTON_DEBOUNCE_MS);
if(isButtonDown(USER_BUTTON_LEFT)){
button = USER_BUTTON_LEFT;
if (waitForLongPress) {
while (isButtonDown(USER_BUTTON_LEFT)) {
nrf_delay_ms(1);
longPress++;
if (longPress > BUTTON_LONG_PRESS_MS) {
break;
}
}
}
}
}
if(isButtonDown(USER_BUTTON_RIGHT)){
// Debounce
nrf_delay_ms(BUTTON_DEBOUNCE_MS);
if(isButtonDown(USER_BUTTON_RIGHT)){
button = USER_BUTTON_RIGHT;
if (waitForLongPress) {
while (isButtonDown(USER_BUTTON_RIGHT)) {
nrf_delay_ms(1);
longPress++;
if (longPress > BUTTON_LONG_PRESS_MS) {
break;
}
}
}
}
}
if(isButtonDown(USER_BUTTON_A)){
// Debounce
nrf_delay_ms(BUTTON_DEBOUNCE_MS);
if(isButtonDown(USER_BUTTON_A)){
button = USER_BUTTON_A;
if (waitForLongPress) {
while (isButtonDown(USER_BUTTON_A)) {
nrf_delay_ms(1);
longPress++;
if (longPress > BUTTON_LONG_PRESS_MS) {
break;
}
}
}
}
}
if(isButtonDown(USER_BUTTON_B)){
// Debounce
nrf_delay_ms(BUTTON_DEBOUNCE_MS);
if(isButtonDown(USER_BUTTON_B)){
button = USER_BUTTON_B;
if (waitForLongPress) {
while (isButtonDown(USER_BUTTON_B)) {
nrf_delay_ms(1);
longPress++;
if (longPress > BUTTON_LONG_PRESS_MS) {
break;
}
}
}
}
}
if(longPress > BUTTON_LONG_PRESS_MS){
button |= LONG_PRESS_MASK;
}
return button;
}
/**
* @brief Detects if a button is being held down
* @param button Is this button pressed down?
* @return true if button is pressed down
*/
bool isButtonDown(int button){
if(nrf_gpio_pin_read(button) == BUTTON_PRESSED){
return true;
}
return false;
}
/**
* @brief Pause the program until a button has been pressed and released
* @param button Wait on this button
*/
void pauseUntilPress(int button){
while(true){
if(nrf_gpio_pin_read(button) == BUTTON_PRESSED){
// Debounce
nrf_delay_ms(button);
if(nrf_gpio_pin_read(button) == BUTTON_PRESSED){
while(nrf_gpio_pin_read(button) == BUTTON_PRESSED);
return;
}
}
}
}
/**
* @brief Beeps the speaker for a duration at a certain frequency
* @param duration How long to beep
* @param frequency Tone freq in hz
*
* @note Busy waits, frequency might not be exact, might sound uneven if the softdevice needs to do BLE things
*/
void beep(int duration, int frequency){
// Figure out how many beeps
float period = 1000 / (float)frequency;
long counter = period * duration;
float delay = period / 2;
for(long i = 0; i < counter; i++){
nrf_gpio_pin_write(SPEAKER, 1);
nrf_delay_us(delay * 1000);
nrf_gpio_pin_write(SPEAKER, 0);
nrf_delay_us(delay * 1000);
}
}
/**
* Get a string from the user
* @param retString
* @param chars
* @param showScroll
*/
void getString(char *retString, uint8_t chars, bool showScroll) {
uint8_t curIndex = 0;
char string[32];
char pre;
char post;
int16_t xPos = util_gfx_cursor_x_get(), yPos = util_gfx_cursor_y_get();
bool done = false;
memcpy(string, retString, chars);
do {
if (string[curIndex] == 0) {
string[curIndex] = ' ';
}
pre = string[curIndex] - 1;
if (pre < FIRST_ALLOWED_CHAR) {
pre = LAST_ALLOWED_CHAR;
}
post = string[curIndex] + 1;
if (post > LAST_ALLOWED_CHAR) {
post = FIRST_ALLOWED_CHAR;
}
if (showScroll) {
util_gfx_fill_rect(xPos, yPos - 3, util_gfx_font_width() * chars + util_gfx_font_width(), util_gfx_font_height() * 3, COLOR_BLACK);
util_gfx_set_cursor(xPos + (util_gfx_font_width() * curIndex), yPos);
util_gfx_print_char(pre);
util_gfx_set_cursor(xPos, yPos + util_gfx_font_height());
util_gfx_print(string);
util_gfx_draw_line(
xPos + (util_gfx_font_width() * curIndex),
yPos + (util_gfx_font_height() * 2) - 4,
xPos + (util_gfx_font_width() * curIndex) + util_gfx_font_width(),
yPos + (util_gfx_font_height() * 2) - 4,
COLOR_RED);
util_gfx_set_cursor(xPos + (util_gfx_font_width() * curIndex), yPos + (util_gfx_font_height() * 2));
util_gfx_print_char(post);
}
else{
util_gfx_fill_rect(xPos, yPos - 3, util_gfx_font_width() * chars, util_gfx_font_height(), COLOR_BLACK);
util_gfx_set_cursor(xPos + (util_gfx_font_width() * curIndex), yPos);
util_gfx_print(string);
util_gfx_draw_line(xPos, yPos + util_gfx_font_height(), xPos + util_gfx_font_width(), yPos + util_gfx_font_height(), COLOR_RED);
}
bool waitForButton = true;
while (waitForButton) {
switch (getButton(false)) {
case USER_BUTTON_A:
done = true;
waitForButton = false;
while (getButton(false) == USER_BUTTON_A) {
}
break;
case USER_BUTTON_B:
done = true;
waitForButton = false;
while (getButton(false) == USER_BUTTON_B) {
}
break;
case USER_BUTTON_UP:
string[curIndex]++;
if (string[curIndex] > LAST_ALLOWED_CHAR) {
string[curIndex] = FIRST_ALLOWED_CHAR;
}
waitForButton = false;
nrf_delay_ms(100);
break;
case USER_BUTTON_DOWN:
string[curIndex]--;
if (string[curIndex] < FIRST_ALLOWED_CHAR) {
string[curIndex] = LAST_ALLOWED_CHAR;
}
waitForButton = false;
nrf_delay_ms(100);
break;
case USER_BUTTON_RIGHT:
if (string[curIndex] != ' ') {
if (curIndex < chars - 1) {
curIndex++;
}
}
waitForButton = false;
while (getButton(false) == USER_BUTTON_RIGHT) {
}
break;
case USER_BUTTON_LEFT:
if (curIndex > 0) {
curIndex--;
}
waitForButton = false;
while (getButton(false) == USER_BUTTON_LEFT) {
}
break;
default:
break;
}
nrf_delay_ms(1);
}
} while (!done);
memcpy(retString, string, chars);
}
/**
* Set the level up LEDs
* @param level
*/
void setLevelLEDs(LEVEL level) {
switch (level) {
default:
case LEVEL0:
nrf_gpio_pin_set(LED_LEVEL_UP_0);
nrf_gpio_pin_set(LED_LEVEL_UP_1);
nrf_gpio_pin_set(LED_LEVEL_UP_2);
nrf_gpio_pin_set(LED_LEVEL_UP_3);
break;
case LEVEL1:
nrf_gpio_pin_clear(LED_LEVEL_UP_0);
nrf_gpio_pin_set(LED_LEVEL_UP_1);
nrf_gpio_pin_set(LED_LEVEL_UP_2);
nrf_gpio_pin_set(LED_LEVEL_UP_3);
break;
case LEVEL2:
nrf_gpio_pin_clear(LED_LEVEL_UP_0);
nrf_gpio_pin_clear(LED_LEVEL_UP_1);
nrf_gpio_pin_set(LED_LEVEL_UP_2);
nrf_gpio_pin_set(LED_LEVEL_UP_3);
break;
case LEVEL3:
nrf_gpio_pin_clear(LED_LEVEL_UP_0);
nrf_gpio_pin_clear(LED_LEVEL_UP_1);
nrf_gpio_pin_clear(LED_LEVEL_UP_2);
nrf_gpio_pin_set(LED_LEVEL_UP_3);
break;
case LEVEL4:
nrf_gpio_pin_clear(LED_LEVEL_UP_0);
nrf_gpio_pin_clear(LED_LEVEL_UP_1);
nrf_gpio_pin_clear(LED_LEVEL_UP_2);
nrf_gpio_pin_clear(LED_LEVEL_UP_3);
break;
}
}
/**
* Set the power up LEDs
* @param powerUp
*/
void setPowerUpLEDs(POWERUP powerUp){
switch (powerUp) {
default:
case POWERUP_0:
nrf_gpio_pin_set(LED_POWER_UP_0);
nrf_gpio_pin_set(LED_POWER_UP_1);
nrf_gpio_pin_set(LED_POWER_UP_2);
nrf_gpio_pin_set(LED_POWER_UP_3);
break;
case POWERUP_1:
nrf_gpio_pin_clear(LED_POWER_UP_0);
nrf_gpio_pin_set(LED_POWER_UP_1);
nrf_gpio_pin_set(LED_POWER_UP_2);
nrf_gpio_pin_set(LED_POWER_UP_3);
break;
case POWERUP_2:
nrf_gpio_pin_clear(LED_POWER_UP_0);
nrf_gpio_pin_clear(LED_POWER_UP_1);
nrf_gpio_pin_set(LED_POWER_UP_2);
nrf_gpio_pin_set(LED_POWER_UP_3);
break;
case POWERUP_3:
nrf_gpio_pin_clear(LED_POWER_UP_0);
nrf_gpio_pin_clear(LED_POWER_UP_1);
nrf_gpio_pin_clear(LED_POWER_UP_2);
nrf_gpio_pin_set(LED_POWER_UP_3);
break;
case POWERUP_4:
nrf_gpio_pin_clear(LED_POWER_UP_0);
nrf_gpio_pin_clear(LED_POWER_UP_1);
nrf_gpio_pin_clear(LED_POWER_UP_2);
nrf_gpio_pin_clear(LED_POWER_UP_3);
break;
}
}
/**
* Get a list of files on a path
* @param files
* @param path
* @param fileMax
* @return
*/
uint8_t getFiles(char files[][9], char *path, uint8_t fileMax){
FRESULT ff_result;
DIR dir;
FILINFO fno;
ff_result = f_opendir(&dir, path);
if (ff_result) {
printf("Can't open extras\n");
return 0;
}
uint8_t counter = 0;
for (uint8_t i = 0; i < fileMax; i++) {
ff_result = f_readdir(&dir, &fno); /* Read a directory item */
if (ff_result != FR_OK || fno.fname[0] == 0) {
break; /* Break on error or end of dir */
}
if ((fno.fattrib & AM_DIR)) {
// Ignore subdirs
}
else{
char *ext = strrchr(fno.fname, '.') + 1;
if (strcmp(ext, "RAW") == 0){
// Add the file
memcpy(&files[counter++], fno.fname, ext - fno.fname - 1);
}
}
}
f_closedir(&dir);
return counter;
}
/**
* Calculate the CRC on a chunk of memory
* @param data
* @param len
* @return
*/
uint16_t calcCRC(uint8_t *data, uint8_t len, const uint16_t POLYNOM){
uint16_t crc;
uint8_t aux = 0;
crc = 0x0000;
while (aux < len){
crc = crc16(crc, data[aux], POLYNOM);
aux++;
}
return (crc);
}
/**
* Calculate the crc16 of a value
* @param crcValue
* @param newByte
* @return
*/
uint16_t crc16(uint16_t crcValue, uint8_t newByte, const uint16_t POLYNOM){
uint8_t i;
for (i = 0; i < 8; i++) {
if (((crcValue & 0x8000) >> 8) ^ (newByte & 0x80)){
crcValue = (crcValue << 1) ^ POLYNOM;
}else{
crcValue = (crcValue << 1);
}
newByte <<= 1;
}
return crcValue;
}
#define OVERFLOW ((uint32_t)(0xFFFFFFFF/32.768))
uint32_t millis_elapsed(uint32_t currentMillis, uint32_t previousMillis)
{
if(currentMillis < previousMillis) return(currentMillis + OVERFLOW + 1 - previousMillis);
return(currentMillis - previousMillis);
}
uint32_t millis(void)
{
return(app_timer_cnt_get() / 32.768);
}
void EEpwm_init() {
app_pwm_config_t pwm1_cfg = APP_PWM_DEFAULT_CONFIG_1CH(5000L, 11);
APP_ERROR_CHECK(app_pwm_init(&PWM1,&pwm1_cfg,NULL));
app_pwm_enable(&PWM1);
}
void EEpwm_set(int r)
{
r = r%101;
app_pwm_channel_duty_set(&PWM1, 0, 100-r);
}
void EEget_milliVolts(int r, int *v1, int *v2, int *v3) {
*v1 = EE_VOLT(EE_R4) * r / 100;
*v2 = EE_VOLT(EE_R3 +EE_R4) * r / 100;
*v3 = EE_VOLT(EE_R2 + EE_R3 + EE_R4) * r / 100;
}
//Turns hex 0x2305 to 2305
uint32_t hex2dec(uint32_t v) {
uint32_t val = 0;
const int tens[] = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000};
for (int i=0; i<8; ++i)
val += ((v >> (i*4)) & 0xF) * tens[i];
return val;
}