Ejemplo n.º 1
0
/**
 * \brief Highlights a square
 */
static void highlight_square(uint8_t square_num)
{
	static uint8_t last_square = 0;

	/* Clear current highlighting */
	uint8_t x = square_coord[last_square][0];
	uint8_t y = square_coord[last_square][1];
	gfx_mono_draw_rect(x + 1, y + 1, SQUARE_SIZE - 2, SQUARE_SIZE - 2,
			GFX_PIXEL_CLR);

	last_square = square_num;

	/* Highlight new square */
	x = square_coord[square_num][0];
	y = square_coord[square_num][1];
	gfx_mono_draw_rect(x + 1, y + 1, SQUARE_SIZE - 2, SQUARE_SIZE - 2,
			GFX_PIXEL_SET);
}
Ejemplo n.º 2
0
/**
 * \internal
 * \brief Test drawing the outline of a rectangle spanning two pages
 *
 * This test draws the outline of a rectangle spanning two pages and checks
 * that this is done.
 *
 * \param test Current test case.
 */
static void run_draw_rectangle_outline_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;
	uint8_t i;

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

	// Fill page buffer holding first part of rectangle
	set_buffer(expected_page1, 0x00);
	expected_page1[5] = 0xE0;
	for (i = 1; i < 99; i++) {
		expected_page1[i + 5] = 0x20;
	}
	expected_page1[99 + 5] = 0xE0;

	// Fill page buffer holding second part of rectangle
	set_buffer(expected_page2, 0x00);
	expected_page2[5] = 0x7F;
	for (i = 1; i < 99; i++) {
		expected_page2[i + 5] = 0x40;
	}
	expected_page2[99 + 5] = 0x7F;

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

	// Draw the outline of a 100x10 rectangle at position 5, 5
	gfx_mono_draw_rect(5, 5, 100, 10, GFX_PIXEL_SET);

	// Get all pages from display and check that the rectangle 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 rectangle not matching expected page",
					page);
		} else if (page == 1) {
			test_assert_true(test, is_page_correct(actual, expected_page2),
					"Page %d with rectangle 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.º 3
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.º 4
0
/**
 * \brief Main demo task
 *
 * This task keeps track of which screen the user has selected, which tasks
 * to resume/suspend to draw the selected screen, and also draws the menu bar.
 *
 * The menu bar shows which screens the user can select by clicking the
 * corresponding buttons on the OLED1 Xplained Pro:
 * - \ref graph_task() "graph" (selected at start-up)
 * - \ref terminal_task() "term."
 * - \ref about_task() "about"
 *
 * \param params Parameters for the task. (Not used.)
 */
static void main_task(void *params)
{
	bool graph_buffer_initialized = false;
	bool selection_changed = true;
	bool select_graph_buffer;
	enum menu_items current_selection = MENU_ITEM_GRAPH;
	gfx_coord_t x, y, display_y_offset;
	xTaskHandle temp_task_handle = NULL;

	for(;;) {
		// Show that task is executing
		oled1_set_led_state(&oled1, OLED1_LED3_ID, true);

		// Check buttons to see if user changed the selection
		if (oled1_get_button_state(&oled1, OLED1_BUTTON1_ID)
					&& (current_selection != MENU_ITEM_GRAPH)) {
			current_selection = MENU_ITEM_GRAPH;
			selection_changed = true;
		} else if (oled1_get_button_state(&oled1, OLED1_BUTTON2_ID)
					&& (current_selection != MENU_ITEM_TERMINAL)) {
			current_selection = MENU_ITEM_TERMINAL;
			selection_changed = true;
		} else if (oled1_get_button_state(&oled1, OLED1_BUTTON3_ID)
					&& (current_selection != MENU_ITEM_ABOUT)) {
			current_selection = MENU_ITEM_ABOUT;
			selection_changed = true;
		}

		// If selection changed, handle the selection
		if (selection_changed) {
			// Wait for and take the display semaphore before doing any changes.
			xSemaphoreTake(display_mutex, portMAX_DELAY);

			// We can now safely suspend the previously resumed task
			if (temp_task_handle) {
				vTaskSuspend(temp_task_handle);
				temp_task_handle = NULL;
			}

			// Select the new drawing task and corresponding display buffer
			switch (current_selection) {
			case MENU_ITEM_GRAPH:
				// Graph task runs continuously, no need to set task handle
				select_graph_buffer = true;
				break;

			case MENU_ITEM_TERMINAL:
				temp_task_handle = terminal_task_handle;
				select_graph_buffer = false;
				break;

			default:
			case MENU_ITEM_ABOUT:
				temp_task_handle = about_task_handle;
				select_graph_buffer = false;
			}

			// Select and initialize display buffer to use.
			display_y_offset = select_graph_buffer ? CANVAS_GRAPH_Y_OFFSET : 0;

			// Draw the menu bar (only needs to be done once for graph)
			if (!select_graph_buffer || !graph_buffer_initialized) {
				// Clear the selected display buffer first
				gfx_mono_draw_filled_rect(0, display_y_offset,
						GFX_MONO_LCD_WIDTH, GFX_MONO_LCD_HEIGHT / 2,
						GFX_PIXEL_CLR);

				// Draw menu lines, each item with height MENU_HEIGHT pixels
				y = display_y_offset + CANVAS_HEIGHT;
				gfx_mono_draw_horizontal_line(0, y, GFX_MONO_LCD_WIDTH,
						GFX_PIXEL_SET);

				x = MENU_ITEM_WIDTH;
				y++;

				for (uint8_t i = 0; i < (MENU_NUM_ITEMS - 1); i++) {
					gfx_mono_draw_vertical_line(x, y, MENU_HEIGHT,
							GFX_PIXEL_SET);
					x += 1 + MENU_ITEM_WIDTH;
				}

				// Highlight the current selection
				gfx_mono_draw_rect(current_selection * (1 + MENU_ITEM_WIDTH), y,
						MENU_ITEM_WIDTH, MENU_HEIGHT, GFX_PIXEL_SET);

				// Draw the menu item text
				x = (MENU_ITEM_WIDTH / 2) - ((5 * SYSFONT_WIDTH) / 2);
				y += (MENU_HEIGHT / 2) - (SYSFONT_HEIGHT / 2);

				for (uint8_t i = 0; i < MENU_NUM_ITEMS; i++) {
					gfx_mono_draw_string(menu_items_text[i], x, y, &sysfont);
					x += 1 + MENU_ITEM_WIDTH;
				}

				graph_buffer_initialized = true;
			}

			// Set display controller to output the new buffer
			ssd1306_set_display_start_line_address(display_y_offset);

			// We are done modifying the display, so give back the mutex
			xSemaphoreGive(display_mutex);

			selection_changed = false;

			// If a task handle was specified, resume it now
			if (temp_task_handle) {
				vTaskResume(temp_task_handle);
			}
		}

		// Show that task is done
		oled1_set_led_state(&oled1, OLED1_LED3_ID, false);

		vTaskDelay(MAIN_TASK_DELAY);
	}
}
Ejemplo n.º 5
0
void app_usb_task(void)
{
	static bool sw0_released = true;
	static bool usb_running = false;
	static bool cdc_running = false;
	static bool toggle = true;

	if (sw0_released && ioport_pin_is_low(GPIO_PUSH_BUTTON_0)) {
		/* A new press has been done */
		sw0_released = false;
		/* Switch USB state */
		if (usb_running) {
			udc_stop();
			gfx_mono_draw_filled_rect(DISPLAY_USB_STA_POS_X,
					DISPLAY_USB_STA_POS_Y,
					DISPLAY_USB_STA_SIZE_X,
					DISPLAY_USB_STA_SIZE_Y,
					GFX_PIXEL_CLR);
			app_microsd_start();
		} else {
			/* Stop FatFS on uSD card if enabled */
			app_microsd_stop();
			stdio_usb_init(); /* Start USB */
			gfx_mono_generic_put_bitmap(&bitmap_usb,
					DISPLAY_USB_STA_POS_X,
					DISPLAY_USB_STA_POS_Y);
		}

		usb_running = !usb_running;
		cdc_running = true;
	} else {
		/* Wait switch release */
		sw0_released = ioport_pin_is_high(GPIO_PUSH_BUTTON_0);
	}

	if (!usb_running) {
		return;
	}

	/* USB MSC task */
	while (udi_msc_process_trans()) {
	}

	if (app_usb_cdc_open && !cdc_running) {
		printf("\x0CSensor data logs:\r\n");
		cdc_running = true;
	}

	if (!app_usb_cdc_open && cdc_running) {
		cdc_running = false;
	}

	/* Toggle USB icon */
	if ((app_usb_cdc_open && app_usb_rec_toggle) ||
			(toggle && app_usb_rec_toggle)) {
		app_usb_rec_toggle = false;
		toggle = !toggle;
		gfx_mono_draw_rect(DISPLAY_USB_STACDC_POS_X,
				DISPLAY_USB_STACDC_POS_Y,
				DISPLAY_USB_STACDC_SIZE_X,
				DISPLAY_USB_STACDC_SIZE_Y,
				toggle ? GFX_PIXEL_SET : GFX_PIXEL_CLR);
	}
}
Ejemplo n.º 6
0
void temp_disp_init()
{
    /* TODO: Replaced for testing
    // Initiate a temperature sensor reading
    ntc_measure();
    */
    // Initiate a ADCB reading
    adcb_ch0_measure();
    adcb_ch1_measure();
    adcb_ch2_measure();
    adcb_ch3_measure();

    // Struct for holding the temperature scale background
    tempscale.type = GFX_MONO_BITMAP_RAM;
    tempscale.width = 6;
    tempscale.height = 32;
    tempscale.data.pixmap = tempscale_img;

    // Screen border
    gfx_mono_draw_rect(0, 0, 128, 32, GFX_PIXEL_SET);
    // Clear screen
    gfx_mono_draw_filled_rect(1, 1, 126, 30, GFX_PIXEL_CLR);

    // Paint thermometer on screen
    // gfx_mono_put_bitmap(&tempscale, 10, 0);	// TODO: Can be removed.

    /* TODO: Simply replaced for testing
    // wait for NTC data to ready
    while (!ntc_data_is_ready());
    // Read the temperature once the ADC reading is done
    temperature = ntc_get_temperature();
    */
    // Wait for ADCB date to ready
    while (!adcb_data_is_ready());
    temperature0 = adcb_chX_get_temperature(0);//adcb_ch0_get_raw_value();
    temperature1 = adcb_chX_get_temperature(1);
    temperature2 = adcb_chX_get_temperature(2);
    temperature3 = adcb_chX_get_temperature(3);


    // Convert the temperature into the thermometer scale
    /* temp_scale = -0.36 * temperature + 20.25;
    if (temp_scale <= 0) {
    	temp_scale = 0;
    }
    */

    // Draw the scale element on top of the background temperature image
    /*gfx_mono_draw_filled_rect(12, 3, 2, temp_scale,
    GFX_PIXEL_CLR);
    */

    /*snprintf(temperature_string, sizeof(temperature_string), "%3i C",
    temperature);

    // Draw the Celsius string
    gfx_mono_draw_string(temperature_string, 22, 13, &sysfont);
    */
    // ********************** START UPDATE SCREEN ************************

    snprintf(temp1_string, sizeof(temp1_string), "TMP1:%3iC",
             temperature0);

    snprintf(temp2_string, sizeof(temp2_string), "TMP2:%3iC",
             temperature1);

    snprintf(temp3_string, sizeof(temp3_string), "TMP3:%3iC",
             temperature2);

    snprintf(pressure_string, sizeof(pressure_string), "BAR:%3i",
             temperature3);

    // TODO: Set up variables and call methods for reading all the values
    // Draw the Celsius string
    gfx_mono_draw_string(temp1_string, 1, 5, &sysfont);	// Temp1
    gfx_mono_draw_string(temp2_string, 64, 5, &sysfont);	// Temp2
    gfx_mono_draw_string(temp3_string, 1, 20, &sysfont);	// Temp3
    gfx_mono_draw_string(pressure_string, 64, 20, &sysfont);	// Pressure
}