int main(void) { coord_t width, height; coord_t i, j; halInit(); chSysInit(); /* Initialize and clear the display */ gdispInit(); gdispClear(Black); // Get the screen size width = gdispGetWidth(); height = gdispGetHeight(); // Code Here gdispDrawBox(10, 10, width/2, height/2, Yellow); gdispFillArea(width/2, height/2, width/2-10, height/2-10, Blue); gdispDrawLine(5, 30, width-50, height-40, Red); for(i = 5, j = 0; i < width && j < height; i += 7, j += i/20) gdispDrawPixel (i, j, White); while(TRUE) { chThdSleepMilliseconds(500); } }
int main(void) { halInit(); chSysInit(); /* 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); /* * 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) { coord_t width, height; halInit(); chSysInit(); /* Initialize and clear the display */ gdispInit(); gdispClear(Black); // Get the screen size width = gdispGetWidth(); height = gdispGetHeight(); // Code Here gdispDrawCircle(width/2, height/2, 20, Yellow); gdispFillCircle (width/4, height/4, 50, Blue); gdispFillEllipse (width-100, height-100, 30, 60, Red); gdispDrawEllipse (width-100, height-100, 50, 20, Yellow); gdispDrawArc(width-width/8, height/8, 30, 10, 70, Gray); gdispFillArc(width/8, height/8, 30, 10, 70, Gray); while(TRUE) { chThdSleepMilliseconds(500); } }
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) { 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); } }
int main(void) { halInit(); chSysInit(); gdispInit(); gdispClear(Black); // gdispDrawXXX(...); while (TRUE) { chThdSleepMilliseconds(100); } }
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); } }
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) { color_t color = Black; uint16_t pen = 0; halInit(); chSysInit(); gdispInit(); ginputGetMouse(0); gdispSetOrientation(GDISP_ROTATE_90); drawScreen(); while (TRUE) { ginputGetMouseStatus(0, &ev); if (!(ev.current_buttons & GINPUT_MOUSE_BTN_LEFT)) continue; /* inside color box ? */ if(ev.y >= OFFSET && ev.y <= COLOR_SIZE) { if(GET_COLOR(0)) color = Black; else if(GET_COLOR(1)) color = Red; else if(GET_COLOR(2)) color = Yellow; else if(GET_COLOR(3)) color = Green; else if(GET_COLOR(4)) color = Blue; else if(GET_COLOR(5)) color = White; /* inside pen box ? */ } else if(ev.x >= OFFSET && ev.x <= PEN_SIZE) { if(GET_PEN(1)) pen = 0; else if(GET_PEN(2)) pen = 1; else if(GET_PEN(3)) pen = 2; else if(GET_PEN(4)) pen = 3; else if(GET_PEN(5)) pen = 4; /* inside drawing area ? */ } else if(DRAW_AREA(ev.x, ev.y)) { if(pen == 0) gdispDrawPixel(ev.x, ev.y, color); else gdispFillCircle(ev.x, ev.y, pen, color); } } }
int main(void) { float cx, cy; float zoom = 1.0f; halInit(); chSysInit(); gdispInit(); gdispSetOrientation(GDISP_ROTATE_270); /* where to zoom in */ cx = -0.086f; cy = 0.85f; while(TRUE) { mandelbrot(-2.0f*zoom+cx, -1.5f*zoom+cy, 2.0f*zoom+cx, 1.5f*zoom+cy); zoom *= 0.7f; if(zoom <= 0.00001f) zoom = 1.0f; } }
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); } }
/*------------------------------------------------------------------------* * GINPUT Touch Driver Calibrator. * *------------------------------------------------------------------------*/ int main(void) { GSourceHandle gs, gsNext, gsPrev; GEvent *pe; GEventMouse *pem; GEventGWinButton *peb; coord_t swidth, sheight; GHandle ghc, ghNext, ghPrev; BaseSequentialStream *gp; GEventType deviceType; font_t font; halInit(); // Initialise the Hardware chSysInit(); // Initialize the OS gdispInit(); // Initialize the display // Get the display dimensions swidth = gdispGetWidth(); sheight = gdispGetHeight(); ghNext = ghPrev = 0; // Create our title font = gdispOpenFont("UI2"); gdispFillStringBox(0, 0, swidth, 20, "Touch Calibration", font, Red, White, justifyLeft); // Create our main display window ghc = gwinCreateConsole(&gc, 0, 20, swidth, sheight-20, font); gwinClear(ghc); gp = gwinGetConsoleStream(ghc); // Initialize the mouse in our special no calibration mode. geventListenerInit(&gl); gs = ginputGetMouse(9999); geventAttachSource(&gl, gs, GLISTEN_MOUSEDOWNMOVES|GLISTEN_MOUSEMETA); /* * Test: Device Type */ StepDeviceType: gwinClear(ghc); gwinSetColor(ghc, Yellow); chprintf(gp, "\n1. DEVICE TYPE\n\n"); pem = (GEventMouse *)&gl.event; ginputGetMouseStatus(0, pem); deviceType = pem->type; gwinSetColor(ghc, White); chprintf(gp, "This is detected as a %s device\n\n", deviceType == GEVENT_MOUSE ? "MOUSE" : (pem->type == GEVENT_TOUCH ? "TOUCH" : "UNKNOWN")); if (ghNext) chprintf(gp, "Press Next or Back to continue.\n"); else if (deviceType == GEVENT_MOUSE) chprintf(gp, "Click the mouse button to move on to the next test.\n"); else chprintf(gp, "Press and release your finger to move on to the next test.\n"); while(1) { pe = geventEventWait(&gl, TIME_INFINITE); if (pe->type == GEVENT_GWIN_BUTTON) { peb = (GEventGWinButton *)pe; if (peb->button == ghPrev) goto StepClickJitter; if (peb->button == ghNext) break; } if (pe->type == GEVENT_MOUSE || pe->type == GEVENT_TOUCH) { pem = (GEventMouse *)pe; if (!ghNext && (pem->meta & GMETA_MOUSE_UP)) break; } } /* * Test: Mouse raw reading jitter */ StepRawJitter: gwinClear(ghc); gwinSetColor(ghc, Yellow); chprintf(gp, "\n2. GINPUT_MOUSE_READ_CYCLES\n\n"); gwinSetColor(ghc, White); if (deviceType == GEVENT_MOUSE) chprintf(gp, "Press and hold the mouse button.\n\n"); else chprintf(gp, "Press and hold on the surface.\n\n"); chprintf(gp, "Numbers will display in this window.\n" "Ensure that values don't jump around very much when your finger is stationary.\n\n" "Increasing GINPUT_MOUSE_READ_CYCLES helps reduce jitter but increases CPU usage.\n\n"); if (ghNext) chprintf(gp, "Press Next or Back to continue.\n"); else if (deviceType == GEVENT_MOUSE) chprintf(gp, "Release the mouse button to move on to the next test.\n"); else chprintf(gp, "Release your finger to move on to the next test.\n"); // For this test turn on ALL mouse movement events geventAttachSource(&gl, gs, GLISTEN_MOUSEDOWNMOVES|GLISTEN_MOUSEMETA|GLISTEN_MOUSENOFILTER); while(1) { pe = geventEventWait(&gl, TIME_INFINITE); if (pe->type == GEVENT_GWIN_BUTTON) { peb = (GEventGWinButton *)pe; if (peb->button == ghPrev) goto StepDeviceType; if (peb->button == ghNext) break; } if (pe->type == GEVENT_MOUSE || pe->type == GEVENT_TOUCH) { pem = (GEventMouse *)pe; if ((pem->current_buttons & GINPUT_MOUSE_BTN_LEFT)) chprintf(gp, "%u:%u\n", pem->x, pem->y); if (!ghNext && (pem->meta & GMETA_MOUSE_UP)) break; } } // Reset to just changed movements. geventAttachSource(&gl, gs, GLISTEN_MOUSEDOWNMOVES|GLISTEN_MOUSEMETA); /* * Test: Calibration */ StepCalibrate: gwinClear(ghc); gwinSetColor(ghc, Yellow); chprintf(gp, "\n3. GINPUT_MOUSE_CALIBRATION_ERROR\n\n"); gwinSetColor(ghc, Gray); chprintf(gp, "Ensure GINPUT_MOUSE_NEED_CALIBRATION = TRUE and GINPUT_MOUSE_CALIBRATION_ERROR is >= 0\n\n"); gwinSetColor(ghc, White); chprintf(gp, "You will be presented with a number of points to touch.\nPress them in turn.\n\n" "If the calibration repeatedly fails, increase GINPUT_MOUSE_CALIBRATION_ERROR and try again.\n\n"); if (ghNext) chprintf(gp, "Press Next to start the calibration.\n"); else if (deviceType == GEVENT_MOUSE) chprintf(gp, "Click the mouse button to start the calibration.\n"); else chprintf(gp, "Press and release your finger to start the calibration.\n"); while(1) { pe = geventEventWait(&gl, TIME_INFINITE); if (pe->type == GEVENT_GWIN_BUTTON) { peb = (GEventGWinButton *)pe; if (peb->button == ghPrev) goto StepRawJitter; if (peb->button == ghNext) break; } if (pe->type == GEVENT_MOUSE || pe->type == GEVENT_TOUCH) { pem = (GEventMouse *)pe; if (!ghNext && (pem->meta & GMETA_MOUSE_UP)) break; } } // Calibrate ginputCalibrateMouse(0); /* From now on we can use Next and Previous Buttons */ if (!ghNext) { ghNext = gwinCreateButton(&gNext, swidth-50, 0, 50, 20, font, GBTN_NORMAL); gwinSetButtonText(ghNext, "Next", FALSE); gsNext = gwinGetButtonSource(ghNext); geventAttachSource(&gl, gsNext, 0); gwinAttachButtonMouseSource(ghNext, gs); ghPrev = gwinCreateButton(&gPrev, swidth-100, 0, 50, 20, font, GBTN_NORMAL); gwinSetButtonText(ghPrev, "Back", FALSE); gsPrev = gwinGetButtonSource(ghPrev); geventAttachSource(&gl, gsPrev, 0); gwinAttachButtonMouseSource(ghPrev, gs); #if 0 { GSourceHandle gsButton1, gsButton2; // Attach a couple of hardware toggle buttons to our Next and Back buttons as well. // We can always use the mouse to trigger the buttons if you don't want to use hardware toggles. // This code depends on your hardware. Turn it on only if you have // defined a board definition for your toggle driver. Then change // the next two lines to be correct for your hardware. The values // below are correct for the Win32 toggle driver. gsButton1 = ginputGetToggle(GINPUT_TOGGLE_MOMENTARY1); gsButton2 = ginputGetToggle(GINPUT_TOGGLE_MOMENTARY2); gwinAttachButtonToggleSource(ghNext, gsButton2); gwinAttachButtonToggleSource(ghPrev, gsButton1); } #endif } // Calibration used the whole screen - re-establish our title gdispFillStringBox(0, 0, swidth, 20, "Touch Calibration", font, Green, White, justifyLeft); gwinButtonDraw(ghNext); gwinButtonDraw(ghPrev); /* * Test: Mouse movement jitter */ StepJitter: gwinClear(ghc); gwinSetColor(ghc, Yellow); chprintf(gp, "\n4. GINPUT_MOUSE_MOVE_JITTER\n\n"); gwinSetColor(ghc, White); if (deviceType == GEVENT_MOUSE) chprintf(gp, "Press and hold the mouse button and move around as if to draw.\n\n"); else chprintf(gp, "Press firmly on the surface and move around as if to draw.\n\n"); chprintf(gp, "Dots will display in this window. Ensure that when you stop moving your finger that " "new dots stop displaying.\nNew dots should only display when your finger is moving.\n\n" "Adjust GINPUT_MOUSE_MOVE_JITTER to the smallest value that this reliably works for.\n\n"); chprintf(gp, "Press Next or Back to continue.\n\n"); while(1) { pe = geventEventWait(&gl, TIME_INFINITE); if (pe->type == GEVENT_GWIN_BUTTON) { peb = (GEventGWinButton *)pe; if (peb->button == ghPrev) goto StepCalibrate; if (peb->button == ghNext) break; } if (pe->type == GEVENT_MOUSE || pe->type == GEVENT_TOUCH) { pem = (GEventMouse *)pe; if ((pem->current_buttons & GINPUT_MOUSE_BTN_LEFT)) chprintf(gp, "."); } } /* * Test: Polling frequency */ StepPolling: gwinClear(ghc); gwinSetColor(ghc, Yellow); chprintf(gp, "\n5. GINPUT_MOUSE_POLL_PERIOD\n\n"); gwinSetColor(ghc, White); chprintf(gp, "Press firmly on the surface (or press and hold the mouse button) and move around as if to draw.\n\n"); chprintf(gp, "A green line will follow your finger.\n" "Adjust GINPUT_MOUSE_POLL_PERIOD to the highest value that provides a line without " "gaps that are too big.\nDecreasing the value increases CPU usage.\n" "About 25 (millisecs) normally produces good results." "This test can be ignored for interrupt driven drivers.\n\n"); chprintf(gp, "Press Next or Back to continue.\n\n"); while(1) { pe = geventEventWait(&gl, TIME_INFINITE); if (pe->type == GEVENT_GWIN_BUTTON) { peb = (GEventGWinButton *)pe; if (peb->button == ghPrev) goto StepJitter; if (peb->button == ghNext) break; } if (pe->type == GEVENT_MOUSE || pe->type == GEVENT_TOUCH) { pem = (GEventMouse *)pe; if ((pem->current_buttons & GINPUT_MOUSE_BTN_LEFT)) gdispDrawPixel(pem->x, pem->y, Green); } } /* * Test: Click Jitter */ StepClickJitter: gwinClear(ghc); gwinSetColor(ghc, Yellow); chprintf(gp, "\n6. GINPUT_MOUSE_MAX_CLICK_JITTER\n\n"); gwinSetColor(ghc, White); chprintf(gp, "Press and release the touch surface to \"click\".\nTry both short and long presses.\n"); chprintf(gp, "For a mouse click with the left and right buttons.\n\n"); chprintf(gp, "Dots will display in this window. A yellow dash is a left (or short) click. " "A red x is a right (or long) click.\n\n" "Adjust GINPUT_MOUSE_CLICK_JITTER to the smallest value that this reliably works for.\n" "Adjust GINPUT_MOUSE_CLICK_TIME to adjust distinguishing short vs long presses.\n" "TIME_INFINITE means there are no long presses (although a right mouse button will still work).\n\n" "Note: moving your finger (mouse) during a click cancels it.\n\n"); chprintf(gp, "This is the last test but you can press Next or Back to continue.\n\n"); while(1) { pe = geventEventWait(&gl, TIME_INFINITE); if (pe->type == GEVENT_GWIN_BUTTON) { peb = (GEventGWinButton *)pe; if (peb->button == ghPrev) goto StepPolling; if (peb->button == ghNext) break; } if (pe->type == GEVENT_MOUSE || pe->type == GEVENT_TOUCH) { pem = (GEventMouse *)pe; if ((pem->meta & GMETA_MOUSE_CLICK)) { gwinSetColor(ghc, Yellow); chprintf(gp, "-"); } if ((pem->meta & GMETA_MOUSE_CXTCLICK)) { gwinSetColor(ghc, Red); chprintf(gp, "x"); } } } // Can't let this really exit goto StepDeviceType; }
/* * Application entry point. */ int main(void) { color_t color = Black; uint16_t pen = 0; /* * 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(); gdispInit(); ginputGetMouse(0); gdispSetOrientation(GDISP_ROTATE_90); drawScreen(); palSetPadMode(GPIOC, 7, PAL_MODE_OUTPUT_PUSHPULL); palSetPadMode(GPIOC, 8, PAL_MODE_OUTPUT_PUSHPULL); palSetPadMode(GPIOC, 9, PAL_MODE_OUTPUT_PUSHPULL); /* * Creates the blinker thread. */ (void)chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); while (TRUE) { ginputGetMouseStatus(0, &ev); if (!(ev.current_buttons & GINPUT_MOUSE_BTN_LEFT)) { chThdSleepMicroseconds(500); // Senza questo sleep l'USB non parte continue; } /* inside color box ? */ if(ev.y >= OFFSET && ev.y <= COLOR_SIZE) { if(GET_COLOR(0)) color = Black; else if(GET_COLOR(1)) color = Red; else if(GET_COLOR(2)) color = Yellow; else if(GET_COLOR(3)) color = Green; else if(GET_COLOR(4)) color = Blue; else if(GET_COLOR(5)) color = White; /* inside pen box ? */ } else if(ev.x >= OFFSET && ev.x <= PEN_SIZE) { if(GET_PEN(1)) pen = 0; else if(GET_PEN(2)) pen = 1; else if(GET_PEN(3)) pen = 2; else if(GET_PEN(4)) pen = 3; else if(GET_PEN(5)) pen = 4; /* inside drawing area ? */ } else if(DRAW_AREA(ev.x, ev.y)) { if(pen == 0) gdispDrawPixel(ev.x, ev.y, color); else gdispFillCircle(ev.x, ev.y, pen, color); } } }
/* * Application entry point. */ int main(void) { color_t color = Black; uint16_t pen = 0; Thread *shelltp = NULL; /* * 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(); gdispInit(); ginputGetMouse(0); gdispSetOrientation(GDISP_ROTATE_90); drawScreen(); /* * Initializes a serial-over-USB CDC driver. */ sduObjectInit(&SDU1); sduStart(&SDU1, &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); /* * Shell manager initialization. */ shellInit(); /* * Creates the blinker thread. */ chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); /* * Normal main() thread activity, in this demo it does nothing except * sleeping in a loop and check the button state. */ while (TRUE) { if (!shelltp && (SDU1.config->usbp->state == USB_ACTIVE)) shelltp = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO); else if (chThdTerminated(shelltp)) { chThdRelease(shelltp); /* Recovers memory of the previous shell. */ shelltp = NULL; /* Triggers spawning of a new shell. */ } ginputGetMouseStatus(0, &ev); if (!(ev.current_buttons & GINPUT_MOUSE_BTN_LEFT)) { chThdSleepMicroseconds(500); // Senza questo sleep l'USB non parte continue; } /* inside color box ? */ if(ev.y >= OFFSET && ev.y <= COLOR_SIZE) { if(GET_COLOR(0)) color = Black; else if(GET_COLOR(1)) color = Red; else if(GET_COLOR(2)) color = Yellow; else if(GET_COLOR(3)) color = Green; else if(GET_COLOR(4)) color = Blue; else if(GET_COLOR(5)) color = White; /* inside pen box ? */ } else if(ev.x >= OFFSET && ev.x <= PEN_SIZE) { if(GET_PEN(1)) pen = 0; else if(GET_PEN(2)) pen = 1; else if(GET_PEN(3)) pen = 2; else if(GET_PEN(4)) pen = 3; else if(GET_PEN(5)) pen = 4; /* inside drawing area ? */ } else if(DRAW_AREA(ev.x, ev.y)) { if(pen == 0) gdispDrawPixel(ev.x, ev.y, color); else gdispFillCircle(ev.x, ev.y, pen, color); } } }