Simple test program to get familiar with functionality of MBED RTOS on ST Nucleo-F411RE. Tasks for LED blinking, user button, temperature measurement with DS1620, temperature measurement with internal temperature sensor of ST32F411RE, ultrasonic distance measurement and displaying result on 16x2 TextLCD.
Dependencies: DS1620_improved TextLCD_improved mbed-rtos mbed
tsk_display.cpp@18:be0130c42925, 2015-12-18 (annotated)
- Committer:
- Jan Tetour
- Date:
- Fri Dec 18 20:00:56 2015 +0100
- Revision:
- 18:be0130c42925
- Parent:
- 17:94c385ff2641
Minor formatting changes.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Jan Tetour | 18:be0130c42925 | 1 | /* |
Jan Tetour | 18:be0130c42925 | 2 | * TSK_DISPLAY.CPP |
Jan Tetour | 18:be0130c42925 | 3 | */ |
dzoni | 9:645f0e517017 | 4 | #include "mbed.h" |
dzoni | 9:645f0e517017 | 5 | #include "rtos.h" |
dzoni | 9:645f0e517017 | 6 | |
dzoni | 9:645f0e517017 | 7 | #include "TextLCD.h" |
dzoni | 9:645f0e517017 | 8 | |
dzoni | 17:94c385ff2641 | 9 | #include "tsk_main.h" |
dzoni | 9:645f0e517017 | 10 | #include "tsk_display.h" |
dzoni | 9:645f0e517017 | 11 | #include "tsk_temp.h" |
dzoni | 17:94c385ff2641 | 12 | #include "tsk_inttemp.h" |
dzoni | 9:645f0e517017 | 13 | #include "tsk_dist.h" |
dzoni | 9:645f0e517017 | 14 | |
dzoni | 15:a627638edd9c | 15 | static TextLCD *lcd; |
dzoni | 9:645f0e517017 | 16 | |
dzoni | 12:1de8b271e292 | 17 | uint32_t initDisplay(void const *args) { |
dzoni | 13:f62b10a6e1c5 | 18 | |
dzoni | 13:f62b10a6e1c5 | 19 | lcd = new TextLCD(PA_8, PA_7, PA_9, PA_1, PB_5, PA_10, TextLCD::LCD16x2); |
dzoni | 13:f62b10a6e1c5 | 20 | |
dzoni | 17:94c385ff2641 | 21 | wait_ms(250); |
dzoni | 13:f62b10a6e1c5 | 22 | lcd->cls(); |
dzoni | 13:f62b10a6e1c5 | 23 | |
dzoni | 13:f62b10a6e1c5 | 24 | return 1; |
dzoni | 13:f62b10a6e1c5 | 25 | } |
dzoni | 13:f62b10a6e1c5 | 26 | |
dzoni | 13:f62b10a6e1c5 | 27 | uint32_t disposeDisplay(void const *args) { |
dzoni | 13:f62b10a6e1c5 | 28 | |
dzoni | 13:f62b10a6e1c5 | 29 | delete lcd; |
dzoni | 13:f62b10a6e1c5 | 30 | lcd = NULL; |
dzoni | 13:f62b10a6e1c5 | 31 | |
dzoni | 12:1de8b271e292 | 32 | return 1; |
dzoni | 12:1de8b271e292 | 33 | } |
dzoni | 12:1de8b271e292 | 34 | |
dzoni | 12:1de8b271e292 | 35 | |
dzoni | 9:645f0e517017 | 36 | void disp_thread(void const *args) { |
dzoni | 17:94c385ff2641 | 37 | float dist; |
dzoni | 17:94c385ff2641 | 38 | float temp; |
dzoni | 17:94c385ff2641 | 39 | float intTemp; |
dzoni | 17:94c385ff2641 | 40 | uint32_t dist_raw; |
dzoni | 17:94c385ff2641 | 41 | uint32_t temp_raw; |
dzoni | 17:94c385ff2641 | 42 | |
dzoni | 17:94c385ff2641 | 43 | while (true) { |
dzoni | 17:94c385ff2641 | 44 | mutexDist.lock(); |
dzoni | 17:94c385ff2641 | 45 | dist = dist_data.distance; |
dzoni | 17:94c385ff2641 | 46 | dist_raw = dist_data.timerTicks; |
dzoni | 17:94c385ff2641 | 47 | mutexDist.unlock(); |
dzoni | 9:645f0e517017 | 48 | |
dzoni | 17:94c385ff2641 | 49 | mutexTemp.lock(); |
dzoni | 17:94c385ff2641 | 50 | temp = temp_data.temperature; |
dzoni | 17:94c385ff2641 | 51 | temp_raw = temp_data.temp_raw; |
dzoni | 17:94c385ff2641 | 52 | mutexTemp.unlock(); |
dzoni | 17:94c385ff2641 | 53 | |
dzoni | 17:94c385ff2641 | 54 | mutexIntTemp.lock(); |
dzoni | 17:94c385ff2641 | 55 | intTemp = int_temp_data.temperature; |
dzoni | 17:94c385ff2641 | 56 | mutexIntTemp.unlock(); |
dzoni | 17:94c385ff2641 | 57 | |
dzoni | 17:94c385ff2641 | 58 | uiCnt += 2; |
dzoni | 17:94c385ff2641 | 59 | |
dzoni | 13:f62b10a6e1c5 | 60 | lcd->cls(); |
dzoni | 17:94c385ff2641 | 61 | // lcd->printf("%4.2fmm (%4u)", dist, dist_raw); |
dzoni | 17:94c385ff2641 | 62 | lcd->printf("%4.2fmm (%4u)", dist, uiCnt); |
dzoni | 13:f62b10a6e1c5 | 63 | lcd->locate(0, 1); |
dzoni | 17:94c385ff2641 | 64 | // lcd->printf("%3.2f%cC (%3u)", temp, 0xdf, temp_raw); |
dzoni | 17:94c385ff2641 | 65 | lcd->printf("%3.1f%cC (%2.1f)", temp, 0xdf, intTemp); |
dzoni | 12:1de8b271e292 | 66 | |
dzoni | 17:94c385ff2641 | 67 | Thread::wait(2000); |
dzoni | 9:645f0e517017 | 68 | } |
Jan Tetour | 18:be0130c42925 | 69 | } |