bool CPeripherals::InitPeripherals(CTouchScreenDlg* pOwner) { m_pOwner = pOwner; m_killReadSerialPortThread = false; InitSerialPort(); TRACE("Serial Communications Thread Started.\n"); return true; }
BOOL SetupComPort() { if(gComPortInfo.bIsOpen == TRUE) { return TRUE; } if(gComPortInfo.bIsConnect == FALSE) { return FALSE; } if(InitSerialPort(gComPortInfo.ComID) == FALSE) { return FALSE; } gComPortInfo.bIsOpen = TRUE; EnableComboBox(FALSE); return TRUE; }
static void Configure ( void ) { // ------- Configure the UART connected to the AVR controller ------- if ( ENABLE_DEBUG_CONSOLE ) { VERIFY( pio_configure( PIOA, PIO_PERIPH_A, PIO_PA8A_URXD | PIO_PA9A_UTXD, PIO_DEFAULT ) ); // Enable the pull-up resistor for RX0. pio_pull_up( PIOA, PIO_PA8A_URXD, ENABLE ) ; InitSerialPort( false ); SerialSyncWriteStr( "--- EmptyDue " PACKAGE_VERSION " ---" EOL ); SerialSyncWriteStr( "Welcome to the Arduino Due's programming USB serial port." EOL ); } SetUserPanicMsgFunction( &PrintPanicMsg ); // ------- Perform some assorted checks ------- assert( IsJtagTdoPullUpActive() ); // Check that the brown-out detector is active. #ifndef NDEBUG const uint32_t supcMr = SUPC->SUPC_MR; assert( ( supcMr & SUPC_MR_BODDIS ) == SUPC_MR_BODDIS_ENABLE ); assert( ( supcMr & SUPC_MR_BODRSTEN ) == SUPC_MR_BODRSTEN_ENABLE ); #endif // ------- Configure the watchdog ------- WDT->WDT_MR = WDT_MR_WDDIS; }
int Game(int port, const char *ApplicationPath) { // Variabeln definieren char Name[20]; // Array für Spielername int Zeichen; // Variable zur Verarbeitung der eingelesenen Zeichen int key; // Variable zum einlesen der Zeichen von der Tastatur int dir = 0; // Variable zum speichern der Richtung int dir_old = 0; // Variable zum speichern der letzten Richtung int score; // Variable für den Score int winner; // Variable für Rückgabewert der Highscorefunktion // Wird 1 wenn Highscore geknackt wurde, sonst 0 int i = 0; // Bildschirm löschen ClearWindow(); // Spielernamen einlesen SelectFont("Arial MS", 15, FONT_NORMAL); DrawTextXY (50, 50, COL_GREEN, "Bitte Namen eingeben:"); while((key = GetKeyPress()) != W_KEY_RETURN ){ Zeichen = key; // Anzahl der Zeichen begrenzen, Leertaste unterdrücken if ((Zeichen >= ' ')&&(i < 19) && (Zeichen != 0x20) ){ Name[i] = Zeichen; Name[i+1] = '\0'; i++; } // Möglichkeit Zeichen zu löschen if( Zeichen == '\b'){ if(i>0){ i--; Name[i]='\0'; DrawFilledRectangle(270, 25, 300, 40, COL_BLACK, 1); } } // Bisherige Eingabe anzeigen DrawTextXY (270, 50, COL_RED, Name); } DrawTextXY (50, 80, COL_GREEN, "Now playing! [ESC] to escape"); if (InitSerialPort(port, Bd9600, P_NONE, 8, 1) == 0) // COM1 { printf("\nPort opened: COM%d", port); do { if(IsKeyPressReady()) // Wenn Taste gedrückt { key = GetKeyPress(); switch(key) { case W_KEY_CURSOR_UP: if(dir_old != 'd') { dir = 'u'; } break; case W_KEY_CURSOR_DOWN: if(dir_old != 'u') { dir = 'd'; } break; case W_KEY_CURSOR_LEFT: if(dir_old != 'r') { dir = 'l'; } break; case W_KEY_CURSOR_RIGHT: if(dir_old != 'l') { dir = 'r'; } break; case W_KEY_ESCAPE: case W_KEY_CLOSE_WINDOW: ShutdownSerialPort(); return 0; break; default: key = NO_VALID_KEY; break; } // Nur wenn Key gültig ist und der Wert geändert hat ein Zeichen ans Carmekit senden if(dir != dir_old) { SendByteToSerialPort(dir); // Alter Wert speichern dir_old = dir; } } score = GetByteFromSerialPort(); } while (score == -1); ShutdownSerialPort(); winner=highscore(Name , score , ApplicationPath); SelectFont("Arial MS", 20, FONT_ITALIC); if(winner == 1) { DrawTextXY (220, 200, COL_GREEN, "Du hast den High Score geknackt!"); } else { DrawTextXY (220, 200, COL_GREEN, "Game over."); } SelectFont("Arial MS", 15, FONT_NORMAL); DrawTextXY (220, 230, COL_GREEN, "Press any key to continue."); while(!IsKeyPressReady()) ; } return 0; }