void startupInit() { usbdataEnable(); gdispSetBacklight(50); gdispSetContrast(50); geventListenerInit(&gl); gwinAttachListener(&gl); // Setup UI objects and show splash guiCreate(); gwinProgressbarSetResolution(ghProgbarLoad, 10); gwinProgressbarStart(ghProgbarLoad, 300); graphInit(); // Setup INA219 I2C Current Sensor ina219Init(); sduObjectInit(USB_SERIAL_DRIVER); sduStart(USB_SERIAL_DRIVER, &serusbcfg); /* * Activates the USB driver and then the USB bus pull-up on D+. * Note, a delay is inserted in order to not have to disconnect the cable * after a reset. */ usbDisconnectBus(serusbcfg.usbp); chThdSleepMilliseconds(1000); usbStart(serusbcfg.usbp, &usbcfg); usbConnectBus(serusbcfg.usbp); setStartTime(); chThdCreateStatic(ledThread, sizeof(ledThread), LOWPRIO, ThreadLED, NULL); chThdCreateStatic(inaThread, sizeof(inaThread), HIGHPRIO, ThreadINA, NULL); chThdCreateStatic(gfxvalThread, sizeof(gfxvalThread), NORMALPRIO, ThreadGFXVal, NULL); chThdCreateStatic(timeThread, sizeof(timeThread), NORMALPRIO, ThreadTIME, NULL); chThdCreateStatic(gfxEventThread, sizeof(gfxEventThread), NORMALPRIO, ThreadGFXEvent, NULL); chThdSleepMilliseconds(2000); chThdCreateStatic(graphThread, sizeof(graphThread), NORMALPRIO+5, ThreadGRAPH, NULL); // Destroy splay screen and show main page gwinDestroy(ghContainerPageSplash); guiShowPage(1); }
/* * Application entry point. */ int main(void) { /* * System initializations. * - HAL initialization, this also initializes the configured device drivers * and performs the board-specific initializations. * - Kernel initialization, the main() function becomes a thread and the * RTOS is active. */ halInit(); chSysInit(); ADC2status = 0; //write_to_backup_sram(0, 0, 0); startBlinker(); /* initialize and clear the display */ gfxInit(); ginputGetMouse(0); //ginputSetMouseCalibrationRoutines(0, mysave, myload, FALSE); //ginputGetMouse(0); // new ugfx do not need this gwinAttachMouse(0); geventListenerInit(&gl); gwinAttachListener(&gl); //geventAttachSource(&gl, mouse, GLISTEN_MOUSEDOWNMOVES|GLISTEN_MOUSEMETA); //mouse = ginputGetMouse(0); //get screen size width = gdispGetWidth(); height = gdispGetHeight(); swidth = gdispGetWidth(); sheight = gdispGetHeight(); font = gdispOpenFont("UI2"); //startBlinker(); myADCinit(); ICUinit(); /* * Activates the serial driver 1 using the driver default configuration. * PA2(TX) and PA3(RX) are routed to USART2. */ sdStart(&SD2, NULL); palSetPadMode(GPIOA, 2, PAL_MODE_ALTERNATE(7)); palSetPadMode(GPIOA, 3, PAL_MODE_ALTERNATE(7)); chThdCreateStatic(waThread2, sizeof(waThread2), NORMALPRIO, Thread2, NULL); //mouse = ginputGetMouse(0); font = gdispOpenFont("UI2"); gwinSetDefaultFont(font); gwinSetDefaultBgColor(Black); gwinSetDefaultColor(White); bHeight = gdispGetFontMetric(font, fontHeight)+2; #if BOOTSCREEN bootScreen(); #endif #ifdef LOGO gdispClear(Black); CreateLogo(); #endif // create main screen createWidgets(); chprintf( (BaseSequentialStream *)&SD2, "Main loop\r\n", NULL ); while (TRUE) { //get an event pe = geventEventWait(&gl, TIME_INFINITE); switch(pe->type) { case GEVENT_TOUCH: { pem = (GEventMouse *)pe; if ((pem->type & GMETA_MOUSE_CLICK)) { //gwinSetColor(ghc, Yellow); chprintf((BaseSequentialStream *)&SD2, "\r\n-touch-click"); } } case GEVENT_GWIN_BUTTON: if (((GEventGWinButton*)pe)->button == ghConsole) { gwinSetText(ghStatus2, "Console", TRUE); chprintf( (BaseSequentialStream *)&SD2, "\r\nConsole button", NULL ); }; break; case GEVENT_GWIN_SLIDER: if (((GEventGWinSlider*)pe)->slider == ghBrightness) { gdispSetBacklight(((GEventGWinSlider *)pe)->position); chprintf((BaseSequentialStream *)&SD2,"Slider %s = %d\r\n", gwinGetText(((GEventGWinSlider *)pe)->slider), ((GEventGWinSlider *)pe)->position); } break; default: break ; } } }
static void createWidgets(void) { gwinSetDefaultFont(gdispOpenFont("UI2")); gwinSetDefaultStyle(&WhiteWidgetStyle, FALSE); gdispClear(White); bHeight = gdispGetFontMetric(font, fontHeight)+2; // apply default settings GWidgetInit wi; wi.customDraw = 0; wi.customParam = 0; wi.customStyle = 0; wi.g.show = TRUE; // create ICU1label wi.g.y = bHeight*2; wi.g.x = 0; wi.g.width = 160; wi.g.height = bHeight; wi.text = "ICU1:"; ICU1label = gwinLabelCreate(NULL, &wi); // ICU1vaule wi.g.y = bHeight*2; wi.g.x = 40; wi.g.width = 160; wi.g.height = bHeight; wi.text = "Status2"; ICU1value = gwinLabelCreate(NULL, &wi); // create ICU2label wi.g.y = bHeight*3; wi.g.x = 0; wi.g.width = 160; wi.g.height = bHeight; wi.text = "ICU2:"; ICU2label = gwinLabelCreate(NULL, &wi); // ICU2vaule wi.g.y = bHeight*3; wi.g.x = 40; wi.g.width = 160; wi.g.height = bHeight; wi.text = "000"; ICU2value = gwinLabelCreate(NULL, &wi); // create two status label //status 1 wi.g.y = sheight-bHeight; wi.g.x = 0; wi.g.width = 50; wi.g.height = bHeight; wi.text = "Status1"; ghStatus1 = gwinLabelCreate(NULL, &wi); // status 2 wi.g.y = sheight-bHeight; wi.g.x = 160; wi.g.width = 50; wi.g.height = bHeight; wi.text = "Status2"; ghStatus2 = gwinLabelCreate(NULL, &wi); // Brightness wi.g.y = sheight-(bHeight*2); wi.g.x = 0; wi.g.width = swidth; wi.g.height = bHeight; wi.text = "Brightness"; ghBrightness = gwinSliderCreate(NULL, &wi); gwinSliderSetRange(ghBrightness, 0, 100); gwinSliderSetPosition(ghBrightness, 50); gdispSetBacklight(50); // create ADC label // ADClabel1 wi.g.y = 0; wi.g.x = 0; wi.g.width = 50; wi.g.height = bHeight; wi.text = "ADC1:"; ADClabel = gwinLabelCreate(NULL, &wi); // ADClabel1 wi.g.y = 0; wi.g.x = 40; wi.g.width = 50; wi.g.height = bHeight; wi.text = "ADC value"; ADCvalue = gwinLabelCreate(NULL, &wi); // create ADC label // ADClabel1 wi.g.y = bHeight; wi.g.x = 0; wi.g.width = 70; wi.g.height = bHeight; wi.text = "Core temp:"; ADClabel2 = gwinLabelCreate(NULL, &wi); // ADClabel1 wi.g.y = bHeight; wi.g.x = 75; wi.g.width = 50; wi.g.height = bHeight; wi.text = "ADC value2"; ADCvalue2 = gwinLabelCreate(NULL, &wi); //create console button bWidth = gdispGetStringWidth("Console", font); wi.g.y = 10; //sheight-(bHeight*4); wi.g.x = swidth-70; wi.g.width = 50; wi.g.height = bHeight+4; wi.text = "Console"; ghConsole = gwinButtonCreate(NULL, &wi); //create console BMP button /* wi.g.x = swidth-85; wi.g.y = 40; wi.g.width = 84; wi.g.height = 23; ghbConsole = gwinImageCreate(NULL, &wi.g); gwinImageOpenMemory(ghbConsole, Console); gwinImageCache(ghbConsole); */ }