int main(void) { GEvent* pe; // Initialize the display gfxInit(); // Set the widget defaults gwinSetDefaultFont(gdispOpenFont("*")); gwinSetDefaultStyle(&WhiteWidgetStyle, FALSE); gdispClear(White); // create the widget createWidgets(); // We want to listen for widget events geventListenerInit(&gl); gwinAttachListener(&gl); while(1) { // Get an Event pe = geventEventWait(&gl, TIME_INFINITE); } return 0; }
int main(void) { GEvent* pe; // Initialize the display gfxInit(); // Attach the mouse input gwinAttachMouse(0); // Set the widget defaults gwinSetDefaultFont(gdispOpenFont("*")); gwinSetDefaultStyle(&WhiteWidgetStyle, FALSE); gdispClear(White); // create the widget _createWidgets(); // We want to listen for widget events geventListenerInit(&gl); gwinAttachListener(&gl); while(1) { // Get an Event pe = geventEventWait(&gl, TIME_INFINITE); switch(pe->type) { case GEVENT_GWIN_SLIDER: if (((GEventGWinSlider *)pe)->gwin == ghSliderR || \ ghSliderG || \ ghSliderB ) { _updateColor(); } break; case GEVENT_GWIN_BUTTON: if (((GEventGWinButton *)pe)->gwin == ghButton1) { gwinSliderSetPosition(ghSliderR, rand() % 256); } else if (((GEventGWinButton *)pe)->gwin == ghButton2) { gwinSliderSetPosition(ghSliderG, rand() % 256); } else if (((GEventGWinButton *)pe)->gwin == ghButton3) { gwinSliderSetPosition(ghSliderB, rand() % 256); } _updateColor(); default: break; } } return 0; }
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); }
int main(void) { GEvent* pe; // Initialize the display gfxInit(); // Set the widget defaults gwinSetDefaultFont(gdispOpenFont("UI2")); gwinSetDefaultStyle(&WhiteWidgetStyle, FALSE); gdispClear(White); // Attach the mouse input gwinAttachMouse(0); // create the widget createWidgets(); // We want to listen for widget events geventListenerInit(&gl); gwinAttachListener(&gl); while(1) { // Get an Event pe = geventEventWait(&gl, TIME_INFINITE); switch(pe->type) { case GEVENT_GWIN_CHECKBOX: if (((GEventGWinCheckbox*)pe)->checkbox == ghCheckbox1) { // The state of our checkbox has changed printf("Checkbox state: %d\r\n", ((GEventGWinCheckbox*)pe)->isChecked); } break; default: break; } } return 0; }
int main(void) { GEvent * pe; // Initialize the display gfxInit(); // Set the widget defaults font = gdispOpenFont("*"); // Get the first defined font. gwinSetDefaultFont(font); gwinSetDefaultStyle(&WhiteWidgetStyle, FALSE); gdispClear(White); // Create the gwin windows/widgets createWidgets(); // Assign toggles and dials to specific buttons & sliders etc. #if GINPUT_NEED_TOGGLE gwinAttachToggle(ghButton1, 0, 0); gwinAttachToggle(ghButton2, 0, 1); #endif #if GINPUT_NEED_DIAL gwinAttachDial(ghSlider1, 0, 0); gwinAttachDial(ghSlider3, 0, 1); #endif // Make the console visible gwinShow(ghConsole); gwinClear(ghConsole); // We want to listen for widget events geventListenerInit(&gl); gwinAttachListener(&gl); gtimerInit(&FlashTimer); #if !GWIN_NEED_TABSET // Press the Tab we want visible gwinRadioPress(ghTabButtons); #endif while(1) { // Get an Event pe = geventEventWait(&gl, TIME_INFINITE); switch(pe->type) { case GEVENT_GWIN_BUTTON: gwinPrintf(ghConsole, "Button %s\n", gwinGetText(((GEventGWinButton *)pe)->gwin)); break; case GEVENT_GWIN_SLIDER: gwinPrintf(ghConsole, "Slider %s=%d\n", gwinGetText(((GEventGWinSlider *)pe)->gwin), ((GEventGWinSlider *)pe)->position); break; case GEVENT_GWIN_CHECKBOX: gwinPrintf(ghConsole, "Checkbox %s=%s\n", gwinGetText(((GEventGWinCheckbox *)pe)->gwin), ((GEventGWinCheckbox *)pe)->isChecked ? "Checked" : "UnChecked"); // If it is the Disable All checkbox then do that. if (((GEventGWinCheckbox *)pe)->gwin == ghCheckDisableAll) { gwinPrintf(ghConsole, "%s All\n", ((GEventGWinCheckbox *)pe)->isChecked ? "Disable" : "Enable"); setEnabled(!((GEventGWinCheckbox *)pe)->isChecked); // If it is the toggle button checkbox start the flash. } else if (((GEventGWinCheckbox *)pe)->gwin == ghCheckbox3) { gwinFlash(ghCheckbox3); gtimerStart(&FlashTimer, FlashOffFn, 0, FALSE, 3000); } break; case GEVENT_GWIN_LIST: gwinPrintf(ghConsole, "List %s Item %d %s\n", gwinGetText(((GEventGWinList *)pe)->gwin), ((GEventGWinList *)pe)->item, gwinListItemIsSelected(((GEventGWinList *)pe)->gwin, ((GEventGWinList *)pe)->item) ? "Selected" : "Unselected"); break; case GEVENT_GWIN_RADIO: gwinPrintf(ghConsole, "Radio Group %u=%s\n", ((GEventGWinRadio *)pe)->group, gwinGetText(((GEventGWinRadio *)pe)->gwin)); switch(((GEventGWinRadio *)pe)->group) { #if !GWIN_NEED_TABSET case GROUP_TABS: // Set control visibility depending on the tab selected setTab(((GEventGWinRadio *)pe)->gwin); // We show the state of some of the GUI elements here setProgressbar(((GEventGWinRadio *)pe)->gwin == ghTabProgressbar); if (((GEventGWinRadio *)pe)->gwin == ghTabLabels) setLabels(); break; #endif case GROUP_COLORS: { const GWidgetStyle *pstyle; gwinPrintf(ghConsole, "Change Color Scheme\n"); if (((GEventGWinRadio *)pe)->gwin == ghRadioYellow) pstyle = &YellowWidgetStyle; else if (((GEventGWinRadio *)pe)->gwin == ghRadioBlack) pstyle = &BlackWidgetStyle; else pstyle = &WhiteWidgetStyle; // Clear the screen to the new color gdispClear(pstyle->background); // Update the style on all controls gwinSetDefaultStyle(pstyle, TRUE); } break; } break; #if GWIN_NEED_TABSET case GEVENT_GWIN_TABSET: gwinPrintf(ghConsole, "TabPage %u (%s)\n", ((GEventGWinTabset *)pe)->nPage, gwinTabsetGetTitle(((GEventGWinTabset *)pe)->ghPage)); // We show the state of some of the GUI elements here setProgressbar(((GEventGWinTabset *)pe)->ghPage == ghPgProgressbars); if (((GEventGWinTabset *)pe)->ghPage == ghPgLabels) setLabels(); break; #endif default: gwinPrintf(ghConsole, "Unknown %d\n", pe->type); break; } } return 0; }
GHandle gwinGFrameCreate(GDisplay *g, GFrameObject *fo, GWidgetInit *pInit, uint32_t flags) { if (!(fo = (GFrameObject *)_gcontainerCreate(g, &fo->gc, pInit, &frameVMT))) return 0; fo->btnClose = 0; fo->btnMin = 0; fo->btnMax = 0; /* Buttons require a border */ if ((flags & (GWIN_FRAME_CLOSE_BTN|GWIN_FRAME_MINMAX_BTN))) flags |= GWIN_FRAME_BORDER; /* create and initialize the listener if any button is present. */ if ((flags & (GWIN_FRAME_CLOSE_BTN|GWIN_FRAME_MINMAX_BTN))) { geventListenerInit(&fo->gl); gwinAttachListener(&fo->gl); geventRegisterCallback(&fo->gl, _callbackBtn, (GHandle)fo); } /* create close button if necessary */ if ((flags & GWIN_FRAME_CLOSE_BTN)) { GWidgetInit wi; gwinWidgetClearInit(&wi); wi.g.show = TRUE; wi.g.parent = &fo->gc.g; wi.g.x = fo->gc.g.width - BORDER_X - BUTTON_X; wi.g.y = (BORDER_Y - BUTTON_Y) / 2; wi.g.width = BUTTON_X; wi.g.height = BUTTON_Y; wi.text = "X"; fo->btnClose = gwinGButtonCreate(g, 0, &wi); } /* create minimize and maximize buttons if necessary */ if ((flags & GWIN_FRAME_MINMAX_BTN)) { GWidgetInit wi; gwinWidgetClearInit(&wi); wi.g.show = TRUE; wi.g.parent = &fo->gc.g; wi.g.x = (flags & GWIN_FRAME_CLOSE_BTN) ? fo->gc.g.width - 2*BORDER_X - 2*BUTTON_X : fo->gc.g.width - BORDER_X - BUTTON_X; wi.g.y = (BORDER_Y - BUTTON_Y) / 2; wi.g.width = BUTTON_X; wi.g.height = BUTTON_Y; wi.text = "O"; fo->btnMin = gwinGButtonCreate(g, 0, &wi); wi.g.x = (flags & GWIN_FRAME_CLOSE_BTN) ? fo->gc.g.width - 3*BORDER_X - 3*BUTTON_X : fo->gc.g.width - BORDER_X - BUTTON_X; wi.g.y = (BORDER_Y - BUTTON_Y) / 2; wi.g.width = BUTTON_X; wi.g.height = BUTTON_Y; wi.text = "_"; fo->btnMax = gwinGButtonCreate(g, 0, &wi); } /* Apply flags. We apply these here so the controls above are outside the child area */ fo->gc.g.flags |= flags; gwinSetVisible(&fo->gc.g, pInit->g.show); return &fo->gc.g; }
int main(void) { GEvent * pe; GEventKeyboard * pk; unsigned i; // Initialize the display gfxInit(); // Set the widget defaults font = gdispOpenFont("*"); // Get the first defined font. gwinSetDefaultFont(font); gwinSetDefaultStyle(&WhiteWidgetStyle, FALSE); gdispClear(White); // Create the gwin windows/widgets createWidgets(); // We want to listen for widget events geventListenerInit(&gl); gwinAttachListener(&gl); // We also want to listen to keyboard events from the virtual keyboard geventAttachSource(&gl, gwinKeyboardGetEventSource(ghKeyboard), GLISTEN_KEYTRANSITIONS|GLISTEN_KEYUP); while(1) { // Get an Event pe = geventEventWait(&gl, TIME_INFINITE); switch(pe->type) { case GEVENT_GWIN_KEYBOARD: // This is a widget event generated on the standard gwin event source gwinPrintf(ghConsole, "Keyboard visibility has changed\n"); break; case GEVENT_KEYBOARD: // This is a keyboard event from a keyboard source which must be separately listened to. // It is not sent on the gwin event source even though in this case it was generated by a gwin widget. pk = (GEventKeyboard *)pe; gwinPrintf(ghConsole, "KEYSTATE: 0x%04X [ %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s]", pk->keystate, (!pk->keystate ? "NONE " : ""), ((pk->keystate & GKEYSTATE_KEYUP) ? "KEYUP " : ""), ((pk->keystate & GKEYSTATE_REPEAT) ? "REPEAT " : ""), ((pk->keystate & GKEYSTATE_SPECIAL) ? "SPECIAL " : ""), ((pk->keystate & GKEYSTATE_RAW) ? "RAW " : ""), ((pk->keystate & GKEYSTATE_SHIFT_L) ? "LSHIFT " : ""), ((pk->keystate & GKEYSTATE_SHIFT_R) ? "RSHIFT " : ""), ((pk->keystate & GKEYSTATE_CTRL_L) ? "LCTRL " : ""), ((pk->keystate & GKEYSTATE_CTRL_R) ? "RCTRL " : ""), ((pk->keystate & GKEYSTATE_ALT_L) ? "LALT " : ""), ((pk->keystate & GKEYSTATE_ALT_R) ? "RALT " : ""), ((pk->keystate & GKEYSTATE_FN) ? "FN " : ""), ((pk->keystate & GKEYSTATE_COMPOSE) ? "COMPOSE " : ""), ((pk->keystate & GKEYSTATE_WINKEY) ? "WINKEY " : ""), ((pk->keystate & GKEYSTATE_CAPSLOCK) ? "CAPSLOCK " : ""), ((pk->keystate & GKEYSTATE_NUMLOCK) ? "NUMLOCK " : ""), ((pk->keystate & GKEYSTATE_SCROLLLOCK) ? "SCROLLLOCK " : "") ); if (pk->bytecount) { gwinPrintf(ghConsole, " Keys:"); for (i = 0; i < pk->bytecount; i++) gwinPrintf(ghConsole, " 0x%02X", (uint8_t)pk->c[i]); gwinPrintf(ghConsole, " ["); for (i = 0; i < pk->bytecount; i++) gwinPrintf(ghConsole, "%c", pk->c[i] >= ' ' && pk->c[i] <= '~' ? pk->c[i] : ' '); gwinPrintf(ghConsole, "]"); } gwinPrintf(ghConsole, "\n"); break; default: gwinPrintf(ghConsole, "Unknown %d\n", pe->type); break; } } return 0; }
int main(void) { GEvent * pe; // Initialize the display gfxInit(); // Set the widget defaults gwinSetDefaultFont(gdispOpenFont("*")); gwinSetDefaultStyle(&WhiteWidgetStyle, FALSE); gdispClear(White); // Connect the mouse #if GINPUT_NEED_MOUSE gwinAttachMouse(0); #endif // Create the gwin windows/widgets createWidgets(); // Assign toggles and dials to specific buttons & sliders etc. #if GINPUT_NEED_TOGGLE gwinAttachToggle(ghButton1, 0, 0); gwinAttachToggle(ghButton2, 0, 1); #endif #if GINPUT_NEED_DIAL gwinAttachDial(ghSlider1, 0, 0); gwinAttachDial(ghSlider3, 0, 1); #endif // Make the console visible gwinSetVisible(ghConsole, TRUE); gwinClear(ghConsole); // We want to listen for widget events geventListenerInit(&gl); gwinAttachListener(&gl); // Press the Tab we want visible gwinRadioPress(ghTabButtons); while(1) { // Get an Event pe = geventEventWait(&gl, TIME_INFINITE); switch(pe->type) { case GEVENT_GWIN_BUTTON: gwinPrintf(ghConsole, "Button %s\n", gwinGetText(((GEventGWinButton *)pe)->button)); break; case GEVENT_GWIN_SLIDER: gwinPrintf(ghConsole, "Slider %s=%d\n", gwinGetText(((GEventGWinSlider *)pe)->slider), ((GEventGWinSlider *)pe)->position); break; case GEVENT_GWIN_CHECKBOX: gwinPrintf(ghConsole, "Checkbox %s=%s\n", gwinGetText(((GEventGWinCheckbox *)pe)->checkbox), ((GEventGWinCheckbox *)pe)->isChecked ? "Checked" : "UnChecked"); // If it is the Disable All checkbox then do that. if (((GEventGWinCheckbox *)pe)->checkbox == ghCheckDisableAll) { gwinPrintf(ghConsole, "%s All\n", ((GEventGWinCheckbox *)pe)->isChecked ? "Disable" : "Enable"); setEnabled(!((GEventGWinCheckbox *)pe)->isChecked); } break; case GEVENT_GWIN_LIST: gwinPrintf(ghConsole, "List %s Item %d %s\n", gwinGetText(((GEventGWinList *)pe)->list), ((GEventGWinList *)pe)->item, gwinListItemIsSelected(((GEventGWinList *)pe)->list, ((GEventGWinList *)pe)->item) ? "Selected" : "Unselected"); break; case GEVENT_GWIN_RADIO: gwinPrintf(ghConsole, "Radio Group %u=%s\n", ((GEventGWinRadio *)pe)->group, gwinGetText(((GEventGWinRadio *)pe)->radio)); switch(((GEventGWinRadio *)pe)->group) { case GROUP_TABS: // Set control visibility depending on the tab selected setTab(((GEventGWinRadio *)pe)->radio); // Do some special animation for Label1 to demonstrate auto width sizing if (((GEventGWinRadio *)pe)->radio == ghTabLabels) { gwinPrintf(ghConsole, "Change Label Text\n"); gfxSleepMilliseconds(1000); gwinSetText(ghLabel1, "Very Big Label", FALSE); gfxSleepMilliseconds(1000); gwinSetText(ghLabel1, "Label", FALSE); } break; case GROUP_COLORS: { const GWidgetStyle *pstyle; gwinPrintf(ghConsole, "Change Color Scheme\n"); if (((GEventGWinRadio *)pe)->radio == ghRadioYellow) pstyle = &YellowWidgetStyle; else if (((GEventGWinRadio *)pe)->radio == ghRadioBlack) pstyle = &BlackWidgetStyle; else pstyle = &WhiteWidgetStyle; // Clear the screen to the new color - we avoid the console area as it can't redraw itself #if GDISP_NEED_CLIP gdispUnsetClip(); #endif gdispFillArea(0, 0, ScrWidth, ScrHeight/2, pstyle->background); gdispFillArea(0, ScrHeight/2, ScrWidth/2, ScrHeight/2, pstyle->background); // Update the style on all controls gwinSetDefaultStyle(pstyle, TRUE); } break; } break; default: gwinPrintf(ghConsole, "Unknown %d\n", pe->type); break; } } return 0; }
/* * 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 ; } } }