Ejemplo n.º 1
0
/**
 * \brief Lightsensor application
 *
 * This application will output the lightsensor value read by the ADC both as
 * a raw value and by drawing a bar that represent the amount of light hitting
 * the sensor.
 * The raw value is sampled 200 times and the average value is used.
 */
void lightsensor_application(void)
{
	struct keyboard_event input_key;
	char string_buf[10];
	uint32_t lightsensor_val = 0;
	uint8_t scaled;
	uint8_t iterations = 0;

	// Clear screen
	gfx_mono_draw_filled_rect(0, 0, 128, 32, GFX_PIXEL_CLR);

	// Put icons at the bottom of the screen indicating light intensity
	gfx_mono_put_bitmap(&bitmap_moon, 1, 24);    // ~1 lux
	gfx_mono_put_bitmap(&bitmap_cloud, 30, 24);  // ~200 lux
	gfx_mono_put_bitmap(&bitmap_indoor, 60, 24); // ~400 lux
	gfx_mono_put_bitmap(&bitmap_sun, 118, 24);   // ~850 lux

	// Draw static strings outside the loop
	gfx_mono_draw_string("Lightsensor", 0, 0, &sysfont);
	gfx_mono_draw_string("Raw value:", 0, 8, &sysfont);

	while (true) {
		// Start an ADC conversion of the lightsensor
		lightsensor_measure();

		while (!lightsensor_data_is_ready()) {
			// Wait until the conversion is complete
		}

		lightsensor_val += lightsensor_get_raw_value();

		// Let's average some samples to be outputted
		if (iterations++ >= LIGHTSENSOR_NUM_SAMPLES) {
			iterations = 0;
			lightsensor_val /= LIGHTSENSOR_NUM_SAMPLES;
			snprintf(string_buf, sizeof(string_buf), "%4ld", lightsensor_val);
			gfx_mono_draw_string(string_buf, 70, 8, &sysfont);
			// Scale down to LCD width for drawing bar
			scaled = lightsensor_val >> 4;

			// Graphic bar representing the light level
			gfx_mono_draw_filled_rect(0, 17,scaled, 7, GFX_PIXEL_SET);
			gfx_mono_draw_filled_rect(scaled, 17,128 - scaled, 7,
					GFX_PIXEL_CLR);

			lightsensor_val = 0;
		}

		// exit if the "back" button has been pressed and released
		keyboard_get_key_state(&input_key);
		if ((input_key.keycode == KEYBOARD_BACK) &&
				(input_key.type == KEYBOARD_RELEASE)) {
			break;
		}
	}
Ejemplo n.º 2
0
int main(void){

	struct gfx_mono_bitmap smiley;
	struct gfx_mono_bitmap smiley_flash;

	board_init();
	sysclk_init();

	/* Initialize GFX lib. Will configure the display controller and
	 * create a framebuffer in RAM if the controller lack two-way communication
	 */
	gfx_mono_init();

	// Setup bitmap struct for bitmap stored in RAM
	smiley.type = GFX_MONO_BITMAP_RAM;
	smiley.width = 8;
	smiley.height = 16;
	smiley.data.pixmap = smiley_data;

	// Setup bitmap for bitmap stored in FLASH
	smiley_flash.type = GFX_MONO_BITMAP_PROGMEM;
	smiley_flash.width = 8;
	smiley_flash.height = 16;
	smiley_flash.data.progmem = flash_bitmap;

	// Output bitmaps to display
	gfx_mono_put_bitmap(&smiley, 50, 0);
	gfx_mono_put_bitmap(&smiley_flash, 0, 0);

	//Draw  horizontal an vertical lines with length 128 and 32 pixels
	gfx_mono_draw_vertical_line(1, 0, 32, GFX_PIXEL_SET);
	gfx_mono_draw_horizontal_line(0, 2, 128, GFX_PIXEL_SET);

	// Draw a line from the top-left corner to the bottom right corner
	gfx_mono_draw_line(0, 0, 127, 31, GFX_PIXEL_SET);

	// Draw a rectangle with upper left corner at x=20,y=10 - width=height=10px
	gfx_mono_draw_rect(20, 10, 10, 10,GFX_PIXEL_SET);

	// Draw a 10x10 filled rectangle at x=10,y=10
	gfx_mono_draw_filled_rect(10, 10, 10, 10, GFX_PIXEL_SET);

	// Draw a whole circle at x=50,y=16 with radios=8 and all octants drawn
	gfx_mono_draw_circle(50, 16, 8, GFX_PIXEL_SET,GFX_WHOLE);

	// Draw a filled circle with all quadrant drawn
	gfx_mono_draw_filled_circle(80, 16, 10, GFX_PIXEL_SET, GFX_WHOLE);

	while(true) {
	// This while left intentionally blank to halt execution.
	}
}
Ejemplo n.º 3
0
/**
 * \brief Draw or delete indicator arrow in front of spinner
 *
 * \param *spinner initialized gfx_mono_spinctrl struct
 * \param draw     true on draw, false on delete
 */
static void gfx_mono_spinctrl_draw_indicator(struct gfx_mono_spinctrl *spinner,
        bool draw)
{
    if (draw) {
        gfx_mono_put_bitmap(&gfx_mono_spinctrl_bitmap_indicator, 0,
                            spinner->y);
    } else {
        gfx_mono_draw_filled_rect(0, spinner->y,
                                  GFX_MONO_SPINCTRL_INDICATOR_WIDTH,
                                  GFX_MONO_SPINCTRL_INDICATOR_HEIGHT,
                                  GFX_PIXEL_CLR);
    }
}
Ejemplo n.º 4
0
/**
 * \brief Draw OK button at bottom of screen
 *
 * This function draws an OK button at the bottom of the screen. It will
 * also draw an indicator arrow in front of the button if the indicator bool
 * is true. If the draw bool is false, the OK button will be deleted, and if
 * the indicator bool is false, the indicator will be deleted.
 *
 * \param draw       true on draw, false on delete
 * \param indicator  true on draw indicator, false on delete
 */
static void gfx_mono_spinctrl_draw_button(bool draw, bool indicator)
{
    uint8_t width;
    uint8_t height;
    uint8_t offset;
    char string_buf[22];

    /* Clear bottom line */
    gfx_mono_draw_filled_rect(0,
                              (SYSFONT_HEIGHT + 1) *
                              GFX_MONO_SPINCTRL_MAX_ELEMENTS_IN_SPINCOLLECTION,
                              GFX_MONO_LCD_WIDTH, SYSFONT_HEIGHT, GFX_PIXEL_CLR);

    snprintf(string_buf, sizeof(string_buf), "OK");
    gfx_mono_get_string_bounding_box(string_buf, &sysfont, &width, &height);
    offset = (GFX_MONO_LCD_WIDTH - width) / 2;

    if (draw) {
        /* Draw OK button in the middle of the last line */
        gfx_mono_draw_string(string_buf, offset,
                             (SYSFONT_HEIGHT + 1) *
                             GFX_MONO_SPINCTRL_MAX_ELEMENTS_IN_SPINCOLLECTION,
                             &sysfont);
        if (indicator) {
            /* Draw indicator arrow in front of button */
            gfx_mono_put_bitmap(&gfx_mono_spinctrl_bitmap_indicator,
                                offset - GFX_MONO_SPINCTRL_INDICATOR_WIDTH,
                                (SYSFONT_HEIGHT + 1) *
                                GFX_MONO_SPINCTRL_MAX_ELEMENTS_IN_SPINCOLLECTION);
        } else {
            /* Delete indicator */
            gfx_mono_draw_filled_rect(offset -
                                      GFX_MONO_SPINCTRL_INDICATOR_WIDTH,
                                      (SYSFONT_HEIGHT + 1) *
                                      GFX_MONO_SPINCTRL_MAX_ELEMENTS_IN_SPINCOLLECTION,
                                      GFX_MONO_SPINCTRL_INDICATOR_WIDTH,
                                      GFX_MONO_SPINCTRL_INDICATOR_HEIGHT,
                                      GFX_PIXEL_CLR);
        }
    } else {
        /* Delete OK button */
        gfx_mono_draw_filled_rect(
            offset - GFX_MONO_SPINCTRL_INDICATOR_WIDTH,
            (SYSFONT_HEIGHT + 1) *
            GFX_MONO_SPINCTRL_MAX_ELEMENTS_IN_SPINCOLLECTION, 20,
            SYSFONT_HEIGHT, GFX_PIXEL_CLR);
    }
}
Ejemplo n.º 5
0
/**
 * \brief Draw menu strings and an icon by the current selection.
 *
 * \param menu     a menu struct with menu settings
 * \param redraw   clear screen before drawing menu
 */
static void menu_draw(struct gfx_mono_menu *menu, bool redraw)
{
	static bool redraw_state;
	uint8_t i;
	uint8_t line = 1;
	uint8_t menu_page = menu->current_selection /
			GFX_MONO_MENU_ELEMENTS_PER_SCREEN;

	if (menu->current_page != menu_page || redraw == true) {
		/* clear screen if we have changed the page or menu and prepare
		 * redraw */
		gfx_mono_draw_filled_rect(0, SYSFONT_LINESPACING,
				GFX_MONO_LCD_WIDTH,
				GFX_MONO_LCD_HEIGHT - SYSFONT_LINESPACING,
				GFX_PIXEL_CLR);
		redraw_state = true;
	}

	menu->current_page = menu_page;

	/* Clear old indicator icon */
	gfx_mono_draw_filled_rect(0, SYSFONT_LINESPACING,
			GFX_MONO_MENU_INDICATOR_WIDTH, GFX_MONO_LCD_HEIGHT -
			SYSFONT_LINESPACING, GFX_PIXEL_CLR);

	/* Put indicator icon on current selection */
	gfx_mono_put_bitmap(&menu_bitmap_indicator, 0,
			SYSFONT_LINESPACING * ((menu->current_selection %
			GFX_MONO_MENU_ELEMENTS_PER_SCREEN) + 1));

	/* Print visible options if page or menu has changed */
	if (redraw_state == true) {
		for (i = menu_page * GFX_MONO_MENU_ELEMENTS_PER_SCREEN;
				i < menu_page *
				GFX_MONO_MENU_ELEMENTS_PER_SCREEN +
				GFX_MONO_MENU_ELEMENTS_PER_SCREEN &&
				i < menu->num_elements; i++) {
			gfx_mono_draw_progmem_string(
					(char PROGMEM_PTR_T)menu->strings[i],
					GFX_MONO_MENU_INDICATOR_WIDTH + 1,
					line * SYSFONT_LINESPACING, &sysfont);
			line++;
		}
		redraw_state = false;
	}
}
Ejemplo n.º 6
0
/**
 * \internal
 * \brief Test drawing a bitmap stored in RAM
 *
 * This test draws a bitmap to position x = 50, y = 5 and checks that
 * it is aligned with display pages and that it is drawn correctly.
 *
 * \param test Current test case.
 */
static void run_draw_ram_bitmap_test(const struct test_case *test)
{
	uint8_t actual[GFX_MONO_LCD_WIDTH];
	uint8_t expected_page1[GFX_MONO_LCD_WIDTH];
	uint8_t expected_page2[GFX_MONO_LCD_WIDTH];
	uint8_t expected_empty[GFX_MONO_LCD_WIDTH];
	uint8_t page;
	struct gfx_mono_bitmap smiley;

	// Setup bitmap struct for bitmap stored in RAM
	smiley.type = GFX_MONO_BITMAP_RAM;
	smiley.width = 8;
	smiley.height = 16;
	smiley.data.pixmap = smiley_data;

	// Clear entire display
	gfx_mono_draw_filled_rect(0, 0, GFX_MONO_LCD_WIDTH, GFX_MONO_LCD_HEIGHT,
			GFX_PIXEL_CLR);

	// Fill first page buffer holding smileys
	set_buffer(expected_page1, 0x00);
	expected_page1[50] = 0x3C;
	expected_page1[51] = 0x42;
	expected_page1[52] = 0x95;
	expected_page1[53] = 0xA1;
	expected_page1[54] = 0xA1;
	expected_page1[55] = 0x95;
	expected_page1[56] = 0x42;
	expected_page1[57] = 0x3C;

	// Fill second page buffer holding smileys
	set_buffer(expected_page2, 0x00);
	expected_page2[50] = 0x3C;
	expected_page2[51] = 0x42;
	expected_page2[52] = 0x95;
	expected_page2[53] = 0xA1;
	expected_page2[54] = 0xA1;
	expected_page2[55] = 0x95;
	expected_page2[56] = 0x42;
	expected_page2[57] = 0x3C;

	// Fill empty page buffer
	set_buffer(expected_empty, 0x00);

	// Output bitmap
	gfx_mono_put_bitmap(&smiley, 50, 5);

	// Get all pages from display and check that the bitmap is drawn
	for (page = 0; page < GFX_MONO_LCD_PAGES; page++) {
		gfx_mono_get_page(actual, page, 0, GFX_MONO_LCD_WIDTH);
		if (page == 0) {
			test_assert_true(test, is_page_correct(actual, expected_page1),
					"Page %d with smileys not matching expected page", page);
		} else if (page == 1) {
			test_assert_true(test, is_page_correct(actual, expected_page2),
					"Page %d with smileys not matching expected page", page);
		} else {
			test_assert_true(test, is_page_correct(actual, expected_empty),
					"Empty page %d not matching expected page", page);
		}
	}
}
Ejemplo n.º 7
0
/**
 * \internal
 * \brief Test drawing a bitmap stored in FLASH
 *
 * This test draws a bitmap to position x = 60, y = 9 and checks that
 * it is aligned with display pages and that it is drawn correctly.
 *
 * \param test Current test case.
 */
static void run_draw_flash_bitmap_test(const struct test_case *test)
{
	uint8_t actual[GFX_MONO_LCD_WIDTH];
	uint8_t expected_page1[GFX_MONO_LCD_WIDTH];
	uint8_t expected_page2[GFX_MONO_LCD_WIDTH];
	uint8_t expected_empty[GFX_MONO_LCD_WIDTH];
	uint8_t page;
	struct gfx_mono_bitmap smiley_flash;

	// Setup bitmap for bitmap stored in FLASH
	smiley_flash.type = GFX_MONO_BITMAP_PROGMEM;
	smiley_flash.width = 8;
	smiley_flash.height = 16;
	smiley_flash.data.progmem = flash_bitmap;

	// Clear entire display
	gfx_mono_draw_filled_rect(0, 0, GFX_MONO_LCD_WIDTH, GFX_MONO_LCD_HEIGHT,
			GFX_PIXEL_CLR);

	// Fill first page buffer holding smileys
	set_buffer(expected_page1, 0x00);
	expected_page1[60] = 0x3C;
	expected_page1[61] = 0x42;
	expected_page1[62] = 0x95;
	expected_page1[63] = 0xA1;
	expected_page1[64] = 0xA1;
	expected_page1[65] = 0x95;
	expected_page1[66] = 0x42;
	expected_page1[67] = 0x3C;

	// Fill second page buffer holding smileys
	set_buffer(expected_page2, 0x00);
	expected_page2[60] = 0x3C;
	expected_page2[61] = 0x42;
	expected_page2[62] = 0x95;
	expected_page2[63] = 0xA1;
	expected_page2[64] = 0xA1;
	expected_page2[65] = 0x95;
	expected_page2[66] = 0x42;
	expected_page2[67] = 0x3C;


	// Fill empty page buffer
	set_buffer(expected_empty, 0x00);

	// Output bitmap
	gfx_mono_put_bitmap(&smiley_flash, 60, 9);

	// Get all pages from display and check that the bitmap is drawn
	for (page = 0; page < GFX_MONO_LCD_PAGES; page++) {
		gfx_mono_get_page(actual, page, 0, GFX_MONO_LCD_WIDTH);
		if (page == 1) {
			test_assert_true(test, is_page_correct(actual, expected_page1),
					"Page %d with smileys not matching expected page",
					page);
		} else if (page == 2) {
			test_assert_true(test, is_page_correct(actual, expected_page2),
					"Page %d with smileys not matching expected page",
					page);
		} else {
			test_assert_true(test, is_page_correct(actual, expected_empty),
					"Empty page %d not matching expected page", page);
		}
	}
}