GIU\ZF
Dependencies: MCP23017 WattBob_TextLCD mbed-rtos mbed
Fork of rtos_basic by
Diff: tasks/task_group1.cpp
- Revision:
- 15:524de2b2ef8e
- Parent:
- 14:8a6c20435523
- Child:
- 16:0ada6cbd41e2
--- a/tasks/task_group1.cpp Tue Mar 27 16:11:18 2018 +0000 +++ b/tasks/task_group1.cpp Tue Mar 27 18:55:43 2018 +0000 @@ -1,4 +1,33 @@ #include "core.h" +namespace display{ + //Display on MBED text display • odometer value • average speed + const float freq = 2.0f; //hz + + //I/O + MCP23017 *port; + WattBob_TextLCD *lcd; + + void init(){ + port = new MCP23017(p9, p10, 0x40); + lcd = new WattBob_TextLCD(port); + port->write_bit(1,BL_BIT); // LCD backlight on. + lcd->cls(); + } + static inline void hotLoop(){ + lcd->cls(); + + runTimeParams::liveAccess.lock(); + float odometer = runTimeParams::odometer; + float avgSpeed = runTimeParams::avgSpeed; + runTimeParams::liveAccess.unlock(); + + lcd->locate(0,0); //located col, row. + lcd->printf("Odo=%.2f",odometer); + + lcd->locate(1,0); //located col, row. + lcd->printf("Speed=%.2f",avgSpeed); + } +} namespace task_group_1{ Thread thread; @@ -25,7 +54,8 @@ // Run all tasks - display::hotLoop(); + static const int tick_interval_display = int((freq/display::freq)+0.5f); + if (!(tick%tick_interval_display )) display::hotLoop(); tick++; @@ -34,8 +64,8 @@ #if DEBUG_MODE runTimeParams::liveAccess.lock(); - const int debug_log_interval = int(freq/dequeueMail::freq); - if (!(tick%debug_log_interval)){ + static const int tick_interval_debug_log = int((freq/dequeueMail::freq)+0.5f); + if (!(tick%tick_interval_debug_log)){ runTimeParams::liveAccess.lock(); runTimeParams::debugLog += "task_group_1," + to_string(exec_time) + "," + to_string(sleepTime) + "," @@ -43,7 +73,7 @@ runTimeParams::liveAccess.unlock(); } - if (tick==debug_log_interval*1) tick=0; + if (tick==tick_interval_debug_log*1) tick=0; runTimeParams::liveAccess.unlock(); #endif