int UEZGUICmdTouchscreenClear(void *aWorkspace, int argc, char *argv[]) { G_nonvolatileSettings.iNeedRecalibrate = ETrue; NVSettingsSave(); FDICmdSendString(aWorkspace, "PASS: OK\n"); return 0; }
/*---------------------------------------------------------------------------* * Task: main *---------------------------------------------------------------------------* * Description: * In the uEZ system, main() is a task. Do not exit this task * unless you want to the board to reset. This function should * setup the system and then run the main loop of the program. * Outputs: * int -- Output error code *---------------------------------------------------------------------------*/ int MainTask(void) { #if COMPILE_OPTION_USB_SDCARD_DISK T_USBMSDriveCallbacks usbMSDiskCallbacks = { 0 }; #endif //printf("\f" PROJECT_NAME " " VERSION_AS_TEXT "\n\n"); // clear serial screen and put up banner // Load the settings from non-volatile memory if (NVSettingsLoad() != UEZ_ERROR_NONE) { //printf("EEPROM Settings\n"); NVSettingsInit(); NVSettingsSave(); } #if COMPILE_OPTION_USB_SDCARD_DISK // Setup the USB MassStorage device to connect to MS1 (the SD Card) USBMSDriveInitialize( &usbMSDiskCallbacks, 0, "MS1"); #endif // Setup any additional misc. tasks (such as the heartbeat task) SetupTasks(); AudioStart(); // Pass control to the main menu MainMenu(); // We should not exit main unless we want to reset the board return 0; }
int UEZGUICmdIPMaskAddress(void *aWorkspace, int argc, char *argv[]) { char ip[4]; int ipLen; char *p; char c; char num[10]; int numLen; if (argc == 1) { FDICmdPrintf(aWorkspace, "PASS: %d.%d.%d.%d\n", G_nonvolatileSettings.iIPMask[0], G_nonvolatileSettings.iIPMask[1], G_nonvolatileSettings.iIPMask[2], G_nonvolatileSettings.iIPMask[3]); } else if (argc == 2) { p = argv[1]; ipLen = 0; ip[0] = '\0'; numLen = 0; while (1) { c = *p; if ((c == '.') || (c == '\0')) { if (ipLen == 4) { FDICmdSendString(aWorkspace, "FAIL: IP Mask address too long!\n"); return 0; } ip[ipLen++] = FDICmdUValue(num); numLen = 0; } else { num[numLen++] = c; num[numLen] = '\0'; } if (*p == '\0') break; p++; } if (ipLen != 4) { FDICmdSendString(aWorkspace, "FAIL: IP Mask address too short!\n"); return 0; } memcpy(&G_nonvolatileSettings.iIPMask, ip, 4); if (NVSettingsSave()) { FDICmdSendString(aWorkspace, "FAIL: IP Mask address failed to save correctly\n"); } else { FDICmdPrintf(aWorkspace, "PASS: %d.%d.%d.%d\n", G_nonvolatileSettings.iIPMask[0], G_nonvolatileSettings.iIPMask[1], G_nonvolatileSettings.iIPMask[2], G_nonvolatileSettings.iIPMask[3]); } } else { FDICmdSendString(aWorkspace, "FAIL: Incorrect parameters\n"); } return 0; }
/*---------------------------------------------------------------------------* * Task: main *---------------------------------------------------------------------------* * Description: * In the uEZ system, main() is a task. Do not exit this task * unless you want to the board to reset. This function should * setup the system and then run the main loop of the program. * Outputs: * int -- Output error code *---------------------------------------------------------------------------*/ int MainTask(void) { #if COMPILE_OPTION_USB_SDCARD_DISK T_USBMSDriveCallbacks usbMSDiskCallbacks = { 0 }; #endif printf("\f" PROJECT_NAME " " VERSION_AS_TEXT "\n\n"); // clear serial screen and put up banner // Load the settings from non-volatile memory if (NVSettingsLoad() != UEZ_ERROR_NONE) { printf("EEPROM Settings\n"); NVSettingsInit(); NVSettingsSave(); } #if COMPILE_OPTION_USB_SDCARD_DISK // Setup the USB MassStorage device to connect to MS1 (the SD Card) USBMSDriveInitialize( &usbMSDiskCallbacks, 0, "MS1"); #endif // Setup any additional misc. tasks (such as the heartbeat task) SetupTasks(); AudioStart(); // initialize command console for test commands //UEZGUITestCmdsInit(); #include "UEZGainSpan.h" // Gainspan here: char rxBuf[128]; void *G_UEZGUIWorkspace; G_UEZGUIWorkspace = 0; char* argv[2]; argv[0]= "gainspan"; argv[1] = "program"; // argv[1] = "check"; UEZGUIGainSpan(G_UEZGUIWorkspace, 2, (char **)argv, (char *)&rxBuf); // Pass control to the main menu MainMenu(); // We should not exit main unless we want to reset the board return 0; }
/*---------------------------------------------------------------------------* * 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(); }
/*---------------------------------------------------------------------------* * Task: main *---------------------------------------------------------------------------* * Description: * In the uEZ system, main() is a task. Do not exit this task * unless you want to the board to reset. This function should * setup the system and then run the main loop of the program. * Outputs: * int -- Output error code *---------------------------------------------------------------------------*/ void MainTask(void) { #if COMPILE_OPTION_USB_SDCARD_DISK T_USBMSDriveCallbacks usbMSDiskCallbacks = {0}; #endif printf("\f" PROJECT_NAME " " VERSION_AS_TEXT "\n\n"); // clear serial screen and put up banner // Load the settings from non-volatile memory if (NVSettingsLoad() != UEZ_ERROR_NONE) { printf("EEPROM Settings\n"); NVSettingsInit(); NVSettingsSave(); } // Start up the heart beat of the LED UEZTaskCreate(Heartbeat, "Heart", 64, (void *)0, UEZ_PRIORITY_NORMAL, 0); #if UEZ_ENABLE_USB_DEVICE_STACK if (G_usbIsDevice) { // Setup the USB MassStorage device to connect to MS1 (the SD Card) USBMSDriveInitialize( &usbMSDiskCallbacks, 0, "MS1"); } #endif AudioStart(); // Force calibration? Calibrate(CalibrateTestIfTouchscreenHeld()); if(!GUIManager_Start_emWin_PF()){ GUIManager_Create_All_Active_Windows_PF(); //start the main window. if(G_SystemWindows_PF[HOME_SCREEN]){ GUIManager_Show_Window_PF(HOME_SCREEN); GUI_ExecCreatedDialog(G_SystemWindows_PF[HOME_SCREEN]); } else { UEZFailureMsg("Failed to create windows!"); } } else { UEZFailureMsg("emWin Failed to Start!"); } // We should not exit main unless we want to reset the board }
/*---------------------------------------------------------------------------* * Task: main *---------------------------------------------------------------------------* * Description: * In the uEZ system, main() is a task. Do not exit this task * unless you want to the board to reset. This function should * setup the system and then run the main loop of the program. * Outputs: * int -- Output error code *---------------------------------------------------------------------------*/ int MainTask(void) { #if COMPILE_OPTION_USB_SDCARD_DISK T_USBMSDriveCallbacks usbMSDiskCallbacks = {0}; #endif printf("\f" PROJECT_NAME " " VERSION_AS_TEXT "\n\n"); // clear serial screen and put up banner // Load the settings from non-volatile memory if (NVSettingsLoad() != UEZ_ERROR_NONE) { printf("EEPROM Settings\n"); NVSettingsInit(); NVSettingsSave(); } #if UEZ_ENABLE_USB_DEVICE_STACK if (G_usbIsDevice) { // Setup the USB MassStorage device to connect to MS1 (the SD Card) USBMSDriveInitialize( &usbMSDiskCallbacks, 0, "MS1"); } #endif // Setup any additional misc. tasks (such as the heartbeat task) SetupTasks(); AudioStart(); #if UEZGUI_EXP_DK_FCT_TEST // no command console so functional test can run #else // initialize command console for test commands UEZGUITestCmdsInit(); #endif // Pass control to the main menu MainMenu(); // We should not exit main unless we want to reset the board return 0; }
/*---------------------------------------------------------------------------*/ int MainTask(void) { // Output a start up banner printf("\f" PROJECT_NAME " " VERSION_AS_TEXT "\n\n"); // Start up the heart beat of the LED UEZTaskCreate(Heartbeat, "Heart", 64, (void *)0, UEZ_PRIORITY_NORMAL, 0); // Load any non-volatile settings from the data flash. NVSettingsInit(); // Load the settings from non-volatile memory if (NVSettingsLoad() == UEZ_ERROR_CHECKSUM_BAD) { printf("EEPROM Settings\n"); NVSettingsInit(); NVSettingsSave(); } // Setup the glyph API to the LCD and draw the title screen. GlyphOpen(&G_glyphLCD, 0); IDrawTitle(); // Setup any additional misc. tasks (such as the heartbeat task) SetupTasks(); // Play startup tones PlayAudio(523, 100); PlayAudio(659, 100); PlayAudio(783, 100); PlayAudio(1046, 100); PlayAudio(783, 100); PlayAudio(659, 100); PlayAudio(523, 100); // Wait in an infinite loop. while(1) { UEZTaskDelay(10000); } return 0; }
/*---------------------------------------------------------------------------* * Task: main *---------------------------------------------------------------------------* * Description: * In the uEZ system, main() is a task. Do not exit this task * unless you want to the board to reset. This function should * setup the system and then run the main loop of the program. * Outputs: * int -- Output error code *---------------------------------------------------------------------------*/ int MainTask(void) { printf("\f" PROJECT_NAME " " VERSION_AS_TEXT "\n\n"); // clear serial screen and put up banner // Start up the heart beat of the LED UEZTaskCreate(Heartbeat, "Heart", 64, (void *)0, UEZ_PRIORITY_NORMAL, 0); NVSettingsInit(); // Load the settings from non-volatile memory if (NVSettingsLoad() == UEZ_ERROR_CHECKSUM_BAD) { printf("EEPROM Settings\n"); NVSettingsInit(); NVSettingsSave(); } // Delete old log file UEZFileDelete("0:/ACCELLOG.TXT"); // Setup any additional misc. tasks (such as the heartbeat task) SetupTasks(); GlyphOpen(&G_glyphLCD, 0); IDrawTitle(); // Play tones PlayAudio(523, 100); PlayAudio(659, 100); PlayAudio(783, 100); PlayAudio(1046, 100); PlayAudio(783, 100); PlayAudio(659, 100); PlayAudio(523, 100); while(1) { UEZTaskDelay(500); } return 0; }
/*---------------------------------------------------------------------------* * Routine: TestModeTouchscreenProcedure *---------------------------------------------------------------------------* * Description: * Step the user through the calibration process. A target is shown * at each of 3 locations and waits for the user to touch the * target. * Inputs: * TUInt16 *aPixels -- Pointer to pixel memory * TUInt16 aX, aY -- Coordinate of target to draw *---------------------------------------------------------------------------*/ void TestModeTouchscreenProcedure( T_pixelColor *aPixels, T_uezDevice ts) { static const T_uezTSReading G_coord[5] = { { 0, 0+TP_INSET, TP_INSET, 1 }, // 0 { 0, DISPLAY_WIDTH-TP_INSET, TP_INSET, 1 }, // 1 { 0, 0+TP_INSET, DISPLAY_HEIGHT-TP_INSET, 1 }, // 2 { 0, DISPLAY_WIDTH-TP_INSET, DISPLAY_HEIGHT-TP_INSET, 1 }, // 3 { 0, DISPLAY_WIDTH/2, DISPLAY_HEIGHT/2, 1 }, // 4 }; // List of expected results (based on a single screen) #if ((UEZ_DEFAULT_LCD_CONFIG==LCD_CONFIG_SHARP_LQ043T3DG01) || (UEZ_DEFAULT_LCD_CONFIG==LCD_CONFIG_SHARP_LQ043T1DG28)) static const T_uezTSReading G_expectedReadings[5] = { { 0, 0x13f6, 0x58ec, 1 }, // 0 { 0, 0x6aa3, 0x58f0, 1 }, // 1 { 0, 0x12d8, 0x22cd, 1 }, // 2 { 0, 0x6616, 0x1f62, 1 }, // 3 { 0, 0x3f47, 0x3de0, 1 }, // 4 }; #elif (UEZ_DEFAULT_LCD_CONFIG==LCD_CONFIG_INTELTRONIC_LMIX0560NTN53V1) static const T_uezTSReading G_expectedReadings[5] = { { 0, 0x6D64, 0x62F8, 1 }, // 0 { 0, 0x0F3A, 0x63D7, 1 }, // 1 { 0, 0x6BFD, 0x1B4B, 1 }, // 2 { 0, 0x0F6D, 0x1880, 1 }, // 3 { 0, 0x3CC8, 0x3C98, 1 }, // 4 }; #elif ((UEZ_DEFAULT_LCD_CONFIG==LCD_CONFIG_SEIKO_70WVW2T)) static const T_uezTSReading G_expectedReadings[5] = { { 0, 0x6F1C, 0x620D, 1 }, // 0 { 0, 0x118B, 0x628A, 1 }, // 1 { 0, 0x6F01, 0x1BF4, 1 }, // 2 { 0, 0x11D7, 0x1BFB, 1 }, // 3 { 0, 0x4036, 0x3F62, 1 }, // 4 }; #elif (UEZ_DEFAULT_LCD_CONFIG==LCD_CONFIG_TIANMA_TM070RBHG04) static const T_uezTSReading G_expectedReadings[5] = { { 0, 0x0C04, 0x204C, 1 }, // 0 { 0, 0x6F2A, 0x2134, 1 }, // 1 { 0, 0x0C58, 0x6012, 1 }, // 2 { 0, 0x6F2C, 0x5DBA, 1 }, // 3 { 0, 0x3C6A, 0x4098, 1 }, // 4 }; #elif (UEZ_DEFAULT_LCD_CONFIG == LCD_CONFIG_MICROTIPS_UMSH_8596MD_20T) //TODO : update numbers static const T_uezTSReading G_expectedReadings[5] = { { 0, 0x0C04, 0x204C, 1 }, // 0 { 0, 0x6F2A, 0x2134, 1 }, // 1 { 0, 0x0C58, 0x6012, 1 }, // 2 { 0, 0x6F2C, 0x5DBA, 1 }, // 3 { 0, 0x3C6A, 0x4098, 1 }, // 4 }; #endif // The raw X range is 0x560A (left) to 0x2908 (right) // 100% = 0x2D02 // 20% = 0x0900 // 10% = 0x0480 // The raw Y range is 0x5A7A (top) to 0x24A1 (bottom) // 100% = 0x35D9 // 20% = 0x0AC5 // 10% = 0x0562 #define READING_X_TOLERANCE 0x0900 #define READING_Y_TOLERANCE 0x0AC5 T_uezTSReading readings[5]; T_uezTSReading reading; T_uezTSReading sum; TUInt32 count; int i; T_uezError error; TBool sawNoTouch; TUInt32 timeoutCount=0; TUInt32 timeoutStart; G_mmTestModeTouchscreenCalibrationValid = EFalse; while (1) { // Put the touch screen into calibration mode UEZTSCalibrationStart(ts); // Clear the screen //CalibrateScreen(); // Show 5 different targets timeoutStart = UEZTickCounterGet(); for (i=0; i<5; i++) { // Make sure we see the screen is not being touched // when we start. This ensures if the unit is being held at power // up that we don't go into calibration and get a bogus // starting reading. sawNoTouch = EFalse; // Show target to touch IDrawTarget(aPixels, G_coord[i].iX, G_coord[i].iY); // Wait for the pen to touch (while not in test mode) for (;;) { sum.iX = 0; sum.iY = 0; for (count=0; count<4; ) { if (UEZTSGetReading(ts, &reading)==UEZ_ERROR_NONE) { if (reading.iFlags & TSFLAG_PEN_DOWN) { // Only accept reading if we originally // were not touching the screen. if (sawNoTouch) { sum.iX += reading.iX; sum.iY += reading.iY; count++; timeoutStart = UEZTickCounterGet(); timeoutCount = 0; } } else { sawNoTouch = ETrue; // Reset the timeout timeoutStart = UEZTickCounterGet(); timeoutCount = 0; } } if (!sawNoTouch) { timeoutCount = UEZTickCounterGet() - timeoutStart; if (timeoutCount > 10000) break; } UEZTaskDelay(50); } reading.iX = sum.iX/count; reading.iY = sum.iY/count; // Remember this reading readings[i] = reading; if (i < 3) { // If one of the first 3 points, store the data UEZTSCalibrationAddReading(ts, &reading, &G_coord[i]); G_nonvolatileSettings.iReadings[i] = reading; G_nonvolatileSettings.iNum = i+1; } ButtonClick(); break; } // Erase target to signal the user touched the target IEraseTarget(aPixels, G_coord[i].iX, G_coord[i].iY); if (timeoutCount < 10000) { // Wait for the pen to lift timeoutCount = 0; for (;;) { if (UEZTSGetReading(ts, &reading)==UEZ_ERROR_NONE) { if (!(reading.iFlags & TSFLAG_PEN_DOWN)) { break; } } UEZTaskDelay(50); timeoutCount += 50; if (timeoutCount >= 10000) break; } } } // Calibration is complete. Put the new calibration into effect. error = UEZTSCalibrationEnd(ts); if (timeoutCount >= 10000) error = UEZ_ERROR_TIMEOUT; // Determine if this is valid or not if (error) { G_mmTestModeTouchscreenCalibrationValid = EFalse; } else { // Check the validity of the readings G_mmTestModeTouchscreenCalibrationValid = ETrue; for (i=0; i<5; i++) { if ((readings[i].iX < G_expectedReadings[i].iX-READING_X_TOLERANCE) || (readings[i].iX > G_expectedReadings[i].iX+READING_X_TOLERANCE)) { // Outside along X G_mmTestModeTouchscreenCalibrationValid = EFalse; break; } if ((readings[i].iY < G_expectedReadings[i].iY-READING_Y_TOLERANCE) || (readings[i].iY > G_expectedReadings[i].iY+READING_Y_TOLERANCE)) { // Outside along Y G_mmTestModeTouchscreenCalibrationValid = EFalse; break; } } } NVSettingsSave(); break; } }
/*---------------------------------------------------------------------------* * Task: main *---------------------------------------------------------------------------* * Description: * In the uEZ system, main() is a task. Do not exit this task * unless you want to the board to reset. This function should * setup the system and then run the main loop of the program. * Outputs: * int -- Output error code *---------------------------------------------------------------------------*/ int MainTask(void) { T_uezDevice temp; T_uezDevice accel; T_uezError tempDeviceError; T_uezError accelDeviceError; TUInt8 displayString[100]; TInt32 tempValue; float tempFloatValue; AccelerometerReading accelReading; printf("\f" PROJECT_NAME " " VERSION_AS_TEXT "\n\n"); // clear serial screen and put up banner // Start up the heart beat of the LED UEZTaskCreate(Heartbeat, "Heart", 64, (void *)0, UEZ_PRIORITY_NORMAL, 0); NVSettingsInit(); // Load the settings from non-volatile memory if (NVSettingsLoad() == UEZ_ERROR_CHECKSUM_BAD) { printf("EEPROM Settings\n"); NVSettingsInit(); NVSettingsSave(); } // Setup any additional misc. tasks (such as the heartbeat task) SetupTasks(); GlyphOpen(&G_glyphLCD, 0); IDrawTitle(); PlayAudio(523, 100); PlayAudio(659, 100); PlayAudio(783, 100); PlayAudio(1046, 100); PlayAudio(783, 100); PlayAudio(659, 100); PlayAudio(523, 100); tempDeviceError = UEZTemperatureOpen("Temp0", &temp); if (tempDeviceError == UEZ_ERROR_NONE) { printf("MainTask: Temperature Device Open\n"); } else { printf("MainTask: Failed to Open Temperature Device\n"); } accelDeviceError = UEZAccelerometerOpen("Accel0", &accel); if (accelDeviceError == UEZ_ERROR_NONE) { printf("MainTask: Accelerometer Device Open\n"); } else { printf("MainTask: Failed to Open Accelerometer Device\n"); } while(1) { if ( tempDeviceError == UEZ_ERROR_NONE ) { if (UEZTemperatureRead(temp, &tempValue) == UEZ_ERROR_NONE) { tempFloatValue = tempValue/65536.0; sprintf((char *)displayString, "Temp: %.2f C", tempFloatValue); GlyphSetXY(G_glyphLCD, 0, 0); GlyphString(G_glyphLCD, displayString, strlen(displayString)); } } if ( accelDeviceError == UEZ_ERROR_NONE ) { if(UEZAccelerometerReadXYZ(accel, &accelReading, 10) == UEZ_ERROR_NONE ) { sprintf((char *)displayString, "ACCEL X: %d", accelReading.iX); GlyphSetXY(G_glyphLCD, 0, 16); GlyphString(G_glyphLCD, displayString, strlen(displayString)); sprintf((char *)displayString, "ACCEL Y: %d", accelReading.iY); GlyphSetXY(G_glyphLCD, 0, 24); GlyphString(G_glyphLCD, displayString, strlen(displayString)); sprintf((char *)displayString, "ACCEL Z: %d", accelReading.iZ); GlyphSetXY(G_glyphLCD, 0, 32); GlyphString(G_glyphLCD, displayString, strlen(displayString)); } } UEZTaskDelay(500); } return 0; }
/*---------------------------------------------------------------------------* * Task: main *---------------------------------------------------------------------------* * Description: * In the uEZ system, main() is a task. Do not exit this task * unless you want to the board to reset. This function should * setup the system and then run the main loop of the program. * Outputs: * int -- Output error code *---------------------------------------------------------------------------*/ int MainTask(void) { T_uezDevice adc; T_uezDevice temp; T_uezDevice accel; T_uezError adcDeviceError; T_uezError tempDeviceError; T_uezError accelDeviceError; ADC_RequestSingle adcRequest; TUInt32 adcReading; TUInt8 displayString[100]; TInt32 tempValue; float tempFloatValue; AccelerometerReading accelReading; printf("\f" PROJECT_NAME " " VERSION_AS_TEXT "\n\n"); NVSettingsInit(); // Load the settings from non-volatile memory if (NVSettingsLoad() == UEZ_ERROR_CHECKSUM_BAD) { printf("EEPROM Settings\n"); NVSettingsInit(); NVSettingsSave(); } SetupTasks(); GlyphOpen(&G_glyphLCD, 0); IDrawTitle(); PlayAudio(523, 100); PlayAudio(659, 100); PlayAudio(783, 100); PlayAudio(1046, 100); PlayAudio(783, 100); PlayAudio(659, 100); PlayAudio(523, 100); adcDeviceError = UEZADCOpen("ADC_S12AD", &adc); if (adcDeviceError == UEZ_ERROR_NONE) { printf("MainTask: ADC Device Open\n"); } else { printf("MainTask: Failed to Open ADC Device\n"); } tempDeviceError = UEZTemperatureOpen("Temp0", &temp); if (tempDeviceError == UEZ_ERROR_NONE) { printf("MainTask: Temperature Device Open\n"); } else { printf("MainTask: Failed to Open Temperature Device\n"); } accelDeviceError = UEZAccelerometerOpen("Accel0", &accel); if (accelDeviceError == UEZ_ERROR_NONE) { printf("MainTask: Accelerometer Device Open\n"); } else { printf("MainTask: Failed to Open Accelerometer Device\n"); } //PORTE.PDR.BIT.B3 = 1; while(1) { if( adcDeviceError == UEZ_ERROR_NONE ) { // the device opened properly adcRequest.iADCChannel = 2; adcRequest.iBitSampleSize = 12; adcRequest.iTrigger = ADC_TRIGGER_NOW; adcRequest.iCapturedData = &adcReading; if (UEZADCRequestSingle(adc,&adcRequest) == UEZ_ERROR_NONE) { printf("MainTask: Potentiometer Reading: %d\n", adcReading); } else { printf("MainTask: Failed to get a Potentiometer Reading\n"); } } if ( tempDeviceError == UEZ_ERROR_NONE ) { if (UEZTemperatureRead(temp, &tempValue) == UEZ_ERROR_NONE) { tempFloatValue = tempValue/65536.0; sprintf((char *)displayString, "Temp: %.2f C", tempFloatValue); GlyphSetXY(G_glyphLCD, 0, 0); GlyphString(G_glyphLCD, displayString, strlen(displayString)); } } if ( accelDeviceError == UEZ_ERROR_NONE ) { if(UEZAccelerometerReadXYZ(accel, &accelReading, 10) == UEZ_ERROR_NONE ) { sprintf((char *)displayString, "ACCEL X: %d", accelReading.iX); GlyphSetXY(G_glyphLCD, 0, 16); GlyphString(G_glyphLCD, displayString, strlen(displayString)); sprintf((char *)displayString, "ACCEL Y: %d", accelReading.iY); GlyphSetXY(G_glyphLCD, 0, 24); GlyphString(G_glyphLCD, displayString, strlen(displayString)); sprintf((char *)displayString, "ACCEL Z: %d", accelReading.iZ); GlyphSetXY(G_glyphLCD, 0, 32); GlyphString(G_glyphLCD, displayString, strlen(displayString)); } } UEZTaskDelay(1000); } return 0; }
/*---------------------------------------------------------------------------*/ 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 UEZGUICmdMACAddress(void *aWorkspace, int argc, char *argv[]) { char mac[6]; int macLen; char *p; char c; char hex[] = "$??"; int hexLen; if (argc == 1) { FDICmdPrintf(aWorkspace, "PASS: %02X:%02X:%02X:%02X:%02X:%02X\n", G_nonvolatileSettings.iMACAddr[0], G_nonvolatileSettings.iMACAddr[1], G_nonvolatileSettings.iMACAddr[2], G_nonvolatileSettings.iMACAddr[3], G_nonvolatileSettings.iMACAddr[4], G_nonvolatileSettings.iMACAddr[5]); } else if (argc == 2) { p = argv[1]; if (strcmp(p, "default")==0) { mac[0] = emacMACADDR0; mac[1] = emacMACADDR1; mac[2] = emacMACADDR2; mac[3] = emacMACADDR3; mac[4] = emacMACADDR4; mac[5] = emacMACADDR5; } else { macLen = 0; mac[0] = '\0'; hexLen = 0; while (*p) { c = *p; if ((c != ':') && (c != '.')) { if (macLen == 6) { FDICmdSendString(aWorkspace, "FAIL: MAC address too long!\n"); return 0; } hex[1 + hexLen++] = c; if (hexLen == 2) { mac[macLen++] = FDICmdUValue(hex); hexLen = 0; } } p++; } if (macLen != 6) { FDICmdSendString(aWorkspace, "FAIL: MAC address too short!\n"); return 0; } } memcpy(&G_nonvolatileSettings.iMACAddr, mac, 6); if (NVSettingsSave()) { FDICmdSendString(aWorkspace, "FAIL: MAC address failed to save correctly\n"); } else { FDICmdPrintf(aWorkspace, "PASS: %02X:%02X:%02X:%02X:%02X:%02X\n", G_nonvolatileSettings.iMACAddr[0], G_nonvolatileSettings.iMACAddr[1], G_nonvolatileSettings.iMACAddr[2], G_nonvolatileSettings.iMACAddr[3], G_nonvolatileSettings.iMACAddr[4], G_nonvolatileSettings.iMACAddr[5]); } } else { FDICmdSendString(aWorkspace, "FAIL: Incorrect parameters\n"); } return 0; }
/*---------------------------------------------------------------------------* * Routine: App_WebProvisioning *---------------------------------------------------------------------------* * Description: * Put the unit into web provisioning mode and wait for the user to * connect with a web browser, change the settings, and click Save. * The settings will then be parsed by the AtLibGs library and * get saved into the nv settings. * Inputs: * void * Outputs: * void *---------------------------------------------------------------------------*/ void App_WebProvisioning(void) { ATLIBGS_MSG_ID_E r; /* At power up, load up the default settings */ if(NVSettingsLoad(&G_nvsettings)) NVSettingsSave(&G_nvsettings); App_InitModule(); while(1) { r = AtLibGs_GetMAC(WiFiMAC); if(r != ATLIBGS_MSG_ID_OK) { DisplayLCD(LCD_LINE6, "Get MAC Failed!"); MSTimerDelay(2000); continue; } break; }; if(r == ATLIBGS_MSG_ID_OK) AtLibGs_ParseGetMacResponse(WiFiMACStr); strcpy(str_config_ssid, (char const*)ATLIBGS_ADK_SSID); strcat(str_config_ssid, &WiFiMACStr[6]); // concatenate last 6 digis of MAC as SSID App_StartupLimitedAP(str_config_ssid); /* Before going into web provisioning, provide DNS to give a link. */ /* The user can then go to http://webprov.gainspan.com/gsclient.html to get */ /* access to the web provisioning screen. */ while (1) { #if 0 AtLibGs_DisableDNSServer(); r = AtLibGs_EnableDNSServer("webprov.gainspan.com"); if (r != ATLIBGS_MSG_ID_OK) { DisplayLCD(LCD_LINE6, "Bad DNS!"); MSTimerDelay(2000); continue; } #endif r = AtLibGs_WebProv(",", ","); if (r != ATLIBGS_MSG_ID_OK) { DisplayLCD(LCD_LINE6, "Bad WebProv!"); MSTimerDelay(2000); continue; } break; } DisplayLCD(LCD_LINE6, "WebProv ON"); DisplayLCD(LCD_LINE7, (const uint8_t *) "192.168.240."); DisplayLCD(LCD_LINE8, (const uint8_t *) "1/prov.html"); #if 0 do { DisplayLCD(LCD_LINE7, "IP: ???.???."); DisplayLCD(LCD_LINE8, " ???.???"); r = AtLibGs_GetNetworkStatus(&network_status); } while (ATLIBGS_MSG_ID_OK != r); sprintf(text, "IP: " _F8_ "." _F8_ ".", network_status.addr.ipv4[0], network_status.addr.ipv4[1]); DisplayLCD(LCD_LINE7, (uint8_t *)text); sprintf(text, " " _F8_ "." _F8_, network_status.addr.ipv4[2], network_status.addr.ipv4[3]); DisplayLCD(LCD_LINE8, (uint8_t *)text); #endif #ifdef ATLIBGS_DEBUG_ENABLE ConsolePrintf("Web Provisioning ON\n"); #endif /* Now wait for a list of responses until we get a blank line */ #ifdef ATLIBGS_DEBUG_ENABLE ConsolePrintf("Waiting for web provisioning response...\n"); #endif AtLibGs_GetWebProvSettings(&G_nvsettings.webprov, 0); /* Save the above settings */ NVSettingsSave(&G_nvsettings); #ifdef ATLIBGS_DEBUG_ENABLE ConsolePrintf("Web provisioning complete.\n"); #endif DisplayLCD(LCD_LINE6, "WebProv Done"); DisplayLCD(LCD_LINE7, ""); DisplayLCD(LCD_LINE8, "Press RESET"); while (1) {} }