int main(void) {
	uint8_t i;
	font_t	font1, font2;

	/* initialize and clear the display */
	gfxInit();

	/* Set some fonts */
	font1 = gdispOpenFont("UI2");
	font2 = gdispOpenFont("DejaVu Sans 12");
	gwinSetDefaultFont(font1);

	/* create the three console windows */
	{
		GWindowInit		wi;

		wi.show = TRUE;
		wi.x = 0; wi.y = 0; wi.width = gdispGetWidth(); wi.height = gdispGetHeight()/2;
		GW1 = gwinConsoleCreate(NULL, &wi);
		wi.y = gdispGetHeight()/2; wi.width = gdispGetWidth()/2; wi.height = gdispGetHeight();
		GW2 = gwinConsoleCreate(NULL, &wi);
		wi.x = gdispGetWidth()/2; wi.height = gdispGetHeight();
		GW3 = gwinConsoleCreate(NULL, &wi);
	}

	/* Use a special font for GW1 */
	gwinSetFont(GW1, 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);

	/* Output some data on the first console */
	for(i = 0; i < 10; i++) {
		gwinPrintf(GW1, "Hello uGFX!\r\n");
	}

	/* Output some data on the second console */
	for(i = 0; i < 16; i++) {
		gwinPrintf(GW2, "Message Nr.: %d\r\n", i+1);
	}

	/* Output some data on the third console */
	for(i = 0; i < 18; i++) {
		gwinPrintf(GW3, "Message Nr.: %d\r\n", i+1);
	}

	while(TRUE) {
		gfxSleepMilliseconds(500);
	}
}
Example #2
0
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;
}
Example #3
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);
  }
}
Example #4
0
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;
}
Example #5
0
File: main.c Project: bhdminh/uGFX
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;
}
Example #6
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;
}
Example #7
0
File: main.c Project: DaviWei/uGFX
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;
}
Example #8
0
/*------------------------------------------------------------------------*
 * GINPUT Touch Driver Calibrator.                                        *
 *------------------------------------------------------------------------*/
int main(void) {
	GSourceHandle			gs;
	GEventMouse				*pem;
	bool_t					isFirstTime;
	bool_t					isCalibrated;
	bool_t					isTouch;
	bool_t					isFinger;
	const char *			isFingerText;
	const char *			deviceText;
	GMouse *				m;
	GMouseVMT *				vmt;
	GMouseJitter *			pjit;
	uint32_t				calerr;

	gfxInit();		// Initialize the display

	// Get the display dimensions
	swidth = gdispGetWidth();
	sheight = gdispGetHeight();

	// Create our title
	font = gdispOpenFont("UI2");
	gwinSetDefaultFont(font);
	bWidth = gdispGetStringWidth("Next", font);
	bHeight = gdispGetStringWidth("Prev", font);
	if (bHeight > bWidth) bWidth = bHeight;
	bWidth += 4;
	bWidth2 = gdispGetStringWidth("+", font)*2;
	bHeight = gdispGetStringWidth("-", font)*2;
	if (bHeight > bWidth2) bWidth2 = bHeight;
	bWidth2 += 4;
	bHeight = gdispGetFontMetric(font, fontHeight)*2+2;

	// Create our main display window
	{
		GWindowInit				wi;

		gwinClearInit(&wi);
		wi.show = TRUE; wi.x = 0; wi.y = bHeight; wi.width = swidth; wi.height = sheight-bHeight;
		ghc = gwinConsoleCreate(&gc, &wi);
	}

	// Initialize the listener
	geventListenerInit(&gl);

	// Copy the current mouse's VMT so we can play with it.
	m = (GMouse *)gdriverGetInstance(GDRIVER_TYPE_MOUSE, 0);
	if (!m) gfxHalt("No mouse instance 0");
	vmt = gfxAlloc(sizeof(GMouseVMT));
	if (!vmt) gfxHalt("Could not allocate memory for mouse VMT");
	memcpy(vmt, m->d.vmt, sizeof(GMouseVMT));

	// Swap VMT's on the current mouse to our RAM copy
	m->d.vmt = (const GDriverVMT *)vmt;

	// Listen for events
	gs = ginputGetMouse(0);
	geventAttachSource(&gl, gs, GLISTEN_MOUSEDOWNMOVES|GLISTEN_MOUSEMETA);

	// Get initial display settings for buttons
	isFirstTime = TRUE;
	isCalibrated = (vmt->d.flags & GMOUSE_VFLG_CALIBRATE) ? FALSE : TRUE;
	calerr = 0;

	/*
	 * Test: Device Type
	 */

StepDeviceType:
	DrawHeader("1. Device Type", isCalibrated, isCalibrated && !isFirstTime, isCalibrated);

	// Get the type of device and the current mode
	isTouch = (vmt->d.flags & GMOUSE_VFLG_TOUCH) ? TRUE : FALSE;
	isFinger = (m->flags & GMOUSE_FLG_FINGERMODE) ? TRUE : FALSE;
	pjit = isFinger ? &vmt->finger_jitter : &vmt->pen_jitter;
	isFingerText = isFinger ? "finger" : "pen";
	deviceText = isTouch ? isFingerText : "mouse";

	gwinPrintf(ghc, "This is detected as a %s device\n\n", isTouch ? "TOUCH" : "MOUSE");
	gwinPrintf(ghc, "It is currently in %s mode\n\n", isFinger ? "FINGER" : "PEN");

	if (!isCalibrated)
		gwinPrintf(ghc, "Press and release your %s to move on to the next test.\n", deviceText);
	else {
		gwinPrintf(ghc, "Press + for pen or - for finger.\n");
		if (isFirstTime)
			gwinPrintf(ghc, "Press Next to continue.\n");
		else
			gwinPrintf(ghc, "Press Next or Back to continue.\n");
	}

	while(1) {
		pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE);
		if (isCalibrated) {
			switch (CheckButtons(pem)) {
			case BTN_NEXT:
				break;
			case BTN_PREV:
				if (!isFirstTime)
					goto StepDrawing;
				continue;
			case BTN_PLUS:
				m->flags &= ~GMOUSE_FLG_FINGERMODE;
				goto StepDeviceType;
			case BTN_MINUS:
				m->flags |= GMOUSE_FLG_FINGERMODE;
				goto StepDeviceType;
			default:
				continue;
			}
			break;
		}
		if ((pem->buttons & GMETA_MOUSE_UP))
			break;
	}

	/*
	 * Test: Mouse raw reading
	 */

StepRawReading:
	DrawHeader("2. Raw Mouse Output", FALSE, FALSE, FALSE);
	if (isTouch)
		gwinPrintf(ghc, "Press and hold on the surface.\n\n");
	else
		gwinPrintf(ghc, "Press and hold the mouse button.\n\n");
	gwinPrintf(ghc, "The raw values coming from your mouse driver will display.\n\n");
	gwinPrintf(ghc, "Make sure the x and y values change as you move.\n\n");

	gwinPrintf(ghc, "Release your %s to move on to the next test.\n", deviceText);

	// Make sure we are in uncalibrated mode
	m->flags &= ~(GMOUSE_FLG_CALIBRATE|GMOUSE_FLG_CLIP);

	// For this test turn on ALL mouse movement events
	geventAttachSource(&gl, gs, GLISTEN_MOUSEDOWNMOVES|GLISTEN_MOUSEUPMOVES|GLISTEN_MOUSEMETA|GLISTEN_MOUSENOFILTER);

	while(1) {
		// Always sleep a bit first to enable other events. We actually don't
		// mind missing events for this test.
		gfxSleepMilliseconds(100);
		pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE);
		gwinPrintf(ghc, "%u, %u z=%u b=0x%04x\n", pem->x, pem->y, pem->z, pem->buttons & ~GINPUT_MISSED_MOUSE_EVENT);
		if ((pem->buttons & GMETA_MOUSE_UP))
			break;
	}

	// Reset to calibrated condition
	if (isCalibrated) {
		m->flags |= GMOUSE_FLG_CLIP;
		if ((vmt->d.flags & GMOUSE_VFLG_CALIBRATE))
			m->flags |= GMOUSE_FLG_CALIBRATE;
	}

	// Reset to just changed movements.
	geventAttachSource(&gl, gs, GLISTEN_MOUSEDOWNMOVES|GLISTEN_MOUSEMETA);

	/*
	 * Test: Calibration
	 */

StepCalibrate:
	DrawHeader("3. Calibration Jitter", isCalibrated, isCalibrated, isCalibrated);
	if ((vmt->d.flags & GMOUSE_VFLG_CALIBRATE)) {
		gwinPrintf(ghc, "You will be presented with a number of points to touch.\nPress them in turn.\n\n"
				"If the calibration repeatedly fails, increase the jitter for %s calibration and try again.\n\n", isFingerText);
		gwinPrintf(ghc, "Pressing the surface for longer gives more accurate results.\n\n");
		if (calerr)
			gwinPrintf(ghc, "Last calibration error ^ 2 = %u\n", calerr);
		gwinPrintf(ghc, "Calibration jitter (%s) = %u\n", isFingerText, pjit->calibrate);
		if (isCalibrated)
			gwinPrintf(ghc, "Press + or - to adjust.\n");
	} else {
		gwinPrintf(ghc, "This device does not need calibration.\n\n");
	}
	if (isCalibrated)
		gwinPrintf(ghc, "Press Next or Back to continue.\n");
	else
		gwinPrintf(ghc, "Press and release your %s to move on to start calibration.\n", deviceText);

	while(1) {
		pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE);
		if (isCalibrated) {
			switch (CheckButtons(pem)) {
			case BTN_NEXT:
				break;
			case BTN_PREV:
				goto StepRawReading;
			case BTN_PLUS:
				gwinPrintf(ghc, "Calibration jitter (%s) = %u", isFingerText, ++pjit->calibrate);
				continue;
			case BTN_MINUS:
				gwinPrintf(ghc, "Calibration jitter (%s) = %u", isFingerText, --pjit->calibrate);
				continue;
			default:
				continue;
			}
			break;
		}
		if ((pem->buttons & GMETA_MOUSE_UP))
			break;
	}

	// Calibrate
	if ((vmt->d.flags & GMOUSE_VFLG_CALIBRATE)) {
		calerr = ginputCalibrateMouse(0);
		if (calerr)
			goto StepCalibrate;
		isCalibrated = TRUE;
	}

	/*
	 * Test: Mouse coords
	 */

StepMouseCoords:
	DrawHeader("4. Show Mouse Coordinates", TRUE, TRUE, TRUE);
	if (isTouch)
		gwinPrintf(ghc, "Press and hold on the surface.\n\n");
	else
		gwinPrintf(ghc, "Press and hold the mouse button.\n\n");
	gwinPrintf(ghc, "Check the coordinates against where it should be on the screen.\n\n");
	gwinPrintf(ghc, "X should be 0 to %u\nY should be 0 to %u\n\n", swidth-1, sheight-1);
	gwinPrintf(ghc, "Press + to retry using extremes or - for normal calibration.\n");
	gwinPrintf(ghc, "Press Next or Back to continue.\n");

	// For this test normal mouse movement events
	geventAttachSource(&gl, gs, GLISTEN_MOUSEDOWNMOVES|GLISTEN_MOUSEMETA);

	while(1) {
		// Always sleep a bit first to enable other events. We actually don't
		// mind missing events for this test.
		gfxSleepMilliseconds(100);
		pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE);

		switch (CheckButtons(pem)) {
		case BTN_NEXT:
			break;
		case BTN_PREV:
			goto StepCalibrate;
		case BTN_PLUS:
			vmt->d.flags |= GMOUSE_VFLG_CAL_EXTREMES;
			goto StepCalibrate;
		case BTN_MINUS:
			vmt->d.flags &= ~GMOUSE_VFLG_CAL_EXTREMES;
			goto StepCalibrate;
		default:
			gwinPrintf(ghc, "%u, %u\n", pem->x, pem->y);
			continue;
		}
		break;
	}

	// Reset to just changed movements.
	geventAttachSource(&gl, gs, GLISTEN_MOUSEDOWNMOVES|GLISTEN_MOUSEMETA);

	/*
	 * Test: Mouse movement jitter
	 */

StepMovementJitter:
	DrawHeader("5. Movement Jitter", TRUE, TRUE, TRUE);
	if (isTouch)
		gwinPrintf(ghc, "Press firmly on the surface and move around as if to draw.\n\n");
	else
		gwinPrintf(ghc, "Press and hold the mouse button and move around as if to draw.\n\n");

	gwinPrintf(ghc, "Dots will display in this window. Ensure that when you stop moving your %s that "
			"new dots stop displaying.\nNew dots should only display when your %s is moving.\n\n"
			"Adjust %s movement jitter to the smallest value that this reliably works for.\n\n", deviceText, deviceText, isFingerText);
	gwinPrintf(ghc, "Movement jitter (%s) = %u\n", isFingerText, pjit->move);
	gwinPrintf(ghc, "Press + or - to adjust.\n");
	gwinPrintf(ghc, "Press Next or Back to continue.\n\n");

	while(1) {
		pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE);
		switch (CheckButtons(pem)) {
		case BTN_NEXT:
			break;
		case BTN_PREV:
			goto StepMouseCoords;
		case BTN_PLUS:
			gwinPrintf(ghc, "Movement jitter (%s) = %u", isFingerText, ++pjit->move);
			continue;
		case BTN_MINUS:
			gwinPrintf(ghc, "Movement jitter (%s) = %u", isFingerText, --pjit->move);
			continue;
		default:
			if ((pem->buttons & GINPUT_MOUSE_BTN_LEFT))
				gwinPrintf(ghc, ".");
			continue;
		}
		break;
	}

	/*
	 * Test: Click Jitter
	 */

StepClickJitter:
	gwinClear(ghc);
	gwinSetColor(ghc, Yellow);
	gwinPrintf(ghc, "\n6. Click Jitter\n\n");

	gwinSetColor(ghc, White);
	if (isTouch)
		gwinPrintf(ghc, "Press and release the touch surface to \"click\".\nTry both short and long presses.\n");
	else
		gwinPrintf(ghc, "Click the mouse with the left and right buttons.\n\n");
	gwinPrintf(ghc, "A yellow dash is a left (or short) click.\n"
			"A red x is a right (or long) click.\n\n"
			"Adjust %s click jitter to the smallest value that this reliably works for.\n"
			"Note: moving your %s during a click cancels it.\n\n", isFingerText, deviceText);
	gwinPrintf(ghc, "Click jitter (%s) = %u\n", isFingerText, pjit->click);
	gwinPrintf(ghc, "Press + or - to adjust.\n");
	gwinPrintf(ghc, "Press Next or Back to continue.\n\n");

	while(1) {
		pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE);
		switch (CheckButtons(pem)) {
		case BTN_NEXT:
			break;
		case BTN_PREV:
			goto StepMovementJitter;
		case BTN_PLUS:
			gwinPrintf(ghc, "Click jitter (%s) = %u", isFingerText, ++pjit->click);
			continue;
		case BTN_MINUS:
			gwinPrintf(ghc, "Click jitter (%s) = %u", isFingerText, --pjit->click);
			continue;
		default:
			if ((pem->buttons & GMETA_MOUSE_CLICK)) {
				gwinSetColor(ghc, Yellow);
				gwinPrintf(ghc, "-");
			}
			if ((pem->buttons & GMETA_MOUSE_CXTCLICK)) {
				gwinSetColor(ghc, uRed);
				gwinPrintf(ghc, "x");
			}
			continue;
		}
		break;
	}

	/*
	 * Test: Polling frequency
	 */

StepDrawing:
	gwinClear(ghc);
	gwinSetColor(ghc, Yellow);
	gwinPrintf(ghc, "\n7. Drawing\n\n");

	gwinSetColor(ghc, White);
	gwinPrintf(ghc, "Press firmly on the surface (or press and hold the mouse button) and move around as if to draw.\n\n");
	gwinPrintf(ghc, "A green line will follow your %s.\n\n", deviceText);
	gwinPrintf(ghc, "Pressing Next will start the tests again but with the option of changing pen/finger mode.\n\n");
	gwinPrintf(ghc, "Press Next or Back to continue.\n\n");

	while(1) {
		pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE);
		if (pem->y < bHeight && pem->x >= swidth-2*bWidth) {
			if ((pem->buttons & GMETA_MOUSE_UP)) {
				if (pem->x >= swidth-bWidth)
					break;
				goto StepClickJitter;
			}
		}
		gdispDrawPixel(pem->x, pem->y, uGreen);
	}

	// Can't let this really exit
	isFirstTime = FALSE;
	goto StepDeviceType;
}
Example #9
0
/*------------------------------------------------------------------------*
 * GINPUT Touch Driver Calibrator.                                        *
 *------------------------------------------------------------------------*/
int main(void) {
	GSourceHandle			gs;
	GEventMouse				*pem;
	GMouse *				m;
	GMouseVMT *				vmt;

	gfxInit();		// Initialize the display

	// Get the display dimensions
	swidth = gdispGetWidth();
	sheight = gdispGetHeight();

	// Create our title
	font = gdispOpenFont("UI2");
	gwinSetDefaultFont(font);
	bHeight = gdispGetFontMetric(font, fontHeight)+4;
	gdispFillStringBox(0, 0, swidth, bHeight, "Raw Touch Readings", font, Red, White, justifyCenter);

	// Create our main display writing window
	{
		GWindowInit				wi;

		gwinClearInit(&wi);
		wi.show = TRUE; wi.x = 0; wi.y = bHeight; wi.width = swidth; wi.height = sheight-bHeight;
		ghc = gwinConsoleCreate(&gc, &wi);
	}

	// Initialize the listener
	geventListenerInit(&gl);

	// Copy the current mouse's VMT so we can play with it.
	m = (GMouse *)gdriverGetInstance(GDRIVER_TYPE_MOUSE, 0);
	if (!m) gfxHalt("No mouse instance 0");
	vmt = gfxAlloc(sizeof(GMouseVMT));
	if (!vmt) gfxHalt("Could not allocate memory for mouse VMT");
	memcpy(vmt, m->d.vmt, sizeof(GMouseVMT));

	// Swap VMT's on the current mouse to our RAM copy
	m->d.vmt = (const GDriverVMT *)vmt;

	// Listen for events
	gs = ginputGetMouse(0);
	geventAttachSource(&gl, gs, GLISTEN_MOUSEDOWNMOVES|GLISTEN_MOUSEMETA);

	// Make sure we are in uncalibrated pen mode
	m->flags &= ~(GMOUSE_FLG_CALIBRATE|GMOUSE_FLG_CLIP|GMOUSE_FLG_FINGERMODE);

	// Pretend we are a mouse, turn off all touch processing, turn off move and click filtering
	vmt->d.flags &= ~(GMOUSE_VFLG_TOUCH | GMOUSE_VFLG_ONLY_DOWN | GMOUSE_VFLG_POORUPDOWN);
	vmt->pen_jitter.move = 0;
	vmt->pen_jitter.click = 0;

	// For this test turn on ALL mouse movement events
	geventAttachSource(&gl, gs, GLISTEN_MOUSEDOWNMOVES|GLISTEN_MOUSEUPMOVES|GLISTEN_MOUSEMETA|GLISTEN_MOUSENOFILTER);

	while(1) {
		pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE);
		gwinPrintf(ghc, "%u, %u z=%u b=0x%04x\n", pem->x, pem->y, pem->z, pem->buttons & ~GINPUT_MISSED_MOUSE_EVENT);

		// Always sleep a bit first to enable other events. We actually don't mind missing events.
		gfxSleepMilliseconds(100);
	}
}
Example #10
0
File: main.c Project: bhdminh/uGFX
/*------------------------------------------------------------------------*
 * GINPUT Touch Driver Calibrator.                                        *
 *------------------------------------------------------------------------*/
int main(void) {
	GSourceHandle			gs;
	GEventMouse				*pem;
	coord_t					swidth, sheight;
	GHandle					ghc;
	GEventType				deviceType;
	bool_t					calibrated;
	coord_t					bWidth, bHeight;

	gfxInit();		// Initialize the display

	// Get the display dimensions
	swidth = gdispGetWidth();
	sheight = gdispGetHeight();
	calibrated = FALSE;

	// Create our title
	font = gdispOpenFont("UI2");
	gwinSetDefaultFont(font);
	bWidth = gdispGetStringWidth("Next", font);
	bHeight = gdispGetStringWidth("Prev", font);
	if (bHeight > bWidth) bWidth = bHeight;
	bWidth += 4;
	bHeight = gdispGetFontMetric(font, fontHeight)+2;
	gdispFillStringBox(0, 0, swidth, bHeight, "Touch Calibration", font, Red, White, justifyLeft);

	// Create our main display window
	{
		GWindowInit				wi;

		gwinClearInit(&wi);
		wi.show = TRUE; wi.x = 0; wi.y = bHeight; wi.width = swidth; wi.height = sheight-bHeight;
		ghc = gwinConsoleCreate(&gc, &wi);
	}
	gwinClear(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);
	gwinPrintf(ghc, "\n1. DEVICE TYPE\n\n");

	pem = (GEventMouse *)&gl.event;
	ginputGetMouseStatus(0, pem);
	deviceType = pem->type;

	gwinSetColor(ghc, White);
	gwinPrintf(ghc, "This is detected as a %s device\n\n",
		deviceType == GEVENT_MOUSE ? "MOUSE" : (pem->type == GEVENT_TOUCH ? "TOUCH" : "UNKNOWN"));

	if (calibrated)
		gwinPrintf(ghc, "Press Next or Back to continue.\n");
	else if (deviceType == GEVENT_MOUSE)
		gwinPrintf(ghc, "Click the mouse button to move on to the next test.\n");
	else
		gwinPrintf(ghc, "Press and release your finger to move on to the next test.\n");

	while(1) {
		pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE);
		if (calibrated) {
			if (pem->y < bHeight && pem->x >= swidth-2*bWidth) {
				if ((pem->meta & GMETA_MOUSE_UP)) {
					if (pem->x >= swidth-bWidth)
						break;
					goto StepClickJitter;
				}
			}
		} else if ((pem->meta & GMETA_MOUSE_UP))
			break;
	}

	/*
	 * Test: Mouse raw reading jitter
	 */

StepRawJitter:
	gwinClear(ghc);
	gwinSetColor(ghc, Yellow);
	gwinPrintf(ghc, "\n2. GINPUT_MOUSE_READ_CYCLES\n\n");

	gwinSetColor(ghc, White);
	if (deviceType == GEVENT_MOUSE)
		gwinPrintf(ghc, "Press and hold the mouse button.\n\n");
	else
		gwinPrintf(ghc, "Press and hold on the surface.\n\n");
	gwinPrintf(ghc, "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 (calibrated)
		gwinPrintf(ghc, "Press Next or Back to continue.\n");
	else if (deviceType == GEVENT_MOUSE)
		gwinPrintf(ghc, "Release the mouse button to move on to the next test.\n");
	else
		gwinPrintf(ghc, "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_MOUSEUPMOVES|GLISTEN_MOUSEMETA|GLISTEN_MOUSENOFILTER);

	while(1) {
		// Always sleep a bit first to enable other events. We actually don't
		// mind missing events for this test.
		gfxSleepMilliseconds(100);
		pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE);
		if (calibrated) {
			if (pem->y < bHeight && pem->x >= swidth-2*bWidth) {
				if ((pem->meta & GMETA_MOUSE_UP)) {
					if (pem->x >= swidth-bWidth)
						break;
					goto StepDeviceType;
				}
			}
		} else if ((pem->meta & GMETA_MOUSE_UP))
			break;
		gwinPrintf(ghc, "%u:%u z=%u b=0x%04x m=%04x\n", pem->x, pem->y, pem->z, pem->current_buttons, pem->meta);
	}

	// Reset to just changed movements.
	geventAttachSource(&gl, gs, GLISTEN_MOUSEDOWNMOVES|GLISTEN_MOUSEMETA);

	/*
	 * Test: Calibration
	 */

StepCalibrate:
	gwinClear(ghc);
	gwinSetColor(ghc, Yellow);
	gwinPrintf(ghc, "\n3. GINPUT_MOUSE_CALIBRATION_ERROR\n\n");
	gwinSetColor(ghc, Gray);
	gwinPrintf(ghc, "Ensure GINPUT_MOUSE_NEED_CALIBRATION = TRUE and GINPUT_MOUSE_CALIBRATION_ERROR is >= 0\n\n");
	gwinSetColor(ghc, White);
	gwinPrintf(ghc, "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 (calibrated)
		gwinPrintf(ghc, "Press Next to start the calibration.\n");
	else if (deviceType == GEVENT_MOUSE)
		gwinPrintf(ghc, "Click the mouse button to start the calibration.\n");
	else
		gwinPrintf(ghc, "Press and release your finger to start the calibration.\n");

	while(1) {
		pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE);
		if (calibrated) {
			if (pem->y < bHeight && pem->x >= swidth-2*bWidth) {
				if ((pem->meta & GMETA_MOUSE_UP)) {
					if (pem->x >= swidth-bWidth)
						break;
					goto StepRawJitter;
				}
			}
		} else if ((pem->meta & GMETA_MOUSE_UP))
			break;
	}

	// Calibrate
	ginputCalibrateMouse(0);
	calibrated = TRUE;

	// Calibration used the whole screen - re-establish our title and Next and Previous Buttons
	gdispFillStringBox(0, 0, swidth, bHeight, "Touch Calibration", font, Green, White, justifyLeft);
	gdispFillStringBox(swidth-2*bWidth, 0, bWidth-1, bHeight, "Prev", font, Black, Gray, justifyCenter);
	gdispFillStringBox(swidth-1*bWidth, 0, bWidth  , bHeight, "Next", font, Black, Gray, justifyCenter);

	/*
	 * Test: Mouse coords
	 */

StepMouseCoords:
	gwinClear(ghc);
	gwinSetColor(ghc, Yellow);
	gwinPrintf(ghc, "\n4. Show Mouse Coordinates\n\n");

	gwinSetColor(ghc, White);
	if (deviceType == GEVENT_MOUSE)
		gwinPrintf(ghc, "Press and hold the mouse button.\n\n");
	else
		gwinPrintf(ghc, "Press and hold on the surface.\n\n");
	gwinPrintf(ghc, "Numbers will display in this window.\n"
			"Check the coordinates against where it should be on the screen.\n\n");

	gwinPrintf(ghc, "Press Next or Back to continue.\n");

	// For this test normal mouse movement events
	geventAttachSource(&gl, gs, GLISTEN_MOUSEDOWNMOVES|GLISTEN_MOUSEMETA);

	while(1) {
		// Always sleep a bit first to enable other events. We actually don't
		// mind missing events for this test.
		gfxSleepMilliseconds(100);
		pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE);
		if (pem->y < bHeight && pem->x >= swidth-2*bWidth) {
			if ((pem->meta & GMETA_MOUSE_UP)) {
				if (pem->x >= swidth-bWidth)
					break;
				goto StepCalibrate;
			}
		}
		if ((pem->current_buttons & GINPUT_MOUSE_BTN_LEFT))
			gwinPrintf(ghc, "%u:%u z=%u\n", pem->x, pem->y, pem->z);
	}

	// Reset to just changed movements.
	geventAttachSource(&gl, gs, GLISTEN_MOUSEDOWNMOVES|GLISTEN_MOUSEMETA);

	/*
	 * Test: Mouse movement jitter
	 */

StepJitter:
	gwinClear(ghc);
	gwinSetColor(ghc, Yellow);
	gwinPrintf(ghc, "\n4. GINPUT_MOUSE_MOVE_JITTER\n\n");

	gwinSetColor(ghc, White);
	if (deviceType == GEVENT_MOUSE)
		gwinPrintf(ghc, "Press and hold the mouse button and move around as if to draw.\n\n");
	else
		gwinPrintf(ghc, "Press firmly on the surface and move around as if to draw.\n\n");

	gwinPrintf(ghc, "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");
	gwinPrintf(ghc, "Press Next or Back to continue.\n\n");

	while(1) {
		pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE);
		if (pem->y < bHeight && pem->x >= swidth-2*bWidth) {
			if ((pem->meta & GMETA_MOUSE_UP)) {
				if (pem->x >= swidth-bWidth)
					break;
				goto StepMouseCoords;
			}
		}
		if ((pem->current_buttons & GINPUT_MOUSE_BTN_LEFT))
			gwinPrintf(ghc, ".");
	}

	/*
	 * Test: Polling frequency
	 */

StepPolling:
	gwinClear(ghc);
	gwinSetColor(ghc, Yellow);
	gwinPrintf(ghc, "\n5. GINPUT_MOUSE_POLL_PERIOD\n\n");

	gwinSetColor(ghc, White);
	gwinPrintf(ghc, "Press firmly on the surface (or press and hold the mouse button) and move around as if to draw.\n\n");
	gwinPrintf(ghc, "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");
	gwinPrintf(ghc, "Press Next or Back to continue.\n\n");

	while(1) {
		pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE);
		if (pem->y < bHeight && pem->x >= swidth-2*bWidth) {
			if ((pem->meta & GMETA_MOUSE_UP)) {
				if (pem->x >= swidth-bWidth)
					break;
				goto StepJitter;
			}
		}
		if ((pem->current_buttons & GINPUT_MOUSE_BTN_LEFT))
			gdispDrawPixel(pem->x, pem->y, Green);
	}
	
	/*
	 * Test: Click Jitter
	 */

StepClickJitter:
	gwinClear(ghc);
	gwinSetColor(ghc, Yellow);
	gwinPrintf(ghc, "\n6. GINPUT_MOUSE_MAX_CLICK_JITTER\n\n");

	gwinSetColor(ghc, White);
	gwinPrintf(ghc, "Press and release the touch surface to \"click\".\nTry both short and long presses.\n");
	gwinPrintf(ghc, "For a mouse click with the left and right buttons.\n\n");
	gwinPrintf(ghc, "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");
	gwinPrintf(ghc, "This is the last test but you can press Next or Back to continue.\n\n");

	while(1) {
		pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE);
		if (pem->y < bHeight && pem->x >= swidth-2*bWidth) {
			if ((pem->meta & GMETA_MOUSE_UP)) {
				if (pem->x >= swidth-bWidth)
					break;
				goto StepPolling;
			}
		}
		if ((pem->meta & GMETA_MOUSE_CLICK)) {
			gwinSetColor(ghc, Yellow);
			gwinPrintf(ghc, "-");
		}
		if ((pem->meta & GMETA_MOUSE_CXTCLICK)) {
			gwinSetColor(ghc, Red);
			gwinPrintf(ghc, "x");
		}
	}

	// Can't let this really exit
	goto StepDeviceType;
}
/*
 * 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 ;
	  	  }
  }
}
Example #12
0
File: main.c Project: bhdminh/uGFX
int main(void) {
	uint8_t i;
	font_t	font1, font2;

	/* initialize and clear the display */
	gfxInit();

	/* Set some fonts */
	font1 = gdispOpenFont("UI2");
	font2 = gdispOpenFont("DejaVu Sans 12");
	gwinSetDefaultFont(font1);

	/* create the three console windows */
	{
		GWindowInit		wi;

		gwinClearInit(&wi);
		wi.show = TRUE;
		wi.x = 0; wi.y = 0; wi.width = gdispGetWidth(); wi.height = gdispGetHeight()/2;
		GW1 = gwinConsoleCreate(0, &wi);
		wi.y = gdispGetHeight()/2; wi.width = gdispGetWidth()/2; wi.height = gdispGetHeight();
		GW2 = gwinConsoleCreate(0, &wi);
		wi.x = gdispGetWidth()/2; wi.height = gdispGetHeight();
		GW3 = gwinConsoleCreate(0, &wi);
	}

	/* Use a special font for GW1 */
	gwinSetFont(GW1, 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);

	/* Output some data on the first console */
	for(i = 0; i < 10; i++) {
		gwinPrintf(GW1, "Hello \033buGFX\033B!\n");
	}

	/* Output some data on the second console - Fast */
	for(i = 0; i < 32; i++) {
		gwinPrintf(GW2, "Message Nr.: \0331\033b%d\033B\033C\n", i+1);
	}

	/* Output some data on the third console - Slowly */
	for(i = 0; i < 32; i++) {
		gwinPrintf(GW3, "Message Nr.: \033u%d\033U\n", i+1);
		gfxSleepMilliseconds(500);
	}

	/* Make console 3 invisible and then visible again to demonstrate the history buffer */
	gwinPrintf(GW2, "Making red window \033uinvisible\033U\n");
	gwinSetVisible(GW3, FALSE);
	gfxSleepMilliseconds(1000);
	gwinPrintf(GW2, "Making red window \033uvisible\033U\n");
	gwinSetVisible(GW3, TRUE);
	gwinPrintf(GW3, "\033bI'm back!!!\033B\n", i+1);

	while(TRUE) {
		gfxSleepMilliseconds(500);
	}
}
Example #13
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;
}
Example #14
0
File: main.c Project: DaviWei/uGFX
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;
}
Example #15
0
File: main.c Project: bigzed/uGFX
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;
}
Example #16
0
int main(void) {
	GEventKeyboard *pk;
	unsigned		i;

	/* initialize and clear the display */
	gfxInit();

	/* Set a font */
	gwinSetDefaultFont(gdispOpenFont("*"));

	// We want to listen for keyboard events
	geventListenerInit(&gl);
	geventAttachSource(&gl, ginputGetKeyboard(0), GLISTEN_KEYTRANSITIONS|GLISTEN_KEYUP);

	/* create the console window */
	{
		GWindowInit		wi;

		gwinClearInit(&wi);
		wi.show = TRUE;
		wi.x = 0; wi.y = 0; wi.width = gdispGetWidth(); wi.height = gdispGetHeight();
		GW = gwinConsoleCreate(0, &wi);

		/* Set the fore- and background colors for the console */
		gwinSetColor(GW, Yellow);
		gwinSetBgColor(GW, Black);
		gwinClear(GW);
	}


	/* Say Hello */
	gwinPrintf(GW, "Keyboard Monitor...\n");

	while(1) {
		// Get an Event
		pk = (GEventKeyboard *)geventEventWait(&gl, TIME_INFINITE);

		if (pk->type != GEVENT_KEYBOARD)
			continue;

		gwinPrintf(GW, "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(GW, " Keys:");
			for (i = 0; i < pk->bytecount; i++)
				gwinPrintf(GW, " 0x%02X", (uint8_t)pk->c[i]);
			gwinPrintf(GW, " [");
			for (i = 0; i < pk->bytecount; i++)
				gwinPrintf(GW, "%c", pk->c[i] >= ' ' && pk->c[i] <= '~' ? pk->c[i] : ' ');
			gwinPrintf(GW, "]");
		}
		gwinPrintf(GW, "\n");
	}
}
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);
	*/
}