/*--------------------------------------------------------------------------------------------------------------- FUNCTION: readFromSerialPort DATE: Oct 3, 2015 AUTHOR: Martin Minkov INTERFACE: DWORD WINAPI readFromSerialPort(LPVOID n) n: Initially is a LPVOID pointer but is then casted to HWND type. When this function is called, n will typically represent the handle to the main window which is created in Application.cpp RETURNS: DWORD NOTES: This function is used in a thread which is declared in Application.cpp. If the application is in "Connection Mode" the function will contiously check if there is input to read from the serial port. If there isn't, it will wait until GetOverlappedResult returns which indicates that there is characters to draw. It calls upon drawToScreen to display the input onto the window, which is defined in Presentation.cpp ----------------------------------------------------------------------------------------------------------------*/ DWORD WINAPI readFromSerialPort(LPVOID n) { HWND hwnd = (HWND)n; while (1) { if (connected == false) break; OVERLAPPED osRead = { 0 }; DWORD bytesRead; osRead.hEvent = CreateEvent(NULL, TRUE, TRUE, NULL); if (osRead.hEvent == NULL) MessageBox(NULL, "Error in creating hEvent", "", MB_OK); if (ReadFile(hComm, str, 1, &bytesRead, &osRead) && (GetLastError() == ERROR_IO_PENDING)) { drawToScreen(hwnd, str); } else { if ((GetOverlappedResult(hComm, &osRead, &bytesRead, TRUE))) { drawToScreen(hwnd, str); } } CloseHandle(osRead.hEvent); } return 0; }
void DrawWidget::endDrawing(bool drawToScreen_) { p.end(); if(drawToScreen_) drawToScreen(); }
int main() { initProgram(); #ifdef PROFILING int counter = 0; irqSet(IRQ_HBLANK, hblank_handler); irqEnable(IRQ_HBLANK); cygprofile_begin(); cygprofile_enable(); #endif while(1) { updateStreamLoop(); if(!checkHelp()) { if(getLCDState() == LCD_ON) { updateStreamLoop(); clearHelpScreen(); } updateStreamLoop(); drawControls(getLCDState() != LCD_ON); updateStreamLoop(); checkKeys(); executeQueuedControls(); // Split here because the state can change in checkKeys if(getLCDState() == LCD_ON) { #ifdef SCREENSHOT_MODE takeScreenshot(); #endif updateStreamLoop(); drawToScreen(); } else { updateStreamLoop(); checkEndSound(); } updateStreamLoop(); checkSleepState(); } #ifdef PROFILING counter++; if(counter == 700) { cygprofile_disable(); cygprofile_end(); } #endif } }
int main( int argc, char** argv ) { drawToScreen(draw, WIDTH, HEIGHT); }