Ejemplo n.º 1
0
void tampilkanPeta(void){
	for(i=0;i<20;++i){
		if(atas[i+j]=='@'){
			if(i==0){
				if(plant[0]){
					plant[0] = false;
					gfx_mono_draw_filled_rect(i*6+6,8,12,7,GFX_PIXEL_CLR);
					atas[i+j] = ' ';
				}else lose = true;
				}else{
				gfx_mono_draw_filled_rect(i*6+12,8,6,7,GFX_PIXEL_CLR);
				if(tembak_atas[i+1]=='*'){
					tembak_atas[i+1]=' ';
					atas[i+j] = ' ';
					zombie--;
					score++;
				}
				gfx_mono_draw_char(atas[i+j],i*6+6,8,&sysfont);
			}
		}
		
		if(tengah[i+j]=='@'){
			if(i==0){
				if(plant[1]){
					plant[1] = false;
					gfx_mono_draw_filled_rect(i*6+6,16,12,7,GFX_PIXEL_CLR);
					tengah[i+j] = ' ';
				}else lose = true;
				}else{
				gfx_mono_draw_filled_rect(i*6+12,16,6,7,GFX_PIXEL_CLR);
				if(tembak_tengah[i+1]=='*'){
					tembak_tengah[i+1]=' ';
					tengah[i+j] = ' ';
					zombie--;
					score++;
				}
				gfx_mono_draw_char(tengah[i+j],i*6+6,16,&sysfont);
			}
		}
		if(bawah[i+j]=='@'){
			if(i==0){
				if(plant[2]){
					plant[2] = false;
					gfx_mono_draw_filled_rect(i*6+6,24,12,7,GFX_PIXEL_CLR);
					bawah[i+j] = ' ';
				}else lose = true;
				}else{
				gfx_mono_draw_filled_rect(i*6+12,24,5,7,GFX_PIXEL_CLR);
				if(tembak_bawah[i+1]=='*'){
					tembak_bawah[i+1]=' ';
					bawah[i+j]=' ';
					zombie--;
					score++;
				}
				gfx_mono_draw_char(bawah[i+j],i*6+6,24,&sysfont);
			}
		}
	}
}
/**
 * \brief Draws a string located in program memory to the display
 *
 * This function will draw a string located in program memory to the display,
 * this differs from gfx_mono_draw_string() by using constant string data from
 * the program memory instead of string data in RAM.
 *
 * Using program memory for constant strings will reduce the applications need
 * for RAM, and thus lower the overall size footprint.
 *
 * \param str       Pointer to string located in program memory
 * \param x         X coordinate on screen.
 * \param y         Y coordinate on screen.
 * \param font      Font to draw string in
 */
void gfx_mono_draw_progmem_string(char PROGMEM_PTR_T str, gfx_coord_t x,
		gfx_coord_t y, const struct font *font)
{
	char temp_char;

	/* Sanity check on parameters, assert if str or font is NULL. */
	Assert(str != NULL);
	Assert(font != NULL);

	/* Save X in order to know where to return to on CR. */
	const gfx_coord_t start_of_string_position_x = x;

	/* Draw characters until trailing null byte */
	temp_char = PROGMEM_READ_BYTE((uint8_t PROGMEM_PTR_T)str);

	while (temp_char) {
		/* Handle '\n' as newline, draw normal characters. */
		if (temp_char == '\n') {
			x = start_of_string_position_x;
			y += font->height + 1;
		} else if (temp_char == '\r') {
			/* Skip '\r' characters. */
		} else {
			gfx_mono_draw_char(temp_char, x, y, font);
			x += font->width;
		}

		temp_char = PROGMEM_READ_BYTE((uint8_t PROGMEM_PTR_T)(++str));
	}
}
Ejemplo n.º 3
0
/**
 * \brief Terminal task
 *
 * This task prints the terminal text buffer to the display.
 *
 * \param params Parameters for the task. (Not used.)
 */
static void terminal_task(void *params)
{
	gfx_coord_t x, y;
	char current_char;
	uint8_t current_column;
	uint8_t current_line;
	uint8_t printed_lines;

	for (;;) {
		oled1_set_led_state(&oled1, OLED1_LED2_ID, true);

		// Grab both display and terminal mutexes before doing anything
		xSemaphoreTake(display_mutex, portMAX_DELAY);
		xSemaphoreTake(terminal_mutex, portMAX_DELAY);

		y = (TERMINAL_LINES - 1) * (SYSFONT_HEIGHT + 1);
		current_line = terminal_line_offset;

		for (printed_lines = 0; printed_lines < TERMINAL_LINES; printed_lines++)
				{
			x = 0;
			current_column = 0;

			// Print characters of string until zero terminator is encountered
			current_char = terminal_buffer[current_line][current_column];
			while (current_char != '\0') {
				gfx_mono_draw_char(current_char, x, y, &sysfont);

				// Move to next character on display and in buffer
				x += SYSFONT_WIDTH;
				current_column++;
				current_char = terminal_buffer[current_line][current_column];
			}

			// Erase remaining part of line on display
			if (current_column < TERMINAL_COLUMNS) {
				gfx_mono_draw_filled_rect(x, y,
						CANVAS_WIDTH - (current_column * SYSFONT_WIDTH),
						SYSFONT_HEIGHT, GFX_PIXEL_CLR);
			}

			// Move to previous line on display and in buffer
			y -= 1 + SYSFONT_HEIGHT;
			current_line += TERMINAL_BUFFER_LINES - 1;
			current_line %= TERMINAL_BUFFER_LINES;
		}

		xSemaphoreGive(terminal_mutex);
		xSemaphoreGive(display_mutex);

		oled1_set_led_state(&oled1, OLED1_LED2_ID, false);

		vTaskDelay(TERMINAL_TASK_DELAY);
	}
}
Ejemplo n.º 4
0
/**
 * \brief About task
 *
 * This task prints a short text about the demo, with a simple zooming
 * animation.
 *
 * \param params Parameters for the task. (Not used.)
 */
static void about_task(void *params)
{
	char c;
	gfx_coord_t x, y;
	uint8_t i, shift;
	EventBits_t event_bits;
	const TickType_t ticks_to_wait = 10 / portTICK_PERIOD_MS;

	const uint8_t max_shift = 8;
	shift = 1;

	for (;;) {
		/* Wait a maximum of 10ms for either bit 3 to be set within
		    the event group.  Not clear the bits before exiting. */
		event_bits = xEventGroupWaitBits(
				event_group,   /* The event group being tested. */
				EVENT_DISPLAY_ABOUT, /* The bits within the event group to wait for. */
				pdFALSE,        /* Bit should not be cleared before returning. */
				pdFALSE,       /* Don't wait for both bits, either bit will do. */
				ticks_to_wait);/* Wait a maximum of 10ms for either bit to be set. */

		if(event_bits & EVENT_DISPLAY_ABOUT) {
			oled1_set_led_state(&oled1, OLED1_LED2_ID, true);

			xSemaphoreTake(display_mutex, portMAX_DELAY);

			// Print the about text in an expanding area
			for (i = 0; i < (sizeof(about_text) - 1); i++) {
				c = about_text[i];
				x = (((i % TERMINAL_COLUMNS) * SYSFONT_WIDTH) * shift
						+ (CANVAS_WIDTH / 2) * (max_shift - shift))
						/ max_shift;
				y = (((i / TERMINAL_COLUMNS) * SYSFONT_HEIGHT) * shift
						+ (CANVAS_HEIGHT / 2) * (max_shift - shift))
						/ max_shift;
				gfx_mono_draw_char(c, x, y, &sysfont);
			}

			xSemaphoreGive(display_mutex);

			oled1_set_led_state(&oled1, OLED1_LED2_ID, false);

			// Repeat task until we're displaying the text in full size
			if (shift < max_shift) {
				shift++;
				vTaskDelay(ABOUT_TASK_DELAY);
			} else {
				shift = 0;
				xEventGroupClearBits(event_group, EVENT_DISPLAY_ABOUT);
			}
		}
	}
}
Ejemplo n.º 5
0
/**
 * \brief This Function Display ADC count on LCD
 *  - It will extract each digit from ADC count and convert to ASCII
 *  - Use GFX service for displaying each character
 * \param adc_rawcount ADC raw count value to be displayed.
 * \param x_cordinate X-coordinate where display should end.
 * \param sign_flag Sign of ADC count.If negative sign_flag is set.
 */
void display_adccount( uint64_t adc_rawcount, uint8_t x_cordinate,
		uint8_t sign_flag)
{
	uint8_t digit_count = 0;
	uint8_t adc_count_digit = 0;
	uint8_t sign_digit = '+';

	/* Loop through all digits to convert to ASCII */
	for (digit_count = 0; digit_count <= NUMBER_OF_DIGITS_IN_ADCCOUNT;
			digit_count++) {
		/* Extract each digit from raw ADC count and convert to ASCII
		 * - The Last digit will be extracted first and displayed
		 */
		adc_count_digit =   (adc_rawcount % 10)  + 48;

		/* Display the extracted character on LCD */
		gfx_mono_draw_char((const char)adc_count_digit, x_cordinate, 23,
				&sysfont);

		/* Point to x-coordinate for display of next digit */
		x_cordinate = (x_cordinate - 7);

		/* Remove extracted digit from raw count by doing divide
		 * with 10
		 */
		adc_rawcount = (adc_rawcount / 10);
	}

	/* If sign_flag is set display negative symbol */
	if (sign_flag) {
		sign_digit = '-';
	}

	/* Display the sign character on LCD */
	gfx_mono_draw_char((const char)sign_digit, x_cordinate, 23, &sysfont);
}
Ejemplo n.º 6
0
/**
 * \brief About task
 *
 * This task prints a short text about the demo, with a simple zooming
 * animation.
 *
 * \param params Parameters for the task. (Not used.)
 */
static void about_task(void *params)
{
    char c;
    gfx_coord_t x, y;
    uint8_t i, shift;
    char * text_to_use = (char *)&about_text;

    const uint8_t max_shift = 8;
    shift = 1;

    for (;;) {
        oled1_set_led_state(&oled1, OLED1_LED2_ID, true);

        xSemaphoreTake(display_mutex, portMAX_DELAY);

        // Print the about text in an expanding area
        for (i = 0; i < (sizeof(about_text) - 1); i++) {
            c = text_to_use[i];
            x = (((i % TERMINAL_COLUMNS) * SYSFONT_WIDTH) * shift
                 + (CANVAS_WIDTH / 2) * (max_shift - shift))
                / max_shift;
            y = (((i / TERMINAL_COLUMNS) * SYSFONT_HEIGHT) * shift
                 + (CANVAS_HEIGHT / 2) * (max_shift - shift))
                / max_shift;
            gfx_mono_draw_char(c, x, y, &sysfont);
        }

        xSemaphoreGive(display_mutex);

        oled1_set_led_state(&oled1, OLED1_LED2_ID, false);

        // Repeat task until we're displaying the text in full size
        if (shift < max_shift) {
            shift++;
            vTaskDelay(ABOUT_TASK_DELAY);
        } else {
            shift = 0;
            vTaskSuspend(NULL);
            if (tickless_enable) {
                text_to_use = (char *)&about_text;
            } else {
                text_to_use = (char *)&about_text_tickless;
            }
            tickless_enable = !tickless_enable;
        }
    }
}
/**
 * \brief Draws a string to the display
 *
 * This function will draw a string located in memory to the display.
 *
 * \param str       Pointer to string
 * \param x         X coordinate on screen.
 * \param y         Y coordinate on screen.
 * \param font      Font to draw string in
 */
void gfx_mono_draw_string(const char *str, gfx_coord_t x, gfx_coord_t y,
		const struct font *font)
{
	/* Save X in order to know where to return to on CR. */
	const gfx_coord_t start_of_string_position_x = x;

	/* Sanity check on parameters, assert if str or font is NULL. */
	Assert(str != NULL);
	Assert(font != NULL);

	/* Draw characters until trailing null byte */
	do {
		/* Handle '\n' as newline, draw normal characters. */
		if (*str == '\n') {
			x = start_of_string_position_x;
			y += font->height + 1;
		} else if (*str == '\r') {
			/* Skip '\r' characters. */
		} else {
			gfx_mono_draw_char(*str, x, y, font);
			x += font->width;
		}
	} while (*(++str));
}
Ejemplo n.º 8
0
void tampilkanTembak(void){
	for(i=0;i<19;++i){
		
		if(i==18){
			if(tembak_atas[i+1]=='*')
			gfx_mono_draw_filled_rect(i*6+12,8,10,7,GFX_PIXEL_CLR);
			if(tembak_tengah[i+1]=='*')
			gfx_mono_draw_filled_rect(i*6+12,16,10,7,GFX_PIXEL_CLR);
			if(tembak_bawah[i+1]=='*')
			gfx_mono_draw_filled_rect(i*6+12,24,10,7,GFX_PIXEL_CLR);
		}
		
		if(tembak_atas[i]=='*')
		{
			if(atas[i+j] =='@'){
				tembak_atas[i]=' ';
				atas[i+j] = ' ';
				zombie--;
				score++;
				gfx_mono_draw_filled_rect(i*6+6,8,12,7,GFX_PIXEL_CLR);
				}else{
				if(i>0){
					gfx_mono_draw_filled_rect(i*6+6,8,6,7,GFX_PIXEL_CLR);
				}
				
				gfx_mono_draw_char(tembak_atas[i],i*6+12,8,&sysfont);
			}
		}
		
		if(tembak_tengah[i]=='*')
		{
			if(tengah[i+j] =='@'){
				tembak_tengah[i]=' ';
				tengah[i+j] = ' ';
				zombie--;
				score++;
				gfx_mono_draw_filled_rect(i*6+6,16,12,7,GFX_PIXEL_CLR);
				}else {
				if(i>0){
					gfx_mono_draw_filled_rect(i*6+6,16,6,7,GFX_PIXEL_CLR);
				}
				gfx_mono_draw_char(tembak_tengah[i],i*6+12,16,&sysfont);
			}
		}
		
		if(tembak_bawah[i]=='*')
		{
			if(bawah[i+j] =='@'){
				tembak_bawah[i]=' ';
				bawah[i+j] = ' ';
				zombie--;
				score++;
				gfx_mono_draw_filled_rect(i*6+6,24,12,7,GFX_PIXEL_CLR);
				}else{
				if(i>0){
					gfx_mono_draw_filled_rect(i*6+6,24,6,7,GFX_PIXEL_CLR);
				}
				gfx_mono_draw_char(tembak_bawah[i],i*6+12,24,&sysfont);
			}
		}
	}
	for(i=19;i>0;i--){
		tembak_atas[i] =  tembak_atas[i-1];
		tembak_tengah[i] = tembak_tengah[i-1];
		tembak_bawah[i] = tembak_bawah[i-1];
	}
	tembak_atas[0] = ' ';
	tembak_tengah[0] = ' ';
	tembak_bawah[0] = ' ';
}
Ejemplo n.º 9
0
void button_press(void){
	if(gpio_pin_is_low(GPIO_PUSH_BUTTON_1)){
		gfx_mono_draw_filled_rect(0,cursor_position,5,8,GFX_PIXEL_CLR);
		if(cursor_position==8) cursor_position = 24;
		else cursor_position-=8;
		gfx_mono_draw_char('>', 0, cursor_position, &sysfont);
	}
	if(gpio_pin_is_low(GPIO_PUSH_BUTTON_2)){
		gfx_mono_draw_filled_rect(0,cursor_position,5,8,GFX_PIXEL_CLR);
		if(cursor_position==24) cursor_position = 8;
		else cursor_position+=8;
		gfx_mono_draw_char('>', 0, cursor_position, &sysfont);
	}
	if(gpio_pin_is_low(GPIO_PUSH_BUTTON_0)){
		if(cursor_position==8){
			if(plant[0]==false){
				if(sun_value>=plant_cost){
					sun_value -= plant_cost;
					plant[0] = true;
					gfx_mono_draw_char('P',6,cursor_position,&sysfont);
				}
			}
			else{
				if(sun_value>=2){
					sun_value -= 2;
					tembak_atas[0]='*';
				}
				
			}
			
			}else if(cursor_position==16){
			if(plant[1]==false){
				if(sun_value>=plant_cost){
					sun_value -= plant_cost;
					plant[1] = true;
					gfx_mono_draw_char('P',6,cursor_position,&sysfont);
				}
			}
			else{
				if(sun_value>=2){
					sun_value -= 2;
					tembak_tengah[0]='*';
				}
				
			}
			
			}else{
			if(plant[2]==false){
				if(sun_value>=plant_cost){
					sun_value -= plant_cost;
					plant[2] = true;
					gfx_mono_draw_char('P',6,cursor_position,&sysfont);
				}
			}
			else{
				if(sun_value>=2){
					sun_value -= 2;
					tembak_bawah[0]='*';
				}
			}
		}
	}
}
Ejemplo n.º 10
0
/**
 * \brief Terminal task
 *
 * This task prints the terminal text buffer to the display.
 *
 * \param params Parameters for the task. (Not used.)
 */
static void terminal_task(void *params)
{
	gfx_coord_t x, y;
	char current_char;
	uint8_t current_column;
	uint8_t current_line;
	uint8_t printed_lines;
	EventBits_t event_bits;
	const TickType_t ticks_to_wait = 10 / portTICK_PERIOD_MS;

	for (;;) {
		/* Wait a maximum of 10ms for either bit 2 to be set within
		    the event group.  Not clear the bits before exiting. */
		event_bits = xEventGroupWaitBits(
				event_group,   /* The event group being tested. */
				EVENT_DISPLAY_TERMINAL, /* The bits within the event group to wait for. */
				pdFALSE,        /* Bit should not be cleared before returning. */
				pdFALSE,       /* Don't wait for both bits, either bit will do. */
				ticks_to_wait);/* Wait a maximum of 10ms for either bit to be set. */

		if(event_bits & EVENT_DISPLAY_TERMINAL) {
			oled1_set_led_state(&oled1, OLED1_LED2_ID, true);

			// Grab both display and terminal mutexes before doing anything
			xSemaphoreTake(display_mutex, portMAX_DELAY);
			xSemaphoreTake(terminal_mutex, portMAX_DELAY);

			y = (TERMINAL_LINES - 1) * (SYSFONT_HEIGHT + 1);
			current_line = terminal_line_offset;

			for (printed_lines = 0; printed_lines < TERMINAL_LINES; printed_lines++)
					{
				x = 0;
				current_column = 0;

				// Print characters of string until zero terminator is encountered
				current_char = terminal_buffer[current_line][current_column];
				while (current_char != '\0') {
					gfx_mono_draw_char(current_char, x, y, &sysfont);

					// Move to next character on display and in buffer
					x += SYSFONT_WIDTH;
					current_column++;
					current_char = terminal_buffer[current_line][current_column];
				}

				// Erase remaining part of line on display
				if (current_column < TERMINAL_COLUMNS) {
					gfx_mono_draw_filled_rect(x, y,
							CANVAS_WIDTH - (current_column * SYSFONT_WIDTH),
							SYSFONT_HEIGHT, GFX_PIXEL_CLR);
				}

				// Move to previous line on display and in buffer
				y -= 1 + SYSFONT_HEIGHT;
				current_line += TERMINAL_BUFFER_LINES - 1;
				current_line %= TERMINAL_BUFFER_LINES;
			}

			xSemaphoreGive(terminal_mutex);
			xSemaphoreGive(display_mutex);

			oled1_set_led_state(&oled1, OLED1_LED2_ID, false);
		}

		vTaskDelay(TERMINAL_TASK_DELAY);
	}
}