/******************************************************************** * Function: void ProcessIO(void) * * PreCondition: None * * Input: None * * Output: None * * Side Effects: None * * Overview: This function is a place holder for other user * routines. It is a mixture of both USB and * non-USB tasks. * * Note: None *******************************************************************/ void ProcessIO(void) { //BMA150_REG reg_MSB; //BMA150_REG reg_LSB; unsigned int w1; if(DemoIntroState == 0xFF) { //BL_CheckLoaderEnabled(); if (g_ballGth == 0 && g_ballGtt == 0) Step(0.04f, 1); else Step(0.04f, 0); DrawScene(); if (g_endGame == 1) { g_endGame = 0; DemoIntroState = 8; } w1 = mTouchReadButton(3); if (w1 < 600) { DemoIntroState = 6; g_menuSelected = 0; FillDisplay(0x00); } } // User Application USB tasks //if((USBDeviceState < CONFIGURED_STATE)||(USBSuspendControl==1)) return; // Soft Start the APP_VDD if(AppPowerReady() == FALSE) return; DemoIntroduction(); } //end ProcessIO
void DemoIntroduction(void) { switch(DemoIntroState) { case 0: ResetDevice(); FillDisplay(0x00); oledPutROMString((ROM_STRING)" PIC18F Starter Kit ",0,0); oledPutROMString((ROM_STRING)"HID Custom Demo v1.0 ",1,0); oledPutROMString((ROM_STRING)"Press Menu to proceed",6,0); DemoIntroState = 1; break; case 1: if(CheckButtonPressed() == TRUE) { DemoIntroState++; } break; case 2: FillDisplay(0x00); oledPutROMString((ROM_STRING)"In this demo, the ",0,0); oledPutROMString((ROM_STRING)" board will act like",1,0); oledPutROMString((ROM_STRING)" a USB custom HID ",2,0); oledPutROMString((ROM_STRING)" device. ",3,0); oledPutROMString((ROM_STRING)" ",4,0); oledPutROMString((ROM_STRING)" ",5,0); oledPutROMString((ROM_STRING)"Press Menu to proceed",6,0); DemoIntroState = 3; break; case 3: if(CheckButtonPressed() == TRUE) { DemoIntroState++; } break; case 4: oledPutROMString((ROM_STRING)"Connect the board to ",0,0); oledPutROMString((ROM_STRING)" the host computer ",1,0); oledPutROMString((ROM_STRING)" and run the ",2,0); oledPutROMString((ROM_STRING)" HID PnP Demo.exe ",3,0); oledPutROMString((ROM_STRING)" ",4,0); oledPutROMString((ROM_STRING)" ",5,0); oledPutROMString((ROM_STRING)"Press Menu to proceed",6,0); DemoIntroState = 5; break; case 5: if(CheckButtonPressed() == TRUE) { DemoIntroState++; } break; case 6: oledPutROMString((ROM_STRING)"The PC application is",0,0); oledPutROMString((ROM_STRING)" reading raw data ",1,0); oledPutROMString((ROM_STRING)" from the capacitive",2,0); oledPutROMString((ROM_STRING)" pads, accelerometer",3,0); oledPutROMString((ROM_STRING)" and potentiometer. ",4,0); oledPutROMString((ROM_STRING)" ",5,0); oledPutROMString((ROM_STRING)"Press Menu to proceed",6,0); DemoIntroState++; break; case 7: if(CheckButtonPressed() == TRUE) { DemoIntroState++; } break; case 8: oledPutROMString((ROM_STRING)"Hold the menu button ",0,0); oledPutROMString((ROM_STRING)" to return to the ",1,0); oledPutROMString((ROM_STRING)" demo menu. ",2,0); oledPutROMString((ROM_STRING)" ",3,0); oledPutROMString((ROM_STRING)" ",4,0); oledPutROMString((ROM_STRING)" ",5,0); oledPutROMString((ROM_STRING)" ",6,0); DemoIntroState = 0xFF; break; default: break; } }
/********************************************************************* * Function: void ResetDevice() * * PreCondition: none * * Input: none * * Output: none * * Side Effects: none * * Overview: resets LCD, initializes PMP * * Note: none * ********************************************************************/ void ResetDevice(void){ unsigned long i; oledWR = 0; oledWR_TRIS = 0; oledRD = 0; oledRD_TRIS = 0; oledCS = 1; oledCS_TRIS = 0; oledD_C = 0; oledD_C_TRIS = 0; oledRESET = 1; //1 = not in reset, 0 = in reset oledRESET_TRIS = 0; //Reset the OLED module oledRESET = 0; for(i=0;i<100;i++){} oledRESET = 1; for(i=0;i<100;i++){} // Setup Display WriteCommand(0xAE); // turn off the display (AF=ON, AE=OFF) WriteCommand(0xDB); // set VCOMH WriteCommand(0x23); WriteCommand(0xD9); // set VP WriteCommand(0x22); ////////////////////////////// // User Set Up ////////////////////////////// // Re-map WriteCommand(0xA1); // [A0]:column address 0 is map to SEG0 // [A1]:column address 131 is map to SEG0 // COM Output Scan Direction WriteCommand(0xC8); // C0 is COM0 to COMn, C8 is COMn to COM0 // COM Pins Hardware Configuration WriteCommand(0xDA); // set pins hardware configuration WriteCommand(0x12); // Multiplex Ratio WriteCommand(0xA8); // set multiplex ratio WriteCommand(0x3F); // set to 64 mux // Display Clock Divide WriteCommand(0xD5); // set display clock divide WriteCommand(0xA0); // set to 100Hz // Contrast Control Register WriteCommand(0x81); // Set contrast control WriteCommand(0x60); // display 0 ~ 127; 2C // Display Offset WriteCommand(0xD3); // set display offset WriteCommand(0x00); // no offset //Normal or Inverse Display WriteCommand(0xA6); // Normal display WriteCommand(0xAD); // Set DC-DC WriteCommand(0x8B); // 8B=ON, 8A=OFF //Clear out the display RAM so that it initializes with all pixels off FillDisplay(0x00); //Turn off all the pixels on the OLED display // Display ON/OFF WriteCommand(0xAF); // AF=ON, AE=OFF //Startup delay DelayMs(150); //SH1101A datasheet suggests waiting 150ms after turning //on display. This doesn't appear strictly needed, //but presumably gives the boost circuitry the time //needed to charge to full voltage for normal operation. // Entire Display ON/OFF WriteCommand(0xA4); // A4=ON // Display Start Line WriteCommand(0x40); // Set display start line // Lower Column Address WriteCommand(0x00+OFFSET); // Set lower column address // Higher Column Address WriteCommand(0x10); // Set higher column address }
void DemoIntroduction(void) { unsigned char i ; unsigned int w1, w2; unsigned char touchedNow; SCROLL_WHEEL_DIRECTION scrollDir; switch(DemoIntroState) { case 0: ResetDevice(); FillDisplay(0x00); oledPutROMString((ROM_STRING)" Labyrinth Demo v1.0 ",0,0); oledPutROMString((ROM_STRING)" by Daniel Szot ",1,0); oledPutROMString((ROM_STRING)" ",2,0); oledPutROMString((ROM_STRING)" MB Turnkey Design ",3,0); oledPutROMString((ROM_STRING)" mbturnkeydesign.com ",4,0); oledPutROMString((ROM_STRING)"Press Menu to proceed",6,0); DemoIntroState = 1; break; case 1: if(CheckButtonPressed() == TRUE) { DemoIntroState=4; } break; case 4: oledPutROMString((ROM_STRING)" 1. Use scroll to ",0,0); oledPutROMString((ROM_STRING)" select menu items. ",1,0); oledPutROMString((ROM_STRING)" 2. Tilt the board ",2,0); oledPutROMString((ROM_STRING)" to move the ball. ",3,0); oledPutROMString((ROM_STRING)" 3. Have a good time.",4,0); oledPutROMString((ROM_STRING)" ",5,0); oledPutROMString((ROM_STRING)"Press Menu to proceed",6,0); DemoIntroState = 5; break; case 5: if(CheckButtonPressed() == TRUE) { DemoIntroState++; } break; case 6: scrollDir = GetScrollDirection(); if (scrollDir == SCROLL_UP) { if (g_menuSelected > 0) g_menuSelected --; } else if (scrollDir == SCROLL_DOWN) { if (g_menuSelected < 3) g_menuSelected ++; } oledPutROMString((ROM_STRING)" LABIRYNTH MENU ",0,0); oledPutROMString(empty_line,1,0); if (g_menuSelected == 0) oledPutROMNegString((ROM_STRING)" NEW GAME ",2,0); else oledPutROMString((ROM_STRING)" NEW GAME ",2,0); if (g_menuSelected == 1) oledPutROMNegString((ROM_STRING)" SELECT LEVEL ",3,0); else oledPutROMString((ROM_STRING)" SELECT LEVEL ",3,0); if (g_menuSelected == 2) oledPutROMNegString((ROM_STRING)" CALIBRATE ",4,0); else oledPutROMString((ROM_STRING)" CALIBRATE ",4,0); if (g_menuSelected == 3) oledPutROMNegString((ROM_STRING)" QUIT GAME ",5,0); else oledPutROMString((ROM_STRING)" QUIT GAME ",5,0); oledPutROMString(empty_line,6,0); w1 = mTouchReadButton(0); if (w1 < 600) { switch(g_menuSelected) { case 0: DemoIntroState = 0xFF; g_level=0; loadLevel(g_level); break; case 1: DemoIntroState = 9; DelayMs(100); FillDisplay(0x00); g_menuSelected = 0; firstLevel = 0; break; case 2: DemoIntroState = 7; DelayMs(100); FillDisplay(0x00); break; case 3: _asm RESET _endasm break; } } break; case 7: CalibrateAcc(); break; case 8: FillDisplay(0xFF); oledPutROMNegString((ROM_STRING)" CORNGRATULATIONS! ",0,0); oledPutROMNegString((ROM_STRING)" You won nothing ",2,0); oledPutROMNegString((ROM_STRING)" You just waste your ",3,0); oledPutROMNegString((ROM_STRING)" PRECIOUS time :) ",4,0); DelayMs(2000); DemoIntroState = 6; FillDisplay(0x00); g_level = 0; g_ballGtt = 0; break; case 9: SelectLevel(); break; default: break; } }