Semaphore attempt ben
Dependencies: mbed mbed-rtos 4DGL-uLCD-SE SDFileSystem ATParser
Revision 5:dc2f1a9c92a2, committed 2020-04-29
- Comitter:
- bleverett3
- Date:
- Wed Apr 29 01:24:34 2020 +0000
- Parent:
- 4:57e7983c861c
- Commit message:
- Semaphore
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 57e7983c861c -r dc2f1a9c92a2 main.cpp --- a/main.cpp Mon Apr 27 21:04:46 2020 +0000 +++ b/main.cpp Wed Apr 29 01:24:34 2020 +0000 @@ -36,6 +36,8 @@ //RTOS Mutex Lock Mutex mutex_lock; +uint16_t max_count = 1; +Semaphore lcd_sem(1); time_t seconds; @@ -58,6 +60,7 @@ void parse_RSSI() { mutex_lock.lock(); + lcd_sem.wait(); at.send("AT+BLEGETRSSI") && at.read(buffer, 10); if(buffer[0] == '-') { datalogged = 1; @@ -72,6 +75,7 @@ RSSI_array[averageCount] = total; } averageCount++; + int temp_risk = risk_level; if(averageCount > 15 && buffer[0] == '-') { averageCount = 0; int average = calculate_average(RSSI_array, 15); @@ -85,6 +89,9 @@ risk_level = 0; } } + if (temp_risk != risk_level) { + lcd_sem.release(); + } pc.printf("Risk level: "); pc.printf("%i\n", risk_level); } else { @@ -179,6 +186,7 @@ mutex_lock.unlock(); while(1) { mutex_lock.lock(); + lcd_sem.wait(); if(risk_level <= 1 && datalogged) { mutex_lock.lock(); uLCD.cls(); @@ -210,6 +218,7 @@ uLCD.printf("Hazard"); mutex_lock.unlock(); } + lcd_sem.release(); mutex_lock.unlock(); } }