예제 #1
0
파일: tictactoe.c 프로젝트: Realtime-7/asf
/**
 * \brief Initializes the display with explanatory text for the buttons
 */
static void init_display(void)
{
	/* Draw buttons */
	gfx_mono_draw_circle(10, SQUARE3_Y, CIRCLE_SIZE, GFX_PIXEL_SET, GFX_WHOLE);
	gfx_mono_draw_circle((LCD_WIDTH_PIXELS / 3) + 10, SQUARE3_Y, CIRCLE_SIZE,
			GFX_PIXEL_SET, GFX_WHOLE);
	gfx_mono_draw_circle((LCD_WIDTH_PIXELS / 3) * 2 + 10, SQUARE3_Y,
			CIRCLE_SIZE, GFX_PIXEL_SET, GFX_WHOLE);

	/* Print text */
	gfx_mono_draw_string("LEFT", 0, SQUARE6_Y, &sysfont);
	gfx_mono_draw_string("OK", (LCD_WIDTH_PIXELS / 3), SQUARE6_Y, &sysfont);
	gfx_mono_draw_string("RIGHT", (LCD_WIDTH_PIXELS / 3) * 2, SQUARE6_Y,
			&sysfont);
}
예제 #2
0
파일: tictactoe.c 프로젝트: Realtime-7/asf
/**
 * \brief Draws a circle at selected point
 */
static void draw_circle(uint8_t square_num)
{
	uint8_t x = square_coord[square_num][0] + SQUARE_SIZE / 4;
	uint8_t y = square_coord[square_num][1] + SQUARE_SIZE / 4;
	/* Draw circle in selected square */
	gfx_mono_draw_circle(x + CIRCLE_SIZE, y + CIRCLE_SIZE, CIRCLE_SIZE,
			GFX_PIXEL_SET, GFX_WHOLE);
}
예제 #3
0
파일: example1.c 프로젝트: kerichsen/asf
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.
	}
}
예제 #4
0
파일: unit_tests.c 프로젝트: kerichsen/asf
/**
 * \internal
 * \brief Test drawing the outline of a circle on a page
 *
 * This test draws the outline of a circle and checks that this is done.
 *
 * \param test Current test case.
 */
static void run_draw_circle_outline_test(const struct test_case *test)
{
	uint8_t actual[GFX_MONO_LCD_WIDTH];
	uint8_t expected_page[GFX_MONO_LCD_WIDTH];
	uint8_t expected_empty[GFX_MONO_LCD_WIDTH];
	uint8_t page;

	// 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 the outlined circle
	set_buffer(expected_page, 0x00);
	expected_page[47] = 0x1C;
	expected_page[48] = 0x22;
	expected_page[49] = 0x41;
	expected_page[50] = 0x41;
	expected_page[51] = 0x41;
	expected_page[52] = 0x22;
	expected_page[53] = 0x1C;

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

	// Draw the outline of a circle with radius 3 and centre at position 50, 11
	gfx_mono_draw_circle(50, 11, 3, GFX_PIXEL_SET, GFX_WHOLE);

	// Get all pages from display and check that the circle 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_page),
					"Page %d with outlined circle not matching expected page",
					page);
		} else {
			test_assert_true(test, is_page_correct(actual, expected_empty),
					"Empty page %d not matching expected page", page);
		}
	}
}
예제 #5
0
/**
 * \brief Main entry of example application
 */
int main(void)
{
	/* The sensor_platform_init() function will initialize the system
	 * clock and sensor bus support in addition to configuring the
	 * XMEGA-A3BU and Sensor Xplained boards.
	 *
	 * Use gfx_mono_init() to initialize the monochrome graphical system
	 * API then write a splash screen after enabling the LCD display
	 * backlight and setting the contrast.
	 */
	sensor_platform_init();
	gfx_mono_init();

	gpio_set_pin_high(NHD_C12832A1Z_BACKLIGHT);
	st7565r_set_contrast(ST7565R_DISPLAY_CONTRAST_MIN);

	gfx_mono_draw_string(
			"Atmel\r\nSensors Xplained\r\nInertial Sensor Demo",
			0, 0, &sysfont);

	delay_ms(2000);

	clear_screen();

	gfx_mono_draw_string("Press button SW1", 1, 5, &sysfont);
	gfx_mono_draw_string("to change sensor", 1, 13, &sysfont);

	delay_ms(1000);

	screen_border();

	/* Attach descriptors to sensors on an Xplained add-on board. */
	sensor_t accelerometer;
	sensor_attach(&accelerometer, SENSOR_TYPE_ACCELEROMETER, 0, 0);

	sensor_t gyroscope;
	sensor_attach(&gyroscope, SENSOR_TYPE_GYROSCOPE, 0, 0);

	sensor_t compass;
	sensor_attach(&compass, SENSOR_TYPE_COMPASS, 0, 0);

	/* Configure operational parameters for select sensors. */
	sensor_set_range(&accelerometer, 2000 /* milli-g */);
	sensor_set_bandwidth(&accelerometer, 25 /* Hertz */);

	while (true) {
		/* Initialize a sensor data descriptor for scaled data. */
		static sensor_data_t sensor_data = {.scaled = true};

		do {
			/* Measure & show acceleration until button SW1 is
			 * pushed. */
			sensor_read(&accelerometer, SENSOR_READ_ACCELERATION, &sensor_data);
			draw_formatted_data(acceleration_format, &sensor_data);
		} while (!switch_pressed(SW1));

		do {
			/* Measure & show rotation until button SW1 is pushed. */
			sensor_read(&gyroscope, SENSOR_READ_ROTATION, &sensor_data);
			draw_formatted_data(rotation_format, &sensor_data);
		} while (!switch_pressed(SW1));

		static gfx_coord_t const ring_center_x = 112;
		static gfx_coord_t const ring_center_y = 16;
		static gfx_coord_t const ring_radius   = 15;

		/* Compass needle point x- and y-coordinate. */
		gfx_coord_t needle_x = ring_center_x;
		gfx_coord_t needle_y = ring_center_y;

		/* Draw the compass ring. */
		gfx_mono_draw_circle(ring_center_x, ring_center_y, ring_radius,
				GFX_PIXEL_SET, GFX_WHOLE);

		do {
			/* Measure & show magnetic heading until button SW1 is
			 * pushed.
			 */
			sensor_read(&compass, SENSOR_READ_HEADING, &sensor_data);

			/* Calculate compass needle coordinates on the display
			 * by using sin() & cos() to find the x- and y-coordinate of the
			 * needle point. Note that the 'direction' value is in degrees
			 * and must be converted to radians for the C-library math
			 * functions.
			 */
			int const needle_length = ring_radius - 3;
			double const direction  = radians(sensor_data.heading.direction);

			/* Erase the old compass needle. */
			gfx_mono_draw_line(ring_center_x, ring_center_y,
					needle_x, needle_y, GFX_PIXEL_CLR);

			needle_x = ring_center_x +
					(needle_length * sin(direction + M_PI));
			needle_y = ring_center_y +
					(needle_length * cos(direction + M_PI));

			/* Draw the new compass needle. */
			gfx_mono_draw_line(ring_center_x, ring_center_y,
					needle_x, needle_y, GFX_PIXEL_SET);

			draw_formatted_data(heading_format, &sensor_data);
		} while (!switch_pressed(SW1));

		/* Clear last compass needle and compass ring. */
		gfx_mono_draw_line(ring_center_x, ring_center_y,
				needle_x, needle_y, GFX_PIXEL_CLR);

		gfx_mono_draw_circle(ring_center_x, ring_center_y, ring_radius,
				GFX_PIXEL_CLR, GFX_WHOLE);

		screen_border();

		do {
			/* Measure & show temperature until button SW1 is pushed. */
			sensor_read(&gyroscope, SENSOR_READ_TEMPERATURE, &sensor_data);

			/* Arrange temperature data values in array with
			 * Fahrenheit and Celsius formats.
			 */
			int32_t const temp_deg_c = sensor_data.temperature.value;
			int32_t const temp_deg_f = CELSIUS_TO_FAHRENHEIT(temp_deg_c);

			sensor_data.value[0] = temp_deg_f;
			sensor_data.value[1] = temp_deg_c;

			draw_formatted_data(temperature_format, &sensor_data);
		} while (!switch_pressed(SW1));
	}
}