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; }
/* * 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(); gfxInit(); // Set the widget defaults gwinSetDefaultFont(gdispOpenFont("UI2")); gwinSetDefaultStyle(&WhiteWidgetStyle, FALSE); gdispClear(White); /* * Normal main() thread activity, in this demo it does nothing. */ while (TRUE) { chThdSleepMilliseconds(500); } }
int main(void) { // uint16_t i; // one wire initialization static OneWireDriver owDrv; static const OneWireConfig owCfg = { .dqPort = GPIOB, .dqPad = 10, .dqAlternate = 7, .uartd = &UARTD3 }; static OneWireRomAddress romAddr[8]; static bool_t searched = FALSE; static bool_t initialized = FALSE; // Initialize the uGFX and the underlying system gfxInit(); // Lock screen uint8_t secret_sequence[UNLOCKER_COLS * UNLOCKER_ROWS]; displayUnlockerSetup(secret_sequence); displayUnlocker(secret_sequence); // Set the widget defaults gwinSetDefaultFont(gdispOpenFont("UI2")); gwinSetDefaultStyle(&WhiteWidgetStyle, FALSE); gdispClear(Black); // Create the widget createWidgets(); // Print to the console gwinPrintf(ghConsole, "Witamy w konsoli!\r\n\n"); gwinPrintf(ghConsole, "Odczyt temp z czujnikow DS18B20.\r\n"); //initialize ds18b20 if (initialized == FALSE) { oneWireInit(&owDrv, &owCfg); initialized = TRUE; } if (searched == FALSE) { oneWireSearchRom (&owDrv, FALSE, romAddr, ARRAY_LEN(romAddr)); searched = TRUE; } while (1) { oneWireSearchRom (&owDrv, FALSE, romAddr, ARRAY_LEN(romAddr)); for (uint8_t i=0; i< ARRAY_LEN(romAddr); i++) { if (romAddr[i].addr[0] == 0x28) { ds1820BInit (&owDrv, &(romAddr[i]), 10); const float temp =ds1820BGetTemp (&owDrv, &(romAddr[i])); gwinPrintf(ghConsole, "czujnik %d temp =%.2f\r\n", i, temp); } } gfxSleepMilliseconds(800); } 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; }
int main(void) { // Initialize the display gfxInit(); // Set the widget defaults gwinSetDefaultFont(gdispOpenFont("*")); gwinSetDefaultStyle(&WhiteWidgetStyle, FALSE); gdispClear(White); // Create the widget createWidgets(); while(1) { gfxSleepMilliseconds(1000); } return 0; }
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; }
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; }
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); */ }