/******************************************************************** * 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) { //Blink the LEDs according to the USB device status BlinkUSBStatus(); // User Application USB tasks if((USBDeviceState < CONFIGURED_STATE)||(USBSuspendControl==1)) return; if(Switch3IsPressed()) //Note: Switch3IsPressed() implements only the { //crudest of switch debounce code. As a result //some pusbbuttons will behave temperamentally. //Proper debounce code should be used which //implements delays millseconds long, and //checks/reckecks pushbutton state many times to //verify that the state is stable. In order //to avoid using blocking functions, or //microcontroller timer resources this feature //is not implemented in this example. emulate_mode = !emulate_mode; } //Call the function that emulates the mouse Emulate_Mouse(); }//end ProcessIO
/*---------------------------------------------------------------------------* * Routine: App_ProgramMode *---------------------------------------------------------------------------* * Description: * Put the unit into programming mode by putting the control pin into * program mode and mimicing the TX/RX lines on SCI2 with the * RX/TX lines of SCI6. * Inputs: * void * Outputs: * void *---------------------------------------------------------------------------*/ void App_Startup(void) { /* At power up, load up the default settings */ if(NVSettingsLoad(&G_nvsettings)) NVSettingsSave(&G_nvsettings); /* Initialize the module now that a mode is chosen (above) */ App_InitModule(); #if 0 /* Grab switch 1 state at startup before we init the module (which */ /* can take longer than people want to hold the button). */ sw1 = Switch1IsPressed(); sw2 = Switch2IsPressed(); sw3 = Switch3IsPressed(); /* Show the mode immediately before initialization */ if (sw1) { DisplayLCD(LCD_LINE3, "SW1 Pressed!"); } else if (sw2) { DisplayLCD(LCD_LINE3, "SW2 Pressed!"); } else if (sw3) { DisplayLCD(LCD_LINE3, "SW3 Pressed!"); } /* Initialize the module now that a mode is chosen (above) */ App_InitModule(); /* Was switch1 held? */ if (sw1) { /* Yes, then go into Limited AP point */ App_StartupLimitedAP(); /* Now go into web provisioning mode */ App_WebProvisioning(); } else if (sw2) { App_StartWPS(); /* Now go into web provisioning mode */ App_WebProvisioning(); } else if (sw3) { /* User wants to do over the air programming */ App_OverTheAirProgramming(); } else #endif App_StartupADKDemo(); }
/*---------------------------------------------------------------------------*/ void AppTCPSetIPMenu(ATLIBGS_NetworkStatus *pNetStatus) { uint8_t ipString[13] = " 001 "; uint8_t ipAddressStr[15]; uint8_t ipByte; uint8_t ipNums[3] = {0, 0, 1}; uint8_t placeSel = 0; uint8_t blink = 0; // Build string to display for first three IP bytes (etc. "192.168.0.") sprintf((char*)ipAddressStr, "%d.%d.%d.", pNetStatus->addr.ipv4[0], pNetStatus->addr.ipv4[1], pNetStatus->addr.ipv4[2]); // Make sure SW2 has been released from AppMenu while(Switch2IsPressed()) {} // Get previous fourth IP byte from NVsettings and format it into ipNums array ipByte = G_nvsettings.webprov.tcpIPClientHostIP; ipNums[0] = (ipByte/100); ipNums[1] = (ipByte%100)/10; ipNums[2] = (ipByte%10); // Display Remote IP Settings Menu DisplayLCD(LCD_LINE3, "Remote IP: "); DisplayLCD(LCD_LINE4, ipAddressStr); DisplayLCD(LCD_LINE6, "SW1: Add 1 "); DisplayLCD(LCD_LINE7, "SW2: Next # "); DisplayLCD(LCD_LINE8, "SW3: Accept "); while(1) { // Update IP string based on ipNums ipString[4] = ipNums[0]+48; ipString[5] = ipNums[1]+48; ipString[6] = ipNums[2]+48; // Monitor Switches if(Switch1IsPressed()){ // SW1 is pressed, increment the selected digit. ipNums[placeSel]++; if(ipNums[0]>2) ipNums[0] = 0; if(ipNums[1]>9) ipNums[1] = 0; if(ipNums[2]>9) ipNums[2] = 0; if(ipNums[0] == 2){ if(ipNums[1] > 5) ipNums[1] = 0; if((ipNums[1] == 5) && (ipNums[2] > 5)) ipNums[2] = 0; } while(Switch1IsPressed()) {} } else if(Switch2IsPressed()){ // SW2 is pressed, change the selected digit. placeSel++; if(placeSel > 2) placeSel = 0; while(Switch2IsPressed()) {} } else if(Switch3IsPressed()){ // SW3 is pressed. We're done, break out of loop. break; } if(blink > 5){ ipString[placeSel+4] = ' '; if(blink > 10) blink = 0; } DisplayLCD(LCD_LINE5, ipString); MSTimerDelay(50); blink++; } // Clear menu and display ip address. DisplayLCD(LCD_LINE3, ""); DisplayLCD(LCD_LINE4, ""); DisplayLCD(LCD_LINE5, ipAddressStr); DisplayLCD(LCD_LINE6, ipString); DisplayLCD(LCD_LINE7, ""); DisplayLCD(LCD_LINE8, ""); // Save remote ip (fourth byte) G_nvsettings.webprov.tcpIPClientHostIP = (ipNums[0]*100) + (ipNums[1]*10) + ipNums[2]; NVSettingsSave(&G_nvsettings); }
int main(void) { AppMode_T AppMode; APP_STATE_E state=UPDATE_TEMPERATURE; char LCDString[30], temp_char[2]; uint16_t temp; float ftemp; HardwareSetup(); /************************initializa LCD module********************************/ SPI2_Init(); InitialiseLCD(); led_init(); MSTimerInit(); /* Default app mode */ AppMode = GAINSPAN_DEMO; /* If the CIK is exist, auto into the Exosite mode */ NVSettingsLoad(&GNV_Setting); /* Determine if SW1 & SW3 is pressed at power up to enter programming mode */ if (Switch1IsPressed() && Switch3IsPressed()) { AppMode = PROGRAM_MODE; } else if(Switch3IsPressed() && Switch2IsPressed()) { AppMode = EXOSITE_ERASE; } else if(Switch1IsPressed()) { AppMode = RUN_EXOSITE; } else if(Switch2IsPressed()) { AppMode = RUN_PROVISIONING; } else if(Switch3IsPressed()) { AppMode = RUN_OVER_AIR_DOWNLOAD; } if(AppMode == GAINSPAN_DEMO) { LCDDisplayLogo(); LCDSelectFont(FONT_SMALL); DisplayLCD(LCD_LINE3, "RL78G14 RDK V2.0"); DisplayLCD(LCD_LINE4, " Wi-Fi & Cloud "); DisplayLCD(LCD_LINE5, " demos by: "); DisplayLCD(LCD_LINE6, "Gainspan "); DisplayLCD(LCD_LINE7, "Exosite "); DisplayLCD(LCD_LINE8, "Future Designs, Inc"); MSTimerDelay(3500); ClearLCD(); DisplayLCD(LCD_LINE1, "Demo Modes: "); DisplayLCD(LCD_LINE2, "-RST no key: "); DisplayLCD(LCD_LINE3, " GS Web Server "); DisplayLCD(LCD_LINE4, "-RST + SW1: "); DisplayLCD(LCD_LINE5, " Exosite Cloud "); DisplayLCD(LCD_LINE6, "-RST + SW2: "); DisplayLCD(LCD_LINE7, " AP Provisioning "); DisplayLCD(LCD_LINE8, "-RST + SW3: OTA "); MSTimerDelay(3000); ClearLCD(); LCDSelectFont(FONT_LARGE); if(Exosite_GetCIK(NULL)) { AppMode = RUN_EXOSITE; } } DisplayLCD(LCD_LINE1, "Starting..."); /*****************************************************************************/ SPI_Init(GAINSPAN_SPI_RATE); /* Setup LCD SPI channel for Chip Select P10, active low, active per byte */ SPI_ChannelSetup(GAINSPAN_SPI_CHANNEL, false, true); GainSpan_SPI_Start(); PM15 &= ~(1 << 2); P15 &= ~(1 << 2); if(AppMode == PROGRAM_MODE) { App_ProgramMode(); } else if (AppMode == RUN_EXOSITE) { DisplayLCD(LCD_LINE1, " CLOUD DEMO "); Temperature_Init(); Potentiometer_Init(); App_Exosite(); } else if(AppMode == RUN_PROVISIONING) { App_WebProvisioning(); } else if(AppMode == RUN_OVER_AIR_DOWNLOAD) { App_OverTheAirProgrammingPushMetheod(); } else if (AppMode == EXOSITE_ERASE) { ClearLCD(); LCDSelectFont(FONT_SMALL); DisplayLCD(LCD_LINE3, "EEPROM ERASING ... "); MSTimerDelay(2000); Exosite_Init("renesas", "rl78g14", IF_WIFI, 1); DisplayLCD(LCD_LINE3, " "); DisplayLCD(LCD_LINE4, "Please reset device"); while(1); } else{ UART0_Start(GAINSPAN_CONSOLE_BAUD); // UART2_Start(GAINSPAN_UART_BAUD); Temperature_Init(); Potentiometer_Init(); // sprintf(LCDString, "RDK Demo %s", VERSION_TEXT); // DisplayLCD(LCD_LINE1, (const uint8_t *)LCDString); /* Before doing any tests or apps, startup the module */ /* and nonvolatile stettings */ App_Startup(); // Now connect to the system //App_Connect(&G_nvsettings.webprov); // App_PassThroughSPI(); /******************Start Processing Sensor data******************/ uint32_t start = MSTimerGet(); uint8_t c; Accelerometer_Init(); while(1) { // if (GainSpan_SPI_ReceiveByte(GAINSPAN_SPI_CHANNEL, &c)) if(App_Read(&c, 1, 0)) AtLibGs_ReceiveDataProcess(c); /* Timeout? */ if (MSTimerDelta(start) >= 100) // every 100 ms, read sensor data { led_task(); switch(state) { case UPDATE_TEMPERATURE: // Temperature sensor reading temp = Temperature_Get(); #if 0 // Get the temperature and show it on the LCD temp_char[0] = (int16_t)temp / 16; temp_char[1] = (int16_t)((temp & 0x000F) * 10) / 16; #endif temp_char[1] = (temp & 0xFF00)>>8; temp_char[0] = temp & 0xFF; ftemp = *(uint16_t *)temp_char; gTemp_F = ((ftemp/5)*9)/128 + 22; // Display the contents of lcd_buffer onto the debug LCD //sprintf((char *)LCDString, "TEMP: %d.%d C", temp_char[0], temp_char[1]); sprintf((char *)LCDString, "TEMP: %.1fF", gTemp_F); DisplayLCD(LCD_LINE6, (const uint8_t *)LCDString); state = UPDATE_LIGHT; break; case UPDATE_LIGHT: // Light sensor reading gAmbientLight = LightSensor_Get(); // Display the contents of lcd_buffer onto the debug LCD sprintf((char *)LCDString, "Light: %d ", gAmbientLight); DisplayLCD(LCD_LINE7, (const uint8_t *)LCDString); state = UPDATE_ACCELEROMETER; break; case UPDATE_ACCELEROMETER: // 3-axis accelerometer reading Accelerometer_Get(); sprintf((char *)LCDString, "x%2d y%2d z%2d", gAccData[0], gAccData[1], gAccData[2]); DisplayLCD(LCD_LINE8, (const uint8_t *)LCDString); state = UPDATE_TEMPERATURE; break; } start = MSTimerGet(); } } }
/***************** The uNabto application logic ***************** * This is where the user implements his/her own functionality * to the device. When a Nabto message is received, this function * gets called with the message's request id and parameters. * Afterwards a user defined message can be sent back to the * requesting browser. ****************************************************************/ application_event_result application_event(application_request* request, buffer_read_t* read_buffer, buffer_write_t* write_buffer) { switch(request->queryId) { case 1: { /** Get acceleration data */ extern int16_t gAccData[3]; uint16_t acc_x; uint16_t acc_y; uint16_t acc_z; // Get accelerometer data and calculate yaw, pitch and roll with offset Accelerometer_Get(); acc_x = gAccData[0] + 0xFF; acc_y = gAccData[1] + 0xFF; acc_z = gAccData[2] + 0xFF; // Write back data if (!buffer_write_uint16(write_buffer, acc_x)) return AER_REQ_RSP_TOO_LARGE; if (!buffer_write_uint16(write_buffer, acc_y)) return AER_REQ_RSP_TOO_LARGE; if (!buffer_write_uint16(write_buffer, acc_z)) return AER_REQ_RSP_TOO_LARGE; return AER_REQ_RESPONSE_READY; } case 2: { /** Get temperature data */ uint16_t temp; temp = Temperature_Get(); // Write back data if (!buffer_write_uint16(write_buffer, temp)) return AER_REQ_RSP_TOO_LARGE; return AER_REQ_RESPONSE_READY; } case 3: { /** Get light level */ uint16_t light; light = LightSensor_Get(); // Write back data if (!buffer_write_uint16(write_buffer, light)) return AER_REQ_RSP_TOO_LARGE; return AER_REQ_RESPONSE_READY; } case 4: { /** Get potentiometer data */ uint32_t pot; pot = Potentiometer_Get(); // Write back data if (!buffer_write_uint32(write_buffer, pot)) return AER_REQ_RSP_TOO_LARGE; return AER_REQ_RESPONSE_READY; } case 5: { /** Get button status */ uint8_t button1; uint8_t button2; uint8_t button3; button1 = Switch1IsPressed(); button2 = Switch2IsPressed(); button3 = Switch3IsPressed(); // Write back data if (!buffer_write_uint8(write_buffer, button1)) return AER_REQ_RSP_TOO_LARGE; if (!buffer_write_uint8(write_buffer, button2)) return AER_REQ_RSP_TOO_LARGE; if (!buffer_write_uint8(write_buffer, button3)) return AER_REQ_RSP_TOO_LARGE; return AER_REQ_RESPONSE_READY; } case 6: { /** Get sound level */ uint32_t sound; sound = Microphone_Get(); // Write back data if (!buffer_write_uint32(write_buffer, sound)) return AER_REQ_RSP_TOO_LARGE; return AER_REQ_RESPONSE_READY; } case 7: { /** Set LED */ uint16_t led; // Read parameters in request if (!buffer_read_uint16(read_buffer, &led)) return AER_REQ_TOO_SMALL; if (led == 1) { led_all_on(); } else { led_all_off(); } // Write back data if (!buffer_write_uint16(write_buffer, led)) return AER_REQ_RSP_TOO_LARGE; return AER_REQ_RESPONSE_READY; } } return AER_REQ_INV_QUERY_ID; }
int main(void) { AppMode_T AppMode; WDTIMK = 0U; /* enable INTWDTI interrupt */ HardwareSetup(); MSTimerInit(); /************************initializa LCD module********************************/ SPI2_Init(); InitialiseLCD(); led_init(); /* Default app mode */ AppMode = RUN_EXOSITE; /* Determine if SW1 & SW3 is pressed at power up to enter nvm erase mode */ if (Switch1IsPressed() && Switch3IsPressed()) { DisplayLCD(LCD_LINE1, "*NVM ERASED*"); DisplayLCD(LCD_LINE2, "Reboot "); DisplayLCD(LCD_LINE3, " Device "); while(1) { // wait here } } else if(Switch1IsPressed()) { AppMode = ACTIVATE_MODEM; } DisplayLCD(LCD_LINE1, "Initializing"); DisplayLCD(LCD_LINE2, " Novatel "); DisplayLCD(LCD_LINE3, " Modem "); // reset the modem P8 &= ~(1<<POWER_OFF_PIN); //SET LOW PM8 &= ~(1<<POWER_OFF_PIN); //SET AS OUTPUT P8 |= (1<<POWER_OFF_PIN); //SET HIGH MSTimerDelay(500); //pulse P8 &= ~(1<<POWER_OFF_PIN); //SET LOW // pulse the phone pin as well ADPC = 0x09U; //DEFAULT is all AINx pins are Analog, change 8-15 // to digital P15 &= ~(1<<MODEM_PHON_PIN); //SET LOW PM15 &= ~(1<<MODEM_PHON_PIN); //SET AS OUTPUT P15 |= (1<<MODEM_PHON_PIN); //SET HIGH MSTimerDelay(500); //pulse P15 &= ~(1<<MODEM_PHON_PIN); //SET LOW PM15 |= (1<<MODEM_PHON_PIN); //SET AS INPUT // wait for modem to power up DisplayLCD(LCD_LINE1, "Waiting for "); DisplayLCD(LCD_LINE2, " Modem to "); DisplayLCD(LCD_LINE3, " Initialize "); DisplayLCD(LCD_LINE4, " 3 "); MSTimerDelay(1000); DisplayLCD(LCD_LINE4, " 2 "); MSTimerDelay(1000); DisplayLCD(LCD_LINE4, " 1 "); MSTimerDelay(1000); DisplayLCD(LCD_LINE4, ""); // Start UART0 for Novatel modem UART0_Start(NOVATEL_UART_BAUD_RATE); /* If the CIK is exist, auto into the Exosite mode */ NVSettingsLoad(&GNV_Setting); if(AppMode == RUN_EXOSITE) { LCDDisplayLogo(); LCDSelectFont(FONT_SMALL); DisplayLCD(LCD_LINE3, "RL78G14 RDK V2.0"); DisplayLCD(LCD_LINE4, " Cellular "); DisplayLCD(LCD_LINE5, " demos by: "); DisplayLCD(LCD_LINE6, "Novatel "); DisplayLCD(LCD_LINE7, "Exosite "); MSTimerDelay(3500); ClearLCD(); DisplayLCD(LCD_LINE1, "Demo Modes: "); DisplayLCD(LCD_LINE2, "-RST no key: "); DisplayLCD(LCD_LINE3, " ExoSite App "); DisplayLCD(LCD_LINE4, "-RST + SW1 & SW3: "); DisplayLCD(LCD_LINE5, " Reset NVM "); DisplayLCD(LCD_LINE6, "-RST + SW1: "); DisplayLCD(LCD_LINE7, " Cell Activate "); MSTimerDelay(3000); ClearLCD(); LCDSelectFont(FONT_LARGE); DisplayLCD(LCD_LINE1, "Exosite DEMO"); Temperature_Init(); Potentiometer_Init(); App_Exosite(); } else if (AppMode == ACTIVATE_MODEM) { ATModem_CellActivate(); } return 0; }