예제 #1
0
파일: bike.c 프로젝트: skrutt/longboard
void init_platform() {
	button_init(&select_btn, PIN_PA14);
	button_init(&down_btn, PIN_PA15);
	device.speed = 255;
	device.inclination = 255;
	
	gfx_mono_init();
	ssd1306_init();
	configure_tc_cadence();
	cadence_sensor_init();
	
	
	// The page address to write to
	uint8_t page_address = 0;
	// The column address, or the X pixel.
	uint8_t column_address = 0;
	
	ssd1306_clear_buffer();
	gfx_mono_draw_string("Accelerometer",1, 18, &sysfont);
	gfx_mono_draw_string("Setup",37, 32, &sysfont);
	ssd1306_write_display();
	
	gfx_mono_active_menu = SPEED_VIEW;
	
}
예제 #2
0
파일: tictactoe.c 프로젝트: Realtime-7/asf
/**
 * \brief Draws the Tic-tac-toe board on the display
 *
 */
static void setup_board(void)
{
	/* Clear screen */
	gfx_mono_draw_filled_rect(0, 0, LCD_WIDTH_PIXELS, LCD_HEIGHT_PIXELS,
			GFX_PIXEL_CLR);

	/* Draw vertical lines */
	gfx_mono_draw_line(SQUARE_SIZE, 0, SQUARE_SIZE, SQUARE_SIZE * 3,
			GFX_PIXEL_SET);
	gfx_mono_draw_line(SQUARE_SIZE * 2, 0, SQUARE_SIZE * 2, SQUARE_SIZE * 3,
			GFX_PIXEL_SET);

	/* Draw horizontal lines */
	gfx_mono_draw_line(0, SQUARE_SIZE, SQUARE_SIZE*3, SQUARE_SIZE,
			GFX_PIXEL_SET);
	gfx_mono_draw_line(0, SQUARE_SIZE * 2, SQUARE_SIZE * 3, SQUARE_SIZE * 2,
			GFX_PIXEL_SET);

	/* Print number of games */
	snprintf(win_string, STRING_LENGTH, "Games: %d", games);
	gfx_mono_draw_string(win_string, STRING_X, SQUARE0_Y, &sysfont);

	/* Print number of wins */
	snprintf(win_string, STRING_LENGTH, "Wins: %d", wins);
	gfx_mono_draw_string(win_string, STRING_X, SQUARE3_Y, &sysfont);

	/* Clear occupied squares */
	for (uint8_t i = 0; i < 3; i++) {
		for (uint8_t j = 0; j < 3; j++) {
			occupied_squares[i][j] = NONE;
		}
	}
}
예제 #3
0
/**
 * \brief Show button names on display
 */
void button_splash(void)
{
	struct keyboard_event input;

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

	gfx_mono_draw_filled_circle(10, 10, 4, GFX_PIXEL_SET, GFX_WHOLE);
	gfx_mono_draw_filled_circle(10, 22, 4, GFX_PIXEL_SET, GFX_WHOLE);
	gfx_mono_draw_filled_circle(117, 10, 4, GFX_PIXEL_SET, GFX_WHOLE);
	gfx_mono_draw_filled_circle(117, 22, 4, GFX_PIXEL_SET, GFX_WHOLE);

	gfx_mono_draw_string("Up", 90, 8, &sysfont);
	gfx_mono_draw_string("Down", 80, 20, &sysfont);
	gfx_mono_draw_string("Enter", 20, 8, &sysfont);
	gfx_mono_draw_string("Back", 20, 20, &sysfont);

	// Any key will exit the loop
	while (true) {
		keyboard_get_key_state(&input);
		if (input.type == KEYBOARD_RELEASE) {
			break;
		}
	}
}
예제 #4
0
void start_game(void)
{
	char* string1 = "Plant Shooter";
	char* string2 = "ESAT vs Zombies";
	uint8_t string_length = 0;

	gfx_mono_draw_string(string1, (128-strlen(string1)*6)/2, 12, &sysfont);
	string_length = strlen(string1)*6;

	led_start();

	gfx_mono_draw_filled_rect((128-string_length)/2, 12, string_length, 8, GFX_PIXEL_CLR);
	gfx_mono_draw_string(string2, (128-strlen(string2)*6)/2, 12, &sysfont);
	string_length = strlen(string2)*6;

	led_start();

	gfx_mono_draw_filled_rect((128-string_length)/2, 12, string_length, 8, GFX_PIXEL_CLR);
	gfx_mono_draw_string(string1, (128-strlen(string1)*6)/2, 7, &sysfont);
	gfx_mono_draw_string(string2, (128-strlen(string2)*6)/2, 18, &sysfont);
	
	led_start();
	
	gfx_mono_draw_filled_rect(0, 0, 128, 32, GFX_PIXEL_CLR);
	
	state = 2;
}
예제 #5
0
/**
 * \brief Main entry of example application
 */
int main(void)
{
	/**
	 * Starts off by initializing the system clock before configuring the
	 * board and the monochrome graphical system.
	 */
	board_init();
	sysclk_init();
	gfx_mono_init();

	/**
	 * After initialization the example will write the "Hello
	 * world!\\r\\nI'm board..." string to position 0, 0 on the display.
	 * Use the system font sysfont. Afterwards the system busy waits
	 * forever in a while true loop.
	 */
#if BOARD == XMEGA_A3BU_XPLAINED
	gfx_mono_draw_string("My name is\r\nXMEGA-A3BU Xplained!\r\nAnd I'm board...",
			0, 0, &sysfont);
#elif BOARD == XMEGA_C3_XPLAINED
	gfx_mono_draw_string("My name is\r\nXMEGA-C3 Xplained!\r\nAnd I'm board...",
			0, 0, &sysfont);
#else
#  error Unknow board.
#endif

	while (true) {
		/* Intentionally left empty. */
	}
}
예제 #6
0
/**
 * \brief Main entry of example application
 */
int main(void)
{
	/**
	 * Starts off by initializing the system clock before configuring the
	 * board and the monochrome graphical system.
	 */
	system_init();
	gfx_mono_init();

	uint8_t start_line_address = 0;
	uint8_t scroll = 0;
	uint32_t line = 0;

	/**
	 * After initialization the example will write the Star Wars opening scrolling text.
	 * Use the system font sysfont. Afterwards the text will be scrolled forever.
	 */

	while (true) {
		if (++start_line_address%8 == 0) {
			scroll = 1;
			gfx_mono_draw_string(string[line%LINES],0, ((line)%8)*8, &sysfont);
			line++;
		} else if (start_line_address % 7 != 0) {
			delay_ms(100);
		}

		if ( scroll != 0 ) {
			ssd1306_set_display_start_line_address(start_line_address-8);
		} else {
			gfx_mono_draw_string(string[line%LINES],0, ((line)%8)*8, &sysfont);
			line++;
		}
	}
}
예제 #7
0
파일: tictactoe.c 프로젝트: Realtime-7/asf
/**
 * \brief Main entry of example application
 */
int main(void)
{
	/* Variable to store the last winner */
	uint8_t winner;

	system_init();
	delay_init();
	gfx_mono_init();

	init_buttons();
	init_display();

	/* Start game */
	while (true) {
		winner = 0;
		/* Wait for button interaction */
		while (get_button() == BUTTON_NONE) {
		}
		/* Draw empty board */
		setup_board();

		/* Start playing */
		for (int i = 0; i < 5; i++) {
			/* User's turn */
			user_turn();

			/* Check if the game is over */
			winner = we_have_a_winner();
			if (winner || i == 4) {
				break;
			}

			/* Add a delay for the opponent to "think" */
			delay_ms(500);
			/* Opponent's turn */
			opponent_turn();

			/* Check if the game is over */
			winner = we_have_a_winner();
			if (winner) {
				break;
			}
		}

		/* Game over, print winner and get ready for restart */
		if (winner == 1) {
			/* User won */
			gfx_mono_draw_string("You won!", STRING_X, 0, &sysfont);
			wins++;
		} else if (winner == 2) {
			gfx_mono_draw_string("You lost!", STRING_X, 0, &sysfont);
		} else {
			gfx_mono_draw_string("No winner!", STRING_X, 0, &sysfont);
		}

		gfx_mono_draw_string("Press a button", STRING_X, SQUARE3_Y, &sysfont);
		games++;
	}
}
예제 #8
0
파일: bike.c 프로젝트: skrutt/longboard
void display_adc_calibration_msg(unsigned char axis) {
	unsigned char axisText[6];
	sprintf(axisText, "%c axis", axis);
	ssd1306_clear_buffer();
	gfx_mono_draw_string("Calibrate", 18, 11, &sysfont);
	gfx_mono_draw_string(axisText ,37, 32, &sysfont);
	ssd1306_write_display();
}
예제 #9
0
/**
 * \brief Main application routine
 *  - Initializes the board and LCD display
 *  - Initialize ADC ,to read ADC offset and configure for oversampling
 *  - If number of sample Reached to  total number of oversample required,
 *    call function to start process on oversampled ADC readings
 */
int main( void )
{
	/*
	 * Initialize basic features for the AVR XMEGA family.
	 *  - PMIC is needed to enable all interrupt levels.
	 *  - Board init for setting up GPIO and board specific features.
	 *  - Sysclk init for configuring clock speed and turning off unused
	 *    peripherals.
	 *  - Sleepmgr init for setting up the basics for the sleep manager,
	 */

	board_init();
	sysclk_init();
	pmic_init();
	sleepmgr_init();

	/* Initialize ST7565R controller and LCD display */
	gfx_mono_init();

	/* Display headings on LCD for oversampled result */
	gfx_mono_draw_string("Oversampled", 0, 0, &sysfont);

	/* Display headings on LCD for normal result */
	gfx_mono_draw_string("Normal", 80, 0, &sysfont);

	/* Initialize ADC ,to read ADC offset and configure ADC for oversampling
	**/
	init_adc();

	/* Enable global interrupt */
	cpu_irq_enable();

	/* Switch ON LCD back light */
	ioport_set_pin_high(NHD_C12832A1Z_BACKLIGHT);

	/* Set LCD contrast */
	st7565r_set_contrast(ST7565R_DISPLAY_CONTRAST_MIN);

	/* Continuous Execution Loop */
	while (1) {
		/*
		 * Check if number of sample reached to  total Number of
		 * oversample required by checking status of
		 * adc_oversampled_flag
		 */
		if (adc_oversampled_flag == true) {
			/* Reset the adc_oversampled_flag */
			adc_oversampled_flag = false;

			/* Process all received ADC samples and calculate analog
			 * input */
			adc_oversampled();
		}
	}
}
예제 #10
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;
		}
	}
예제 #11
0
/**
 * \brief Print error message depending on the value of classb_error.
 */
void oven_classb_display_error(void)
{
	char *error_string;

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

	/* Get the error message based on the error value */
	switch (classb_error) {
	case CLASSB_ERROR_NONE:
		error_string = classb_error_messages[ERR_NONE];
		break;

	case CLASSB_ERROR_WDT:
		error_string = classb_error_messages[ERR_WDT];
		break;

	case CLASSB_ERROR_ANALOG:
		error_string = classb_error_messages[ERR_AIO];
		break;

	case CLASSB_ERROR_CRC:
		error_string = classb_error_messages[ERR_CRC];
		break;

	case CLASSB_ERROR_FREQ:
		error_string = classb_error_messages[ERR_FRQ];
		break;

	case CLASSB_ERROR_INT:
		error_string = classb_error_messages[ERR_INT];
		break;

	case CLASSB_ERROR_CPU:
		error_string = classb_error_messages[ERR_CPU];
		break;

	case CLASSB_ERROR_SRAM:
		error_string = classb_error_messages[ERR_SRAM];
		break;

	case CLASSB_ERROR_OTHER:
		error_string = classb_error_messages[ERR_TMP];
		break;

	default:
		error_string = classb_error_messages[ERR_OTHER];
	}

	/* Print the error message on display */
	gfx_mono_draw_string("Error detected in", 0, 8, &sysfont);
	gfx_mono_draw_string(error_string, 0, 16, &sysfont);
}
예제 #12
0
파일: main.c 프로젝트: Tjalling7/asf
/**
 * \brief Shows on display an explanation of how to use the demonstration
 * SW1 pressed skips this explanation.
 */
static void main_introduction(void)
{
    LED_On(LED3_GPIO);  /* Keep power LED on */

    /* Display Atmel logo */
    if (!main_introduction_is_exist()) {
        gfx_mono_generic_put_bitmap(&bitmap_atmel, 10, 0);
        gfx_mono_draw_string(DISPLAY_INTRO_MSG_EXIT,
                             0, 25, &sysfont);
    }

    main_introduction_delay(DISPLAY_INTRO_ATMEL_DELAY);
    /* Display message */
    if (!main_introduction_is_exist()) {
        gfx_mono_init();
        gfx_mono_draw_string(DISPLAY_INTRO_MSG_A,
                             0, 10 * 0, &sysfont);
        gfx_mono_draw_string(DISPLAY_INTRO_MSG_B,
                             0, 10 * 1, &sysfont);
        gfx_mono_draw_string(DISPLAY_INTRO_MSG_C,
                             0, 10 * 2, &sysfont);
    }

    main_introduction_delay(DISPLAY_INTRO_HELP_DELAY);
    /* Display help */
    if (!main_introduction_is_exist()) {
        gfx_mono_init();
        gfx_mono_draw_string(DISPLAY_INTRO_HELP_A,
                             0, 10 * 0, &sysfont);
        gfx_mono_draw_string(DISPLAY_INTRO_HELP_B,
                             0, 10 * 1, &sysfont);
        gfx_mono_draw_string(DISPLAY_INTRO_HELP_C,
                             0, 10 * 2, &sysfont);
    }

    main_introduction_delay(DISPLAY_INTRO_HELP_DELAY);
    /* Display help */
    if (!main_introduction_is_exist()) {
        gfx_mono_init();
        gfx_mono_draw_string(DISPLAY_INTRO_INF_A,
                             0, 10 * 0, &sysfont);
        gfx_mono_draw_string(DISPLAY_INTRO_INF_B,
                             0, 10 * 1, &sysfont);
        gfx_mono_draw_string(DISPLAY_INTRO_INF_C,
                             0, 10 * 2, &sysfont);
    }

    main_introduction_delay(DISPLAY_INTRO_HELP_DELAY);

    /* Clean display */
    gfx_mono_init();
}
예제 #13
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);
}
예제 #14
0
/**
 * \brief Callback function for ADC interrupts
 *
 * \param adc Pointer to ADC module.
 * \param ch_mask ADC channel mask.
 * \param result Conversion result from ADC channel.
 */
static void adc_handler(ADC_t *adc, uint8_t ch_mask, adc_result_t result)
{
	int32_t temperature;
	char out_str[OUTPUT_STR_SIZE];

	/* Compute current temperature in Celsius, based on linearization
	 * of the temperature sensor adc data.
	 */

	if (result > 697) {
		temperature = (int8_t)((-0.0295 * result) + 40.5);
	} if (result > 420) {
		temperature = (int8_t)((-0.0474 * result) + 53.3);
	} else {
		temperature = (int8_t)((-0.0777 * result) + 65.1);
	}

	last_temperature = temperature;

	// Write temperature to display
	snprintf(out_str, OUTPUT_STR_SIZE, "Temperature: %4d C", last_temperature);
	gfx_mono_draw_string(out_str, 0, 0, &sysfont);

	// Start next conversion.
	adc_start_conversion(adc, ch_mask);
}
예제 #15
0
/*
Function to draw the menu of the song that is currently being played
*/
void song_menu(uint8_t song_choice)
{	
	gfx_mono_draw_filled_rect(0, 0, 128, 32, GFX_PIXEL_CLR); //Clear the screen
	gfx_mono_draw_string("Currently Playing: ", 1, 2, &sysfont);
	gfx_mono_draw_progmem_string((char PROGMEM_PTR_T)main_menu_strings[song_choice], 1, 10, &sysfont);

}
예제 #16
0
void app_cpu_load_init(void)
{
	/* Reset counters */
	app_cpu_load_time_active = 0;
	app_cpu_load_time_sleep = 0;
	/* Start Timer counter used to monitor CPU timing */
	tc45_enable(&TCC4);
	tc45_write_clock_source(&TCC4, TC45_CLKSEL_DIV256_gc); /* 24MHz / 256 */
	tc45_set_direction(&TCC4, TC45_UP);
	/* Display static background */
	gfx_mono_draw_string(DISPLAY_CPU_LOAD_TEXT,
			DISPLAY_CPU_LOAD_TEXT_POS_X,
			DISPLAY_CPU_LOAD_TEXT_POS_Y,
			&sysfont);
	gfx_mono_draw_filled_rect(
			DISPLAY_CPU_LOAD_PROBAR_START_POS_X,
			DISPLAY_CPU_LOAD_PROBAR_START_POS_Y,
			DISPLAY_CPU_LOAD_PROBAR_START_SIZE_X,
			DISPLAY_CPU_LOAD_PROBAR_START_SIZE_Y,
			GFX_PIXEL_SET);
	gfx_mono_draw_filled_rect(
			DISPLAY_CPU_LOAD_PROBAR_STOP_POS_X,
			DISPLAY_CPU_LOAD_PROBAR_STOP_POS_Y,
			DISPLAY_CPU_LOAD_PROBAR_STOP_SIZE_X,
			DISPLAY_CPU_LOAD_PROBAR_STOP_SIZE_Y,
			GFX_PIXEL_SET);
}
예제 #17
0
int main (void)
{
	board_init();	//Board definition and selection
	sysclk_init();	//System clock init
	
	usart_init_rs232(USART_SERIAL_RFID, &usart_options_RFID);	//UART init
	usart_init_rs232(USART_SERIAL_Monitor, &usart_options_Monitor);
	
	gfx_mono_init();	//LCD init
	PORTE.OUTSET=PIN4_bm;	//LCD Back light on
	
	//RTC Init
	sysclk_enable_module(SYSCLK_PORT_GEN, SYSCLK_RTC);
	while (RTC32.SYNCCTRL & RTC32_SYNCBUSY_bm);
	if (rtc_vbat_system_check(false) != VBAT_STATUS_OK)
		rtc_init();
	PORTE.DIRCLR=PIN5_bm;
	
	while(1)
	{
		if(Receive())
		{
			card_no=Check();
			if(card_no)
			{
				PORTR.OUTCLR=PIN0_bm;
				gfx_mono_draw_string("Card Detected",0,0,&sysfont);
				gfx_mono_draw_string("Welcome",0,10,&sysfont);
				gfx_mono_draw_string(names[card_no-1],55,10,&sysfont);
				rtc_timestamp=rtc_get_time();
				calendar_timestamp_to_date_tz(rtc_timestamp,5,30,&get_date);
				gfx_mono_draw_string(display_time(get_date,arr),0,20,&sysfont);
				delay_s(1);
				gfx_mono_init();
				PORTR.OUTSET=PIN0_bm;
			}
			else
			{
				PORTR.OUTCLR=PIN1_bm;
				gfx_mono_draw_string("Invalid Card",0,0,&sysfont);
				delay_s(1);
				gfx_mono_init();
				PORTR.OUTSET=PIN1_bm;
			}
		}
	}
}
예제 #18
0
파일: main.c 프로젝트: icemelon9/imu_buffer
// idx: line number, starting from 0
inline void print_line(int16_t idx, char *str)
{
#ifdef DEBUG
	int16_t y = idx * 10;
	gfx_mono_draw_filled_rect(0, y, 128, 10, GFX_PIXEL_CLR);
	gfx_mono_draw_string(str, 0, y, &sysfont);
#endif
}
예제 #19
0
void sun_count(void)
{
	sun_value++;
	
	char* sun_val_string = NULL;
	sprintf(sun_val_string, "%4d", sun_value);
	gfx_mono_draw_filled_rect(25, 0, 24, 8, GFX_PIXEL_CLR);
	gfx_mono_draw_string(sun_val_string, 25, 0, &sysfont);
}
예제 #20
0
/**
 * \brief Draw spinner at its position.
 *
 * This function draws a spinner at its position.
 * The title of the spinner is only drawn if the redraw option is set.
 * If the spinner is in focus, arrows will be drawn next to the spinner value
 * to indicate that it is spinnable.
 *
 * \param spinner  pointer to initialized gfx_mono_spinctrl struct
 * \param redraw   true if title of spinner should be drawn
 */
void gfx_mono_spinctrl_draw(struct gfx_mono_spinctrl *spinner, bool redraw)
{
    char string_buf[GFX_MONO_SPINCTRL_INT_SPINNER_WIDTH];
    uint8_t index;
    uint8_t offset;

    if (redraw) {
        /* Clear line */
        gfx_mono_draw_filled_rect(0, spinner->y, GFX_MONO_LCD_WIDTH,
                                  SYSFONT_HEIGHT, GFX_PIXEL_CLR);
        /* Draw title */
        gfx_mono_draw_progmem_string((char PROGMEM_PTR_T)spinner->title,
                                     GFX_MONO_SPINCTRL_INDICATOR_WIDTH + 1,
                                     spinner->y, &sysfont);
    }

    if (spinner->in_focus) {
        gfx_mono_spinctrl_draw_spin_indicator(spinner, true);
    } else {
        gfx_mono_spinctrl_draw_spin_indicator(spinner, false);
    }

    if (spinner->datatype == SPINTYPE_INTEGER) {
        offset = GFX_MONO_LCD_WIDTH -
                 (SYSFONT_WIDTH *
                  GFX_MONO_SPINCTRL_INT_SPINNER_WIDTH);
        snprintf(string_buf, sizeof(string_buf), "%d",
                 spinner->integer_data);
        /* Delete previous spinner data */
        gfx_mono_draw_filled_rect(offset, spinner->y,
                                  GFX_MONO_LCD_WIDTH - offset -
                                  GFX_MONO_SPINCTRL_SPIN_INDICATOR_WIDTH,
                                  SYSFONT_HEIGHT,
                                  GFX_PIXEL_CLR);
        /* Draw integer data */
        gfx_mono_draw_string(string_buf, offset, spinner->y, &sysfont);
    } else if (spinner->datatype == SPINTYPE_STRING) {
        index = spinner->strings.index;
        offset = GFX_MONO_LCD_WIDTH -
                 (SYSFONT_WIDTH *
                  GFX_MONO_SPINCTRL_STRING_SPINNER_WIDTH);

        /* Delete previous spinner data */
        gfx_mono_draw_filled_rect(offset, spinner->y,
                                  GFX_MONO_LCD_WIDTH - offset -
                                  GFX_MONO_SPINCTRL_SPIN_INDICATOR_WIDTH,
                                  SYSFONT_HEIGHT,
                                  GFX_PIXEL_CLR);

        /* Draw string data */
        gfx_mono_draw_progmem_string(
            (char PROGMEM_PTR_T)spinner->strings.data[index], offset,
            spinner->y, &sysfont);
    }
}
예제 #21
0
/**
 * \brief Displays the current sampling rate on OLED display
 */
static void app_sampling_display_rate(void)
{
	char string[20];
	sprintf(string, DISPLAY_SAMPLING_TEXT,
			app_sampling_rate / 4,
			(app_sampling_rate % 4) ? 5 : 0);
	gfx_mono_draw_string(string,
			DISPLAY_SAMPLING_TEXT_POS_X,
			DISPLAY_SAMPLING_TEXT_POS_Y,
			&sysfont);
}
예제 #22
0
void LCD_Out_Dec(uint32_t n,int y)
{
	int a=log10(n);
	char ab[a+2];
	ab[a+1]='\0';
	for(;a>=0;a--)
	{
		ab[a]=(n%10)+'0';
		n/=10;
	}
	gfx_mono_draw_string(ab,0,y,&sysfont);
}
예제 #23
0
파일: main.c 프로젝트: Realtime-7/asf
/**
 * \brief Show explanation screen
 *
 * This function draws an explanation screen, and is run if the applications are
 * started without the jumpers described in the documentation attached.
 */
static void show_explain_splash(void)
{
    struct keyboard_event input;

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

    gfx_mono_draw_string("Class B Demonstration", 1, 4, &sysfont);
    gfx_mono_draw_string("See Application note", 4, 12, &sysfont);
    gfx_mono_draw_string("AVR1610", 40, 20, &sysfont);

    /* Any key will exit the loop */
    while (true) {
        oven_wdt_periodic_reset();
        keyboard_get_key_state(&input);
        if (input.type == KEYBOARD_RELEASE) {
            break;
        }
    }

    /* Clear screen */
    gfx_mono_draw_filled_rect(0, 0, 128, 32, GFX_PIXEL_CLR);
    gfx_mono_draw_string("Attach jumpers betwe-", 0, 4, &sysfont);
    gfx_mono_draw_string("en ADC2-ADC4 on J2,", 0, 12, &sysfont);
    gfx_mono_draw_string("and RXD-SS on J1", 0, 20, &sysfont);

    /* Any key will exit the loop */
    while (true) {
        oven_wdt_periodic_reset();
    }
}
예제 #24
0
파일: main.c 프로젝트: Realtime-7/asf
/**
 * \brief Show button names on display
 *
 * This function shows the user what the different on-board buttons do. When
 * the user presses a button, this function exits and the application can
 * continue.
 */
static void show_button_splash(void)
{
    struct keyboard_event input;

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

    gfx_mono_draw_filled_circle(6, 6, 3, GFX_PIXEL_SET, GFX_WHOLE);
    gfx_mono_draw_filled_circle(6, 24, 3, GFX_PIXEL_SET, GFX_WHOLE);
    gfx_mono_draw_filled_circle(122, 6, 3, GFX_PIXEL_SET, GFX_WHOLE);
    gfx_mono_draw_filled_circle(122, 24, 3, GFX_PIXEL_SET, GFX_WHOLE);

    gfx_mono_draw_string("Oven power/", 50, 0, &sysfont);
    gfx_mono_draw_string("Up", 94, 8, &sysfont);
    gfx_mono_draw_string("Down", 90, 22, &sysfont);
    gfx_mono_draw_string("Menu/", 12, 0, &sysfont);
    gfx_mono_draw_string("Back", 12, 8, &sysfont);
    gfx_mono_draw_string("Pot/enter", 12, 22, &sysfont);

    /* Any key will exit the loop */
    while (true) {
        oven_wdt_periodic_reset();
        keyboard_get_key_state(&input);
        if (input.type == KEYBOARD_RELEASE) {
            break;
        }
    }
}
예제 #25
0
static void draw_formatted_data(enum format_string_select sel,
		const sensor_data_t *data)
{
	static char format_buffer[3][17];

	static const char *format[] = {
		/* Acceleration */
		"X %5ld Milli-G ",
		"Y %5ld Milli-G ",
		"Z %5ld Milli-G ",

		/* Angular Rate */
		"X %5ld Deg/sec ",
		"Y %5ld Deg/sec ",
		"Z %5ld Deg/sec ",

		/* Magnetic Heading */
		"Hed %4ld Deg    ",
		"Inc %4ld Deg    ",
		"Fld %4ld uT     ",

		/* Temperature */
		"%4ld Fahrenheit ",
		"%4ld Celsius    ",
		"                "
	};

	LED_Toggle(PROMPT_LED);

	sprintf(format_buffer[0], format[sel + 0], data->value[0]);
	sprintf(format_buffer[1], format[sel + 1], data->value[1]);
	sprintf(format_buffer[2], format[sel + 2], data->value[2]);

	gfx_mono_draw_string(format_buffer[0], 1, 5, &sysfont);
	gfx_mono_draw_string(format_buffer[1], 1, 13, &sysfont);
	gfx_mono_draw_string(format_buffer[2], 1, 21, &sysfont);

	delay_ms(hz_to_ms(REFRESH_PERIOD));
}
예제 #26
0
void app_cpu_load_init(void)
{
	/* Reset counters */
	app_cpu_load_time_actif = 0;
	app_cpu_load_time_sleep = 0;
	/* Start Timer counter used to monitor CPU timing */
	tc_enable(&TCC1);
	tc_write_clock_source(&TCC1, TC_CLKSEL_DIV256_gc); /* 24MHz / 256 */
	tc_set_direction(&TCC1, TC_UP);
	/* Display static background */
	gfx_mono_draw_string(DISPLAY_CPU_LOAD_TEXT,
			DISPLAY_CPU_LOAD_TEXT_POS_X,
			DISPLAY_CPU_LOAD_TEXT_POS_Y,
			&sysfont);
}
예제 #27
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);
    }
}
예제 #28
0
int main(void)
{
	board_init();

	// Initialize graphics library
	gfx_mono_init();

	// Enable backlight
	ioport_set_pin_high(LCD_BACKLIGHT_ENABLE_PIN);

	gfx_mono_draw_string("Tests successful: \r\n1   2   3   4   5",
			0, 0, &sysfont);

	if (test_erase() == STATUS_OK) {
		gfx_mono_draw_string("OK",
				0, 2 * SYSFONT_HEIGHT + 1, &sysfont);
	} else {
		gfx_mono_draw_string("ERR",
				0, 2 * SYSFONT_HEIGHT + 1, &sysfont);
	}

	if (test_write() == STATUS_OK) {
		gfx_mono_draw_string("OK",
				4 * SYSFONT_WIDTH, 2 * SYSFONT_HEIGHT + 1, &sysfont);
	} else {
		gfx_mono_draw_string("ERR",
				4 * SYSFONT_WIDTH, 2 * SYSFONT_HEIGHT + 1, &sysfont);
	}

	if (test_atomic_write() == STATUS_OK) {
		gfx_mono_draw_string("OK",
				8 * SYSFONT_WIDTH, 2 * SYSFONT_HEIGHT + 1, &sysfont);
	} else {
		gfx_mono_draw_string("ERR",
				8 * SYSFONT_WIDTH, 2 * SYSFONT_HEIGHT + 1, &sysfont);
	}

	if (test_split_write() == STATUS_OK) {
		gfx_mono_draw_string("OK",
				12 * SYSFONT_WIDTH, 2 * SYSFONT_HEIGHT + 1, &sysfont);
	} else {
		gfx_mono_draw_string("ERR",
				12 * SYSFONT_WIDTH, 2 * SYSFONT_HEIGHT + 1, &sysfont);
	}

	if (test_erase_bytes() == STATUS_OK) {
		gfx_mono_draw_string("OK",
				16 * SYSFONT_WIDTH, 2 * SYSFONT_HEIGHT + 1, &sysfont);
	} else {
		gfx_mono_draw_string("ERR",
				16 * SYSFONT_WIDTH, 2 * SYSFONT_HEIGHT + 1, &sysfont);
	}

	while (true) {}

}
예제 #29
0
void app_sampling_init(void)
{
	/* QDec configuration */
	qdec_get_config_defaults(&qdec_config);
	qdec_config_phase_pins(&qdec_config, &PORTA, 6, false, 500);
	qdec_config_enable_rotary(&qdec_config);
	qdec_config_tc(&qdec_config, &TCC5);
	qdec_config_revolution(&qdec_config, 40);
	qdec_enabled(&qdec_config);

	/* ! ADC module configuration */
	struct adc_config adc_conf;

	/* Configure the ADC module:
	 * - signed, 12-bit results
	 * - VCC reference
	 * - 200 kHz maximum clock rate
	 * - manual conversion triggering
	 * - callback function
	 */
	adc_read_configuration(&LIGHT_SENSOR_ADC_MODULE, &adc_conf);
	adc_set_conversion_parameters(&adc_conf, ADC_SIGN_ON, ADC_RES_12,
			ADC_REF_VCC);
	adc_set_clock_rate(&adc_conf, 200000);
	adc_set_conversion_trigger(&adc_conf, ADC_TRIG_MANUAL, 1, 0);
	adc_write_configuration(&LIGHT_SENSOR_ADC_MODULE, &adc_conf);
	adc_set_callback(&LIGHT_SENSOR_ADC_MODULE, &app_sampling_handler);
	adc_enable(&LIGHT_SENSOR_ADC_MODULE);

	/* Configure ADC A channel 0 for light and NTC sensors.
	 * - differantial measurement (V- linked on internal GND)
	 * - gain x0.5
	 * - interrupt flag set on completed conversion
	 * - interrupts enabled
	 */
	adcch_read_configuration(&LIGHT_SENSOR_ADC_MODULE, ADC_CH0,
			&adcch_conf);
	adcch_set_input(&adcch_conf, LIGHT_SENSOR_ADC_INPUT,
			ADCCH_NEG_INTERNAL_GND, 0);
	adcch_set_interrupt_mode(&adcch_conf, ADCCH_MODE_COMPLETE);
	adcch_enable_interrupt(&adcch_conf);
	adcch_write_configuration(&LIGHT_SENSOR_ADC_MODULE, ADC_CH0,
			&adcch_conf);

	fifo_init(&app_sampling_fifo_desc, app_sampling_fifo_buffer,
			APP_SAMPLING_FIFO_SIZE);
	rtc_set_callback(&app_sampling_start);

	/* Display background */
	gfx_mono_draw_line(DISPLAY_SAMPLING_TEXT_POS_X - 3,
			0,
			DISPLAY_SAMPLING_TEXT_POS_X - 3,
			32,
			GFX_PIXEL_SET);
	app_sampling_display_rate();
	gfx_mono_draw_string(DISPLAY_LIGHT_TEXT,
			DISPLAY_LIGHT_TEXT_POS_X,
			DISPLAY_LIGHT_TEXT_POS_Y,
			&sysfont);
	gfx_mono_draw_filled_rect(
			DISPLAY_LIGHT_PROBAR_START_POS_X,
			DISPLAY_LIGHT_PROBAR_START_POS_Y,
			DISPLAY_LIGHT_PROBAR_START_SIZE_X,
			DISPLAY_LIGHT_PROBAR_START_SIZE_Y,
			GFX_PIXEL_SET);
	gfx_mono_draw_filled_rect(
			DISPLAY_LIGHT_PROBAR_STOP_POS_X,
			DISPLAY_LIGHT_PROBAR_STOP_POS_Y,
			DISPLAY_LIGHT_PROBAR_STOP_SIZE_X,
			DISPLAY_LIGHT_PROBAR_STOP_SIZE_Y,
			GFX_PIXEL_SET);

	/* Start a RTC alarm immediatly */
	rtc_set_alarm_relative(0);
}
예제 #30
0
int main (void)
{
	sysclk_init();
	board_init();
	pmic_init();
	gfx_mono_init();
	adc_sensors_init();
	// Enable display backlight
	gpio_set_pin_high(NHD_C12832A1Z_BACKLIGHT);
	cpu_irq_enable();
	
	while(true){
		
		if(state==1){
			start_game();
			}else if(state==2){
			tc_enable(&TCC0);
			tc_set_overflow_interrupt_callback(&TCC0, sun_count);
			tc_set_wgm(&TCC0, TC_WG_NORMAL);
			tc_write_period(&TCC0, 13500);
			tc_set_overflow_interrupt_level(&TCC0, TC_INT_LVL_LO);
			tc_write_clock_source(&TCC0, TC_CLKSEL_DIV256_gc);
			
			tc_enable(&TCC1);
			tc_set_overflow_interrupt_callback(&TCC1, button_press);
			tc_set_wgm(&TCC1, TC_WG_NORMAL);
			tc_write_period(&TCC1, 62500);
			tc_set_overflow_interrupt_level(&TCC1, TC_INT_LVL_LO);
			tc_write_clock_source(&TCC1, TC_CLKSEL_DIV8_gc);
			
			gfx_mono_draw_string("SUN:   0", 0, 0, &sysfont);
			gfx_mono_draw_string(">", 0, cursor_position, &sysfont);
			gfx_mono_draw_string("Score:  0", 63, 0, &sysfont);
			
			randomPeta();
			
			char* score_string = NULL;
			uint16_t old_score = 0;
			
			for(j = 0; j <= 70; j++){
				
				if(sun_value > 10){
					
					lightsensor_measure();
					while (!lightsensor_data_is_ready()) {
						// Wait until the conversion is complete
					}
					if(lightsensor_get_raw_value() > 250){
						sun_value -= 10;
						sunBurst();
						gfx_mono_draw_filled_rect(12,8,114,24,GFX_PIXEL_CLR);
					}
				}
				

				if(score > old_score){
					sprintf(score_string, "%3d", score);
					gfx_mono_draw_string(score_string, 100, 0, &sysfont);
					old_score = score;
				}
				
				if(lose){
					state=3;
					break;
					}else if(zombie==0){
					state=4;
					break;
				}
				
				
				tampilkanPeta();
				tampilkanTembak();
				delay_ms(1000);
			}
			}else if(state==3){
			cpu_irq_disable();
			gfx_mono_draw_filled_rect(0,0,128,32,GFX_PIXEL_CLR);
			while(true){
				gfx_mono_draw_string("GAME OVER",36,8,&sysfont)	;
				gfx_mono_draw_string("You Lose",39,20,&sysfont)	;
			}
			}else if(state==4){
			cpu_irq_disable();
			gfx_mono_draw_filled_rect(0,0,128,32,GFX_PIXEL_CLR);
			while(true){
				gfx_mono_draw_string("GAME OVER",36,2,&sysfont)	;
				gfx_mono_draw_string("You Win",42,12,&sysfont)	;
				gfx_mono_draw_string("Score = ",30,22,&sysfont)	;
				char* score_string = NULL;
				sprintf(score_string, "%3d", score);
				gfx_mono_draw_string(score_string, 79, 22, &sysfont);
			}
		}
	}
	
}