Hi All
I am having trouble using Timeout. From my main loop if i write to my LCD i want to set a timer for 10sec for the backlight. Then turn off backlight after the 10sec. I can get this and the callback routine routine to work quite simply. But i think there is exception if the timout interupt is called when the LCD is in the middle of doing something. This is my code.
using namespace std::chrono;
Timeout toutTest;
Timer timerTest;
volatile bool lcdTimmerFlag =0 ;
// Print to LCD
/*!
@param Message [in] String or character for LCD to Print
@param clearLcdFirst [in] Clear screen first, Yes No
@param Pos [in] Position of cursor, Default = 0
@param Line [in] Line number, 0 = ist line, 1 = 2nd Line, Default = 0
*/
void lcdPrint (const char* Message, bool clearLcdFirst = true,int Pos =0,
int Line =0){
microseconds toutRemain = toutTest.remaining_time();
timerTest.stop();
if (clearLcdFirst == true) {lcd.clear();}
lcd.setCursor(Pos,Line);
lcd.print(Message);
if (lcdTimmerFlag == FALSE){
lcdBackLight(ON);
timerTest.start();
toutTest.attach(&lcdBackLightOff, 10s);
lcdTimmerFlag = TRUE;
} else {
timerTest.start();
toutTest.attach(&lcdBackLightOff, toutRemain);
}
}
//
void lcdBackLightOff() {
timerTest.stop();
toutTest.detach();
lcdBackLight(OFF);
lcdTimmerFlag = FALSE;
}
I belive i cant disable the interupt so i have attempted to: 1, stop the timer, 2, read the 'timeout.remaining_time()' 3, DO LCD instructions 4, reattached timeout with remainder.
Am i completly barking up the wrong tree here?
a few other problems i am having is the following line in PIO is always <opimised out> . So it cant be used.
microseconds toutRemain = toutTest.remaining_time();
if i volitile it ie volatile microseconds toutRemain = toutTest.remaining_time();
then the line toutTest.attach(&lcdBackLightOff, toutRemain);
brings up a TYPE error.
Any experience or examples would be greatly appreciated. Cheers