/* * 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); } }
bool keyframe_display_layer_text(keyframe_animation_t* animation, visualizer_state_t* state) { (void)animation; gdispClear(White); gdispDrawString(0, 10, state->layer_text, state->font_dejavusansbold12, Black); gdispFlush(); return false; }
void drawScreen(void) { char *msg = "Notepad/GFX"; font_t font1, font2; font1 = gdispOpenFont("UI2 Double"); font2 = gdispOpenFont("LargeNumbers"); gdispClear(White); //gdispFillArea(0,0,320,240,White); gdispDrawString(gdispGetWidth()-gdispGetStringWidth(msg, font1)-3, 3, msg, font1, Black); /* colors */ gdispFillArea(0 * COLOR_SIZE + 3, 3, COLOR_SIZE, COLOR_SIZE, Black); /* Black */ gdispFillArea(1 * COLOR_SIZE + 3, 3, COLOR_SIZE, COLOR_SIZE, Red); /* Red */ gdispFillArea(2 * COLOR_SIZE + 3, 3, COLOR_SIZE, COLOR_SIZE, Yellow); /* Yellow */ gdispFillArea(3 * COLOR_SIZE + 3, 3, COLOR_SIZE, COLOR_SIZE, Green); /* Green */ gdispFillArea(4 * COLOR_SIZE + 3, 3, COLOR_SIZE, COLOR_SIZE, Blue); /* Blue */ gdispDrawBox (5 * COLOR_SIZE + 3, 3, COLOR_SIZE, COLOR_SIZE, Black); /* White */ /* pens */ gdispDrawString(OFFSET * 2, DRAW_PEN(1), "1", font2, Black); gdispDrawString(OFFSET * 2, DRAW_PEN(2), "2", font2, Black); gdispDrawString(OFFSET * 2, DRAW_PEN(3), "3", font2, Black); gdispDrawString(OFFSET * 2, DRAW_PEN(4), "4", font2, Black); gdispDrawString(OFFSET * 2, DRAW_PEN(5), "5", font2, Black); gdispCloseFont(font1); gdispCloseFont(font2); }
void drawScreen(void) { char *msg = "uGFX"; font_t font1, font2; font1 = gdispOpenFont("DejaVuSans24*"); font2 = gdispOpenFont("DejaVuSans12*"); gdispClear(White); gdispDrawString(gdispGetWidth()-gdispGetStringWidth(msg, font1)-3, 3, msg, font1, Black); /* colors */ gdispFillArea(0 * COLOR_SIZE + 3, 3, COLOR_SIZE, COLOR_SIZE, Black); /* Black */ gdispFillArea(1 * COLOR_SIZE + 3, 3, COLOR_SIZE, COLOR_SIZE, Red); /* Red */ gdispFillArea(2 * COLOR_SIZE + 3, 3, COLOR_SIZE, COLOR_SIZE, Yellow); /* Yellow */ gdispFillArea(3 * COLOR_SIZE + 3, 3, COLOR_SIZE, COLOR_SIZE, Green); /* Green */ gdispFillArea(4 * COLOR_SIZE + 3, 3, COLOR_SIZE, COLOR_SIZE, Blue); /* Blue */ gdispDrawBox (5 * COLOR_SIZE + 3, 3, COLOR_SIZE, COLOR_SIZE, Black); /* White */ /* pens */ gdispFillStringBox(OFFSET * 2, DRAW_PEN(1), PEN_SIZE, PEN_SIZE, "1", font2, White, Black, justifyCenter); gdispFillStringBox(OFFSET * 2, DRAW_PEN(2), PEN_SIZE, PEN_SIZE, "2", font2, White, Black, justifyCenter); gdispFillStringBox(OFFSET * 2, DRAW_PEN(3), PEN_SIZE, PEN_SIZE, "3", font2, White, Black, justifyCenter); gdispFillStringBox(OFFSET * 2, DRAW_PEN(4), PEN_SIZE, PEN_SIZE, "4", font2, White, Black, justifyCenter); gdispFillStringBox(OFFSET * 2, DRAW_PEN(5), PEN_SIZE, PEN_SIZE, "5", font2, White, Black, justifyCenter); gdispCloseFont(font1); gdispCloseFont(font2); }
int main(void) { coord_t swidth, sheight; halInit(); // Initialize the Hardware chSysInit(); // Initialize the OS gdispInit(); // Initialize the display gdispClear(Black); // Get the display dimensions swidth = gdispGetWidth(); sheight = gdispGetHeight(); // Set up IO for our image #if USE_MEMORY_FILE gdispImageSetMemoryReader(&myImage, test_pal8); #else gdispImageSetSimulFileReader(&myImage, "test-pal8.bmp"); #endif gdispImageOpen(&myImage); gdispImageDraw(&myImage, 0, 0, swidth, sheight, 0, 0); gdispImageClose(&myImage); while(1) { chThdSleepMilliseconds(1000); } return 0; }
int main(void) { /* Initialize and clear the display */ gfxInit(); gdispClear(White); /* Create the 3D window */ { GWindowInit wi; gwinClearInit(&wi); wi.show = TRUE; wi.x = (gdispGetWidth()-GL3D_WINDOW_SIZE)/2; wi.y = (gdispGetHeight()-GL3D_WINDOW_SIZE)/2; wi.width = GL3D_WINDOW_SIZE; wi.height = GL3D_WINDOW_SIZE; gh = gwinGL3DCreate(0, &wi); } /* Init the 3D stuff */ setup(); init(); while(TRUE) { // rate control gfxSleepMilliseconds(FRAME_DELAY); // move and redraw spin(); } }
int main(void) { coord_t width, height, r1, r2, cx, cy; uint8_t sectors; // Initialize and clear the display gfxInit(); // Get the screen size width = gdispGetWidth(); height = gdispGetHeight(); // Initialize some variables r1 = width > height ? height/3 : width/3; r2 = r1*3/4; cx = width/2; cy = height/2; sectors = 1; while(1) { // Draw the arc sectors gdispClear(White); gdispDrawArcSectors(cx, cy, r1, sectors, Blue); gdispFillArcSectors(cx, cy, r2, sectors, Red); // Increase the sectors counter sectors++; // Waste some time gfxSleepMilliseconds(250); } }
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; }
bool lcd_keyframe_display_led_states(keyframe_animation_t* animation, visualizer_state_t* state) { (void)animation; char output[LED_STATE_STRING_SIZE]; get_led_state_string(output, state); gdispClear(White); gdispDrawString(0, 10, output, state->font_dejavusansbold12, Black); return false; }
int main(void) { uint8_t i; font_t font1, font2; halInit(); chSysInit(); /* initialize and clear the display */ gdispInit(); gdispClear(Black); font1 = gdispOpenFont("UI2 Double"); font2 = gdispOpenFont("Small"); /* create the three console windows and set a font for each */ GW1 = gwinCreateConsole(NULL, 0, 0, gdispGetWidth(), gdispGetHeight()/2, font1); GW2 = gwinCreateConsole(NULL, 0, gdispGetHeight()/2, gdispGetWidth()/2, gdispGetHeight(), font2); GW3 = gwinCreateConsole(NULL, gdispGetWidth()/2, gdispGetHeight()/2, gdispGetWidth(), gdispGetHeight(), font2); /* Set the fore- and background colors for each console */ gwinSetColor(GW1, Green); gwinSetBgColor(GW1, Black); gwinSetColor(GW2, White); gwinSetBgColor(GW2, Blue); gwinSetColor(GW3, Black); gwinSetBgColor(GW3, Red); /* clear all console windows - to set background */ gwinClear(GW1); gwinClear(GW2); gwinClear(GW3); /* receive the stream pointers of each console */ S1 = gwinGetConsoleStream(GW1); S2 = gwinGetConsoleStream(GW2); S3 = gwinGetConsoleStream(GW3); /* Output some data on the first console */ for(i = 0; i < 10; i++) { chprintf(S1, "Hello ChibiOS/GFX!\r\n"); } /* Output some data on the second console */ for(i = 0; i < 16; i++) { chprintf(S2, "Message Nr.: %d\r\n", i+1); } /* Output some data on the third console */ for(i = 0; i < 18; i++) { chprintf(S3, "Message Nr.: %d\r\n", i+1); } while(TRUE) { chThdSleepMilliseconds(500); } }
bool lcd_keyframe_display_layer_bitmap(keyframe_animation_t* animation, visualizer_state_t* state) { (void)animation; const char* layer_help = "1=On D=Default B=Both"; char layer_buffer[16 + 4]; // 3 spaces and one null terminator gdispClear(White); gdispDrawString(0, 0, layer_help, state->font_fixed5x8, Black); format_layer_bitmap_string(state->status.default_layer, state->status.layer, layer_buffer); gdispDrawString(0, 10, layer_buffer, state->font_fixed5x8, Black); format_layer_bitmap_string(state->status.default_layer >> 16, state->status.layer >> 16, layer_buffer); gdispDrawString(0, 20, layer_buffer, state->font_fixed5x8, Black); return false; }
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; }
bool lcd_keyframe_display_layer_and_led_states(keyframe_animation_t* animation, visualizer_state_t* state) { (void)animation; gdispClear(White); uint8_t y = 10; if (state->status.leds) { char output[LED_STATE_STRING_SIZE]; get_led_state_string(output, state); gdispDrawString(0, 1, output, state->font_dejavusansbold12, Black); y = 17; } gdispDrawString(0, y, state->layer_text, state->font_dejavusansbold12, Black); return false; }
int main(void) { halInit(); chSysInit(); gdispInit(); gdispClear(Black); // gdispDrawXXX(...); while (TRUE) { chThdSleepMilliseconds(100); } }
void benchmark(void) { uint32_t i, pixels, ms, pps; char pps_str[25]; coord_t height, width, rx, ry, rcx, rcy; color_t random_color; font_t font; gdispSetOrientation(GDISP_ROTATE_90); width = gdispGetWidth(); height = gdispGetHeight(); font = gdispOpenFont("UI2 Double"); gdispDrawStringBox(0, 0, width, 30, "ChibiOS/GFX - Benchmark", font, White, justifyCenter); font = gdispOpenFont("UI2"); gdispDrawStringBox(0, height/2, width, 30, "5000 random rectangles", font, White, justifyCenter); gfxSleepMilliseconds(3000); /* seed for the rand() */ srand(DWT_CYCCNT); pixels = 0; CPU_RESET_CYCLECOUNTER; for (i = 0; i < 5000; i++) { random_color = (rand() % 65535); rx = (rand() % (width-10)); ry = (rand() % (height-10)); rcx = (rand() % ((width-rx)-10))+10; rcy = (rand() % ((height-ry)-10))+10; gdispFillArea(rx, ry, rcx, rcy, random_color); pixels += (rcx+1)*(rcy+1); } ms = DWT_CYCCNT / 168000; pps = (float)pixels/((float)ms/1000.0f); memset (pps_str, 0, sizeof(pps_str)); uitoa(pps, pps_str, sizeof(pps_str)); strcat(pps_str, " Pixels/s"); font = gdispOpenFont("UI2 Double"); gdispClear(Black); gdispDrawStringBox(0, 0, width, 30, "ChibiOS/GFX - Benchmark", font, White, justifyCenter); gdispDrawStringBox(0, height/2, width, 30, pps_str, font, White, justifyCenter); //gdispDrawString(20, height/2, pps_str, font, White); }
bool lcd_keyframe_display_mods_bitmap(keyframe_animation_t* animation, visualizer_state_t* state) { (void)animation; const char* title = "Modifier states"; const char* mods_header = " CSAG CSAG "; char status_buffer[12]; gdispClear(White); gdispDrawString(0, 0, title, state->font_fixed5x8, Black); gdispDrawString(0, 10, mods_header, state->font_fixed5x8, Black); format_mods_bitmap_string(state->status.mods, status_buffer); gdispDrawString(0, 20, status_buffer, state->font_fixed5x8, Black); return false; }
int main(void) { halInit(); chSysInit(); gdispInit(); tpInit(&TOUCHPADD1); tpCalibrate(); gdispClear(Black); while (TRUE) { gdispDrawPixel(tpReadX(), tpReadY(), Green); } }
int main(void) { halInit(); chSysInit(); gdispInit(); gdispClear(Lime); gfxConsoleInit(&CON1, 0, 0, gdispGetWidth(), gdispGetHeight(), &fontLarger, Black, White); chprintf((BaseSequentialStream *)&CON1, "Hello the time is %d\nGoodbye.", chTimeNow()); while (TRUE) { chThdSleepMilliseconds(100); } }
bool lcd_keyframe_draw_logo(keyframe_animation_t* animation, visualizer_state_t* state) { (void)state; (void)animation; // Read the uGFX documentation for information how to use the displays // http://wiki.ugfx.org/index.php/Main_Page gdispClear(White); // You can use static variables for things that can't be found in the animation // or state structs, here we use the image //gdispGBlitArea is a tricky function to use since it supports blitting part of the image // if you have full screen image, then just use LCD_WIDTH and LCD_HEIGHT for both source and target dimensions gdispGBlitArea(GDISP, 0, 0, LCD_WIDTH, LCD_HEIGHT, 0, 0, LCD_WIDTH, (pixel_t*)resource_lcd_logo); return false; }
int main(void) { coord_t width, height; font_t font1, font2, font3, font4; const char *msg; halInit(); chSysInit(); /* Initialize and clear the display */ gdispInit(); gdispClear(Black); // Get the screen size width = gdispGetWidth(); height = gdispGetHeight(); // Get the fonts we want to use font1 = gdispOpenFont("UI2"); font2 = gdispOpenFont("UI2 Double"); font3 = gdispOpenFont("UI2 Narrow"); font4 = gdispOpenFont("LargeNumbers"); // Display large numbers on the right (measuring the string) msg = "123456"; gdispDrawString(width-gdispGetStringWidth(msg, font4)-3, 3, msg, font4, Green); // Display the font name under it. msg = gdispGetFontName(font4); gdispDrawString(width-gdispGetStringWidth(msg, font1)-3, 20, msg, font1, Green); // Demonstrate our other fonts gdispDrawString(10, 10, "Writing with Font 'UI2'", font1, Yellow); gdispFillString(10, 35, "Writing with Font 'UI2 Double'", font2, Red, White); gdispDrawStringBox(0, 50, width, 40, "Writing with Font 'UI2 Narrow'", font3, Red, justifyCenter); gdispFillStringBox(0, 90, width, 40, "Filled Centered", font3, Pink, Gray, justifyCenter); // Clean up the fonts gdispCloseFont(font1); gdispCloseFont(font2); gdispCloseFont(font3); gdispCloseFont(font4); // Wait forever while(TRUE) { chThdSleepMilliseconds(500); } }
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; }
void gfxInit(void) { static bool_t initDone = FALSE; /* Ensure we only initialise once */ if (initDone) return; initDone = TRUE; /* These must be initialised in the order of their dependancies */ _gosInit(); #if GFX_USE_GMISC _gmiscInit(); #endif #if GFX_USE_GEVENT _geventInit(); #endif #if GFX_USE_GTIMER _gtimerInit(); #endif #if GFX_USE_GDISP _gdispInit(); gdispClear(Black); #endif #if GFX_USE_GWIN _gwinInit(); #endif #if GFX_USE_GINPUT _ginputInit(); #endif #if GFX_USE_TDISP _tdispInit(); tdispHome(); tdispClear(); #endif #if GFX_USE_GADC _gadcInit(); #endif #if GFX_USE_GAUDIN _gaudinInit(); #endif #if GFX_USE_GAUDOUT _gaudoutInit(); #endif }
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) { halInit(); chSysInit(); coord_t i, j; /* Initialize and clear the display */ gdispInit(); gdispClear(Lime); /* Create two windows */ GW1 = gwinCreateWindow(NULL, 20, 10, 200, 150); GW2 = gwinCreateWindow(NULL, 50, 190, 150, 100); /* Set fore- and background colors for both windows */ gwinSetColor(GW1, Black); gwinSetBgColor(GW1, White); gwinSetColor(GW2, White); gwinSetBgColor(GW2, Blue); /* Clear both windows - to set background color */ gwinClear(GW1); gwinClear(GW2); gwinDrawLine (GW1, 5, 30, 150, 110); for(i=5, j=0; i < 200 && j < 150; i+=3, j+=i/20) gwinDrawPixel (GW1, i, j); /* * Draw two filled circles at the same coordinate * of each window to demonstrate the relative coordinates * of windows */ gwinFillCircle(GW1, 20, 20, 15); gwinFillCircle(GW2, 20, 20, 15); while(TRUE) { chThdSleepMilliseconds(500); } }
int main(void) { halInit(); chSysInit(); gdispInit(); gdispSetOrientation(GDISP_ROTATE_90); gdispClear(Black); Graph G1 = { gdispGetWidth()/2, gdispGetHeight()/2, -150, 150, -110, 110, 21, 5, TRUE, TRUE, White, Grey, }; graphDrawSystem(&G1); uint16_t i; for(i = 0; i < 2500; i++) graphDrawDot(&G1, i-170, 80*sin(2*0.2*M_PI*i/180), 1, Blue); for(i = 0; i < 2500; i++) graphDrawDot(&G1, i/5-150, 95*sin(2*0.2*M_PI*i/180), 1, Green); while(TRUE) { chThdSleepMilliseconds(100); } }
bool_t ginputCalibrateMouse(uint16_t instance) { #if !GINPUT_MOUSE_NEED_CALIBRATION (void) instance; return FALSE; #else const coord_t height = gdispGetHeight(); const coord_t width = gdispGetWidth(); const MousePoint cross[] = {{(width / 4), (height / 4)}, {(width - (width / 4)) , (height / 4)}, {(width - (width / 4)) , (height - (height / 4))}, {(width / 2), (height / 2)}}; /* Check point */ MousePoint points[GINPUT_MOUSE_CALIBRATION_POINTS]; const MousePoint *pc; MousePoint *pt; int32_t px, py; unsigned i, j; font_t font1, font2; #if GINPUT_MOUSE_MAX_CALIBRATION_ERROR >= 0 unsigned err; #endif if (instance || (MouseConfig.flags & FLG_IN_CAL)) return FALSE; font1 = gdispOpenFont(GINPUT_MOUSE_CALIBRATION_FONT); font2 = gdispOpenFont(GINPUT_MOUSE_CALIBRATION_FONT2); MouseConfig.flags |= FLG_IN_CAL; gtimerStop(&MouseTimer); MouseConfig.flags &= ~(FLG_CAL_OK|FLG_CAL_SAVED); #if GDISP_NEED_CONTROL gdispSetOrientation(GDISP_ROTATE_0); #endif #if GDISP_NEED_CLIP gdispSetClip(0, 0, width, height); #endif #if GINPUT_MOUSE_MAX_CALIBRATION_ERROR >= 0 while(1) { #endif gdispClear(Blue); gdispFillStringBox(0, 5, width, 30, GINPUT_MOUSE_CALIBRATION_TEXT, font1, White, Blue, justifyCenter); for(i = 0, pt = points, pc = cross; i < GINPUT_MOUSE_CALIBRATION_POINTS; i++, pt++, pc++) { _tsDrawCross(pc); do { /* Wait for the mouse to be pressed */ while(get_raw_reading(&MouseConfig.t), !(MouseConfig.t.buttons & GINPUT_MOUSE_BTN_LEFT)) chThdSleepMilliseconds(20); /* Average all the samples while the mouse is down */ for(px = py = 0, j = 0; chThdSleepMilliseconds(20), /* Settling time between readings */ get_raw_reading(&MouseConfig.t), (MouseConfig.t.buttons & GINPUT_MOUSE_BTN_LEFT); j++) { px += MouseConfig.t.x; py += MouseConfig.t.y; } } while(!j); pt->x = px / j; pt->y = py / j; _tsClearCross(pc); if (i >= 1 && pt->x == (pt-1)->x && pt->y == (pt-1)->y) { gdispFillStringBox(0, 35, width, 40, GINPUT_MOUSE_CALIBRATION_SAME_TEXT, font2, Red, Yellow, justifyCenter); chThdSleepMilliseconds(5000); gdispFillArea(0, 35, width, 40, Blue); } } /* Apply 3 point calibration algorithm */ _tsDo3PointCalibration(cross, points, &MouseConfig.caldata); /* Verification of correctness of calibration (optional) : * See if the 4th point (Middle of the screen) coincides with the calibrated * result. If point is within +/- Squareroot(ERROR) pixel margin, then successful calibration * Else, start from the beginning. */ #if GINPUT_MOUSE_MAX_CALIBRATION_ERROR >= 0 /* Transform the co-ordinates */ MouseConfig.t.x = points[3].x; MouseConfig.t.y = points[3].y; _tsTransform(&MouseConfig.t, &MouseConfig.caldata); /* Calculate the delta */ err = (MouseConfig.t.x - cross[3].x) * (MouseConfig.t.x - cross[3].x) + (MouseConfig.t.y - cross[3].y) * (MouseConfig.t.y - cross[3].y); if (err <= GINPUT_MOUSE_MAX_CALIBRATION_ERROR * GINPUT_MOUSE_MAX_CALIBRATION_ERROR) break; gdispFillStringBox(0, 35, width, 40, GINPUT_MOUSE_CALIBRATION_ERROR_TEXT, font2, Red, Yellow, justifyCenter); chThdSleepMilliseconds(5000); } #endif // Restart everything gdispCloseFont(font1); gdispCloseFont(font2); MouseConfig.flags |= FLG_CAL_OK; MouseConfig.last_buttons = 0; get_calibrated_reading(&MouseConfig.t); MouseConfig.flags &= ~FLG_IN_CAL; if ((MouseConfig.flags & FLG_INIT_DONE)) gtimerStart(&MouseTimer, MousePoll, 0, TRUE, GINPUT_MOUSE_POLL_PERIOD); // Save the calibration data (if possible) if (MouseConfig.fnsavecal) { MouseConfig.fnsavecal(instance, (const uint8_t *)&MouseConfig.caldata, sizeof(MouseConfig.caldata)); MouseConfig.flags |= FLG_CAL_SAVED; } return TRUE; #endif }
/** * Our main function. * There are two prototypes - one for systems with a command line and one for embedded systems without one. */ int main(proto_args) { uint16_t cmd[5]; unsigned cnt; // Initialize and clear the display gfxInit(); font = gdispOpenFont("UI2"); // Open the connection gdispDrawStringBox(0, 0, gdispGetWidth(), gdispGetHeight(), "Connecting to host...", font, White, justifyCenter); StartSockets(); netfd = doConnect(cmd_args); if (netfd == (SOCKET_TYPE)-1) gfxHalt("Could not connect to the specified server"); gdispClear(Black); // Get the initial packet from the host if (!getpkt(cmd, 2)) goto alldone; if (cmd[0] != GNETCODE_INIT || cmd[1] != GNETCODE_VERSION) gfxHalt("Oops - The protocol doesn't look like one we understand"); // Get the rest of the initial arguments if (!getpkt(cmd, 4)) goto alldone; // cmd[] = width, height, pixelformat, hasmouse // We will ignore size mismatches but the pixel format must match if (cmd[2] != GDISP_PIXELFORMAT) gfxHalt("Oops - The remote display is using a different pixel format to us.\nTry defining GDISP_PIXELFORMAT in your gfxconf.h file."); #if GFX_USE_GINPUT && GINPUT_NEED_MOUSE // Start the mouse thread if needed if (cmd[3]) gfxThreadClose(gfxThreadCreate(waNetThread, sizeof(waNetThread), HIGH_PRIORITY, NetThread, 0)); #endif // Process incoming instructions while(getpkt(cmd, 1)) { switch(cmd[0]) { case GNETCODE_FLUSH: gdispFlush(); break; case GNETCODE_PIXEL: if (!getpkt(cmd, 3)) goto alldone; // cmd[] = x, y, color gdispDrawPixel(cmd[0], cmd[1], cmd[2]); break; case GNETCODE_FILL: if (!getpkt(cmd, 5)) goto alldone; // cmd[] = x, y, cx, cy, color gdispFillArea(cmd[0], cmd[1], cmd[2], cmd[3], cmd[4]); break; case GNETCODE_BLIT: if (!getpkt(cmd, 4)) goto alldone; // cmd[] = x, y, cx, cy - Followed by cx * cy pixels gdispStreamStart(cmd[0],cmd[1],cmd[2],cmd[3]); for(cnt = (unsigned)cmd[2] * cmd[3]; cnt; cnt--) { if (!getpkt(cmd, 1)) goto alldone; gdispStreamColor(cmd[0]); } gdispStreamStop(); break; #if GDISP_NEED_PIXELREAD case GNETCODE_READ: if (!getpkt(cmd, 2)) goto alldone; // cmd[] = x, y - Response is GNETCODE_READ,color cmd[1] = gdispGetPixelColor(cmd[0], cmd[1]); cmd[0] = GNETCODE_READ; if (!sendpkt(cmd, 2)) goto alldone; break; #endif #if GDISP_NEED_SCROLL case GNETCODE_SCROLL: if (!getpkt(cmd, 5)) goto alldone; // cmd[] = x, y, cx, cy, lines gdispVerticalScroll(cmd[0], cmd[1], cmd[2], cmd[3], cmd[4], Black); break; #endif case GNETCODE_CONTROL: if (!getpkt(cmd, 2)) goto alldone; // cmd[] = what,data - Response is GNETCODE_CONTROL, 0x0000 (fail) or GNETCODE_CONTROL, 0x0001 (success) gdispControl(cmd[0], (void *)(unsigned)cmd[1]); switch(cmd[0]) { case GDISP_CONTROL_ORIENTATION: cmd[1] = (uint16_t)gdispGetOrientation() == cmd[1] ? 1 : 0; break; case GDISP_CONTROL_POWER: cmd[1] = (uint16_t)gdispGetPowerMode() == cmd[1] ? 1 : 0; break; case GDISP_CONTROL_BACKLIGHT: cmd[1] = (uint16_t)gdispGetBacklight() == cmd[1] ? 1 : 0; break; default: cmd[1] = 0; break; } cmd[0] = GNETCODE_CONTROL; if (!sendpkt(cmd, 2)) goto alldone; break; default: gfxHalt("Oops - The host has sent invalid commands"); break; } } alldone: closesocket(netfd); gfxHalt("Connection closed"); 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; }
static msg_t notepadThread(void *param) { GEventMouse *pem; GEventGWinButton *peb; GHandle ghc; (void)param; /* Get the display dimensions */ swidth = gdispGetWidth(); sheight = gdispGetHeight(); font = gdispOpenFont("UI2"); /* Initialize the mouse */ geventListenerInit(&gl); ginputGetMouse(0); initButtons(); /* Configure the GIF decoder with the toolbar Icon images */ gdispImageSetMemoryReader(&toolbarImageFilmstrip, toolbarIcons); gdispImageOpen(&toolbarImageFilmstrip); /* Set clip to the entire screen */ gdispSetClip(0, 0, swidth, sheight); /* Clear the screen with the window background * Also, draw the title bars */ gdispClear(nCurColorScheme.winBgColor); gdispDrawBox(0, 0, swidth, sheight, nCurColorScheme.titleBarColor); gdispFillArea(0, 0, swidth, NPAD_TITLEBAR_HEIGHT, nCurColorScheme.titleBarColor); gdispDrawStringBox(NPAD_TITLETEXT_START_X, NPAD_TITLETEXT_START_Y, swidth, NPAD_TITLEBAR_HEIGHT, NPAD_TITLETEXT_STR, font, nCurColorScheme.titleTextColor, justifyLeft); /* Create the drawing window, draw its border */ gdispDrawBox(NPAD_DRAWING_AREA_START_X - 1, NPAD_DRAWING_AREA_START_Y - 1, NPAD_DRAWING_AREA_WIDTH + 2, NPAD_DRAWING_AREA_HEIGHT + 2, nCurColorScheme.drawingWinBorder); nDrawingArea = gwinCreateWindow(NULL, NPAD_DRAWING_AREA_START_X, NPAD_DRAWING_AREA_START_Y, NPAD_DRAWING_AREA_WIDTH, NPAD_DRAWING_AREA_HEIGHT); /* Create the bottom status bar console */ ghc = gwinCreateConsole(NULL, NPAD_STATUSBAR_START_X, NPAD_STATUSBAR_START_Y, NPAD_STATUSBAR_WIDTH, NPAD_STATUSBAR_HEIGHT, font); gdispImageDraw(&toolbarImageFilmstrip, NPAD_STATUSBAR_ICON_START_X, NPAD_STATUSBAR_ICON_START_Y, NPAD_ICON_WIDTH, NPAD_ICON_HEIGHT, NPAD_ICON_START(12), 0); gwinSetBgColor(ghc, nCurColorScheme.winBgColor); gwinSetColor(ghc, Black); gstatusConsole = gwinGetConsoleStream(ghc); /* draw the buttons */ gwinSetColor(nDrawingArea, Black); gwinSetBgColor(nDrawingArea, White); gwinClear(nDrawingArea); gwinClear(ghc); drawButtons(); drawVButtons(); chprintf(gstatusConsole, "Welcome to ChibiOS/GFX Notepad demo."); ncoreSpawnDrawThread(nDrawingArea, gstatusConsole); while(TRUE) { pem = (GEventMouse *) geventEventWait(&gl, TIME_INFINITE); /* button pressed... */ if (pem->type == GEVENT_GWIN_BUTTON) { peb = (GEventGWinButton *)pem; if (peb->button == H(btnNew)) { // Reset all the settings selColorIndex = 0; selPenWidth = 0; ncoreSetMode(NCORE_MODE_DRAW); gwinSetColor(nDrawingArea, Black); gwinSetBgColor(nDrawingArea, White); // Refresh the buttons drawButtons(); drawVButtons(); gwinClear(nDrawingArea); chprintf(gstatusConsole, "\nScreen Cleared."); } else if (peb->button == H(btnOpen)) { chprintf(gstatusConsole, "\nFile Open not implemented."); } else if (peb->button == H(btnSave)) { chprintf(gstatusConsole, "\nFile Save not implemented."); } else if (peb->button == H(btnPencil)) { ncoreSetMode(NCORE_MODE_DRAW); drawVButtons(); chprintf(gstatusConsole, "\nPencil Tool Selected."); } else if (peb->button == H(btnEraser)) { ncoreSetMode(NCORE_MODE_ERASE); drawVButtons(); chprintf(gstatusConsole, "\nEraser Tool Selected."); } else if (peb->button == H(btnFill)) { ncoreSetMode(NCORE_MODE_FILL); drawVButtons(); chprintf(gstatusConsole, "\nFill Tool Selected."); } else if (peb->button == H(btnClose)) { break; } } } gwinDestroyWindow(ghc); // No need to destroy the buttons as they are statically allocated gdispCloseFont(font); ncoreTerminateDrawThread(); gdispImageClose(&toolbarImageFilmstrip); 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; }