void gfx_ili9325_init(void)
{
	struct ili9325_opt_t g_ili9325_display_opt;

	/* initialize globals */
	gfx_width = ILI9325_LCD_WIDTH;
	gfx_height = ILI9325_LCD_HEIGHT;

	/* Enable peripheral clock */
	pmc_enable_periph_clk(ID_SMC);

	/* Configure SMC interface for Lcd */
	smc_set_setup_timing(SMC,ILI9325_LCD_CS,SMC_SETUP_NWE_SETUP(2)
			| SMC_SETUP_NCS_WR_SETUP(2)
			| SMC_SETUP_NRD_SETUP(2)
			| SMC_SETUP_NCS_RD_SETUP(2));
	smc_set_pulse_timing(SMC, ILI9325_LCD_CS , SMC_PULSE_NWE_PULSE(4)
			| SMC_PULSE_NCS_WR_PULSE(4)
			| SMC_PULSE_NRD_PULSE(10)
			| SMC_PULSE_NCS_RD_PULSE(10));
	smc_set_cycle_timing(SMC, ILI9325_LCD_CS, SMC_CYCLE_NWE_CYCLE(10)
			| SMC_CYCLE_NRD_CYCLE(22));
#if !defined(SAM4S)
	smc_set_mode(SMC, ILI9325_LCD_CS, SMC_MODE_READ_MODE
			| SMC_MODE_WRITE_MODE
			| SMC_MODE_DBW_8_BIT);
#else
	smc_set_mode(SMC, ILI9325_LCD_CS, SMC_MODE_READ_MODE
			| SMC_MODE_WRITE_MODE);
#endif

	/* Initialize display parameter */
	g_ili9325_display_opt.ul_width= ILI9325_LCD_WIDTH;
	g_ili9325_display_opt.ul_height = ILI9325_LCD_HEIGHT;
	g_ili9325_display_opt.foreground_color= COLOR_BLACK;
	g_ili9325_display_opt.background_color = COLOR_WHITE;

	/* Switch off backlight */
	aat31xx_disable_backlight();

	/* Initialize LCD */
	ili9325_init(&g_ili9325_display_opt);
	ili9325_display_on();
	/* Set backlight level */
	aat31xx_set_backlight(AAT31XX_AVG_BACKLIGHT_LEVEL);

	/* Set clipping area to whole screen initially */
	gfx_set_clipping(0, 0, gfx_width, gfx_height);

	gfx_draw_filled_rect(0, 0, gfx_width, gfx_height,
			GFX_COLOR(0xFF, 0xFF, 0xFF));
}
Ejemplo n.º 2
0
/**
 * \brief Frame draw event handler
 *
 * This function will draw the contents of the sub-frame.
 *
 * \sa wtk_basic_frame_draw_handler_t
 */
static void sub_frame_draw_handler(struct win_window *win,
		struct win_clip_region const *clip)
{
	char buffer[4];

	snprintf(buffer, sizeof(buffer), "%3d", counter);

	/**
	 * \todo Add code here to draw text on screen using the
	 * gfx_draw_string() function.
	 */
	gfx_draw_string(buffer, clip->origin.x + 30, clip->origin.y + 12,
			&sysfont, GFX_COLOR(255, 255, 255),
			GFX_COLOR_TRANSPARENT);
}
Ejemplo n.º 3
0
/**
 * \brief Compute the next rainbow color for multi-color drawing mode
 *
 * This function handles the color mixing algorithm needed to produce a sequence
 * of colors in the RGB spectrum. Each time it is called, the next color in the
 * sequence is returned.
 *
 * \return The next color in the rainbow sequence as a gfx_color_t.
 */
static gfx_color_t get_next_rainbow_color(void)
{
	static uint8_t multi_color_rgb[3] = {255, 0, 0};
	static uint8_t multi_color_index  = 0;
	static bool multi_color_decrement = false;

	/* Check if we are currently incrementing or decrementing the
	 * R/G/B value */
	if (multi_color_decrement) {
		/* Make sure we wrap the mixing color to the correct minimum
		 * value as we decrement it */
		if (multi_color_rgb[multi_color_index] > MULTI_COLOR_INCREMENT) {
			multi_color_rgb[multi_color_index] -= MULTI_COLOR_INCREMENT;
		}
		else {
			multi_color_rgb[multi_color_index] = 0;
		}
	}
	else {
		/* Make sure we wrap the mixing color to the correct maximum
		 * value as we increment it */
		if (multi_color_rgb[multi_color_index] <
				(255 - MULTI_COLOR_INCREMENT)) {
			multi_color_rgb[multi_color_index] += MULTI_COLOR_INCREMENT;
		}
		else {
			multi_color_rgb[multi_color_index] = 255;
		}
	}

	/* Check if we have reached the current mix color limit */
	if ((multi_color_rgb[multi_color_index] == 0) ||
			(multi_color_rgb[multi_color_index] == 255)) {
		/* Select the next R/G/B color to mix and invert the
		 * mixing direction */
		multi_color_index = (multi_color_index + 1) % 3;
		multi_color_decrement = !multi_color_decrement;
	}

	/* Create the new rainbow drawing color from the current
	 * mixed RGB values */
	return GFX_COLOR(multi_color_rgb[0], multi_color_rgb[1],
			multi_color_rgb[2]);
}
Ejemplo n.º 4
0
void network_application() {
	draw_background();
    gfx_draw_filled_rect(5, 26, 310, 182, GFX_COLOR(20, 20, 20));

    if(!wifi_ready && wifi_error) {
        gfx_draw_string_aligned(SYMFONT_WIFI, gfx_get_width() / 2, 120, &symbol_sysfont, GFX_COLOR_TRANSPARENT, GFX_COLOR_RED, TEXT_POS_CENTER_X, TEXT_ALIGN_CENTER);
        gfx_draw_string_aligned("Not Connected", gfx_get_width() / 2, 155, &sysfont, GFX_COLOR_TRANSPARENT, GFX_COLOR_RED, TEXT_POS_CENTER_X, TEXT_ALIGN_CENTER);
    } else {
        gfx_draw_string_aligned(SYMFONT_WIFI, gfx_get_width() / 2, 120, &symbol_sysfont, GFX_COLOR_TRANSPARENT, GFX_COLOR_GREEN, TEXT_POS_CENTER_X, TEXT_ALIGN_CENTER);
        gfx_draw_string_aligned("Connected", gfx_get_width() / 2, 155, &sysfont, GFX_COLOR_TRANSPARENT, GFX_COLOR_GREEN, TEXT_POS_CENTER_X, TEXT_ALIGN_CENTER);
    }

    uint8_t ram_buf[AT45DBX_SECTOR_SIZE];
    
    at45dbx_read_sector_open(0x0007);
    at45dbx_read_sector_to_ram(ram_buf);
    at45dbx_read_close();
    char mac_string[128];
    snprintf(mac_string, sizeof(mac_string), "MAC: %s", ram_buf);
    gfx_draw_string_aligned(mac_string, 11, 27, &small_sysfont, GFX_COLOR_TRANSPARENT, GFX_COLOR_WHITE, TEXT_POS_LEFT, TEXT_ALIGN_LEFT);

    if (wifi_error) {
         gfx_draw_string_aligned(esp_error, 11, 47, &small_sysfont, GFX_COLOR_TRANSPARENT, GFX_COLOR_WHITE, TEXT_POS_LEFT, TEXT_ALIGN_LEFT);
    }

	struct keyboard_event input;
    while(mma8451_orientation() != 6) {
        esp8266_check_buffer();

        keyboard_get_key_state(&input);
        if (input.type == KEYBOARD_RELEASE) {
            if (input.keycode == KEYBOARD_B) {
                break;
            }
        }
        if(mma8451_clear_interrupt() && is_low_power()) {
            exit_low_power();
        }
    }
}
Ejemplo n.º 5
0
gfx_color_t gfx_ili9488_color(uint8_t r, uint8_t g, uint8_t b)
{
	return GFX_COLOR(r, g, b);
}
Ejemplo n.º 6
0
void draw_event() {
    draw_background();
    draw_time();
    gfx_draw_filled_rect(5, 26, 310, 182, GFX_COLOR(8, 8, 8));
    draw_button_hints();

    switch(event_track) {
        case 0:
            gfx_draw_string_aligned("Schedule - KEYNOTES",    11, 2, &sysfont, GFX_COLOR_TRANSPARENT, GFX_COLOR_YELLOW, TEXT_POS_LEFT, TEXT_ALIGN_LEFT);
            break;
        case 1:
            gfx_draw_string_aligned("Schedule - TRACK 1",    11, 2, &sysfont, GFX_COLOR_TRANSPARENT, GFX_COLOR_YELLOW, TEXT_POS_LEFT, TEXT_ALIGN_LEFT);
            break;
        case 2:
            gfx_draw_string_aligned("Schedule - TRACK 2",    11, 2, &sysfont, GFX_COLOR_TRANSPARENT, GFX_COLOR_YELLOW, TEXT_POS_LEFT, TEXT_ALIGN_LEFT);
            break;
        case 3:
            gfx_draw_string_aligned("Schedule - TRACK 3",    11, 2, &sysfont, GFX_COLOR_TRANSPARENT, GFX_COLOR_YELLOW, TEXT_POS_LEFT, TEXT_ALIGN_LEFT);
            break;
        case 4:
            gfx_draw_string_aligned("Schedule - TRACK 4",    11, 2, &sysfont, GFX_COLOR_TRANSPARENT, GFX_COLOR_YELLOW, TEXT_POS_LEFT, TEXT_ALIGN_LEFT);
            break;
        case 5:
            gfx_draw_string_aligned("Schedule - TRACK 5",    11, 2, &sysfont, GFX_COLOR_TRANSPARENT, GFX_COLOR_YELLOW, TEXT_POS_LEFT, TEXT_ALIGN_LEFT);
            break;
    }
    
    uint16_t keynote = 0x0100;
    uint16_t track1 = 0x0200;
    uint16_t track2 = 0x0300;
    uint16_t track3 = 0x0400;
    uint16_t track4 = 0x0500;
    uint16_t track5 = 0x0600;

    uint16_t addresses[] = {keynote, track1, track2, track3, track4, track5};
    //uint16_t max_event[] = {5, 22, 22, 15, 23};

    uint8_t ram_buf[AT45DBX_SECTOR_SIZE];
    at45dbx_read_sector_open(addresses[event_track] + event_index);
    at45dbx_read_sector_to_ram(ram_buf);
    at45dbx_read_close();

    char *array[6];
    uint8_t i = 0;
    array[i] = strtok(ram_buf,";");
    while(array[i] != NULL) {
        array[++i] = strtok(NULL, ";");
    }

    char *title[256];
    uint8_t a = word_wrap(&title, array[0], 30);

    gfx_draw_string_aligned(title, 11, 27, &sysfont, GFX_COLOR_TRANSPARENT, GFX_COLOR_WHITE, TEXT_POS_LEFT, TEXT_ALIGN_LEFT);

    char event_time[36];
    snprintf(event_time, sizeof(event_time),"%s - %s", array[1], array[2]);
        
    char *names[256];
    uint8_t n = word_wrap(&names, array[3], 33);

        gfx_draw_string_aligned(names, 11, 60+(a*20), &small_sysfont, GFX_COLOR_TRANSPARENT, GFX_COLOR_RED, TEXT_POS_LEFT, TEXT_ALIGN_LEFT);

        gfx_draw_string_aligned(array[4], 11, 85+(a*20)+(n*20), &tiny_sysfont, GFX_COLOR_TRANSPARENT, GFX_COLOR_YELLOW, TEXT_POS_LEFT, TEXT_ALIGN_LEFT);
        gfx_draw_string_aligned(event_time, 11, 100+(a*20)+(n*20), &tiny_sysfont, GFX_COLOR_TRANSPARENT, GFX_COLOR_WHITE, TEXT_POS_LEFT, TEXT_ALIGN_LEFT);
        
        
    // }
}
Ejemplo n.º 7
0
/**
 * \brief Setup widget demo
 *
 * Allocates memory for the application context, and creates all widgets that
 * make up its interface. If memory allocation or widget creation fails, the
 * application exits immediately.
 *
 * \return Boolean true if the application was launched successfully, false if
 *         a memory allocation occurred.
 */
bool app_widget_launch(void)
{
	struct win_window *parent;
	struct win_area area;
	struct wtk_button *button;

	/* Create a new context for the GUI */
	widget_ctx = membag_alloc(sizeof(struct widget_context));
	if (!widget_ctx) {
		return false;
	}

	/* Initialize context data. */
	widget_ctx->frame_bg.type = GFX_BITMAP_SOLID;
	widget_ctx->frame_bg.data.color = GFX_COLOR(220, 220, 220);

	/* Set the area for the GUI window */
	area = win_get_attributes(win_get_root())->area;
	win_inflate_area(&area, -20);

	/* Create and show the main GUI frame */
	widget_ctx->frame = wtk_basic_frame_create(
			win_get_root(), &area, &widget_ctx->frame_bg, NULL,
			widget_frame_command_handler, widget_ctx);
	if (!widget_ctx->frame) {
		goto error_frame;
	}

	parent = wtk_basic_frame_as_child(widget_ctx->frame);
	win_show(parent);

	/* Set the background information for the plot widget */
	widget_ctx->plot_bg.type = GFX_BITMAP_SOLID;
	widget_ctx->plot_bg.data.color = GFX_COLOR_WHITE;

	/* Adjust area for the plot widget */
	area.size.y -= 80;
	area.size.x -= 40;

	/* Create and show the plot widget with vertical axis marks */
	widget_ctx->plot = wtk_plot_create(parent, &area, 100, 10, GFX_COLOR_RED,
			&widget_ctx->plot_bg, WTK_PLOT_LEFT_TO_RIGHT);
	if (!widget_ctx->plot) {
		goto error_widget;
	}
	wtk_plot_set_grid(widget_ctx->plot, WTK_PLOT_TICKS_VERTICAL,
			10, 0, 10, 0, GFX_COLOR_BLUE, GFX_COLOR_GREEN);
	win_show(wtk_plot_as_child(widget_ctx->plot));
	
	/* Adjust area for the slider widget */
	area.pos.y += area.size.y + 10;
	area.size.y = 40;
	area.size.x -= 60;
	
	/* Create and show the slider widget */
	widget_ctx->slider = wtk_slider_create(parent, &area, 100, 0,
			WTK_SLIDER_HORIZONTAL, (win_command_t)SLIDER_ID);	
	if (!widget_ctx->slider) {
		goto error_widget;
	}
	win_show(wtk_slider_as_child(widget_ctx->slider));	
	
	/* Adjust area for the button widget */
	area.pos.x += area.size.x + 10;
	area.size.x = 50;
	
	/* Create and show the button widget */
	button = wtk_button_create(parent, &area, "Add", (win_command_t)BUTTON_ID);	
	if (!button) {
		goto error_widget;
	}
	win_show(wtk_button_as_child(button));

	return true;

	/* Error handling to clean up allocations after an error */
error_widget:
	win_destroy(wtk_basic_frame_as_child(widget_ctx->frame));
error_frame:
	membag_free(widget_ctx);
	
	return false;
}
/**
 * \brief Setup widget demo
 *
 * This function launches the widget demo.
 */
void app_widget_launch()
{
	struct win_window *win_root;
	struct win_window *parent;
	struct win_area area;
	struct wtk_label *lbl;
	struct wtk_button *btn;

	/* Get pointer to root window */
	win_root = win_get_root();

	/* Application frame */

	/* Create a background bitmap using a solid color. */
	frame_background.type = GFX_BITMAP_SOLID;
	frame_background.data.color = APP_BACKGROUND_COLOR;

	/* Set the area to fill the entire screen */
	area.pos.x = 0;
	area.pos.y = 0;
	area.size.x = gfx_get_width();
	area.size.y = gfx_get_height();

	/*
	 * Create a basic frame with a specified background and command event
	 * handler. Check the return value if an error occurred while creating
	 * the widget.
	 */
	main_frame = wtk_basic_frame_create(win_root, &area,
			&frame_background, NULL,
			widget_frame_command_handler, NULL);
	if (!main_frame) {
		goto error_frame;
	}

	/* Get a pointer to the widget's window for adding sub-widgets. */
	parent = wtk_basic_frame_as_child(main_frame);

	/*
	 * Draw the frame by showing the frame widget's window. Any
	 * child-widgets and windows will not be shown before the parent
	 * widget/window is shown.
	 */
	win_show(parent);

	/* Application label */
	area.pos.x = LABEL_POS_X;
	area.pos.y = LABEL_POS_Y;
	/* Find an optimal size for the widget. */
	wtk_label_size_hint(&area.size, demo_string);

	/*
	 * Create the label and check the return value if an error occurred
	 * while creating the label.
	 */
	lbl = wtk_label_create(parent, &area, demo_string,
			GFX_COLOR(255, 255, 255), NULL, false);
	if (!lbl) {
		goto error_widget;
	}

	/* Draw the label by showing the label widget's window. */
	win_show(wtk_label_as_child(lbl));

	/* Application slider */
	area.pos.x = SLIDER_POS_X;
	area.pos.y = SLIDER_POS_Y;
	area.size.x = SLIDER_SIZE_X;
	area.size.y = SLIDER_SIZE_Y;

	/*
	 * Create the slider and check the return value if an error occurred
	 * while creating the slider.
	 */
	slider = wtk_slider_create(parent, &area, SLIDER_MAX_VALUE,
			SLIDER_MAX_VALUE / 2,
			WTK_SLIDER_HORIZONTAL | WTK_SLIDER_CMD_RELEASE,
			(win_command_t)SLIDER_ID);
	if (!slider) {
		goto error_widget;
	}

	/* Draw the slider by showing the slider widget's window. */
	win_show(wtk_slider_as_child(slider));

	/* Application progress bar, placed right of the slider. */
	area.pos.x += area.size.x + SLIDER_PB_SPACING_X;
	area.size.x = PB_SIZE_X;
	area.size.y = PB_SIZE_Y;

	/*
	 * Create the progress bar and check the return value if an error
	 * occurred while creating the progress bar.
	 */
	progress_bar = wtk_progress_bar_create(parent, &area, SLIDER_MAX_VALUE,
			SLIDER_MAX_VALUE / 2, GFX_COLOR(255, 255, 0),
			GFX_COLOR(90, 90, 90), WTK_PROGRESS_BAR_HORIZONTAL);
	if (!progress_bar) {
		goto error_widget;
	}

	/* Draw the progress bar by showing the progress bar widget's window. */
	win_show(wtk_progress_bar_as_child(progress_bar));

	/** \todo Add code to set up button here. */

	/** \todo Add code to set up basic frame here. */

	return;

error_widget:
	/* Destroy widget and all sub-widgets. */
	win_destroy(wtk_basic_frame_as_child(main_frame));
error_frame:
	/* Wait forever if an error occurred during setup. */
	while (1) {
	}
}
Ejemplo n.º 9
0
#endif

/* A message is posted each time the values goes outside the [-5,+5] interval
 * around the previous measure */
#define NB_INTERVALS 5

/** Demo bitmap used for PPT player */
static struct gfx_bitmap demo_ppt = {
	.width = 240, .height = 320,
	.type = GFX_BITMAP_EXT,
};

/** Demo background bitmap */
static struct gfx_bitmap win_root_background = {
	.type = GFX_BITMAP_SOLID,
	.data.color = GFX_COLOR(255, 255, 255),
};

/** Demo startup bitmap */
static struct gfx_bitmap win_startup_bmp = {
	.width = 240, .height = 240,
	.type = GFX_BITMAP_EXT,
	.data.custom = DEMO_BMP_INTRO_SAM4S
};

/* Handle to the semaphore protecting memories transfer. */
static xSemaphoreHandle main_trans_semphr = NULL;

/** Tick Counter united by ms */
static volatile uint32_t g_ul_tick_count = 0;
Ejemplo n.º 10
0
void battery_application() {
    draw_background();



    gfx_draw_string_aligned("Power Info", gfx_get_width() / 2, 2, &sysfont, GFX_COLOR_TRANSPARENT, GFX_COLOR_WHITE, TEXT_POS_CENTER_X, TEXT_ALIGN_LEFT);

    uint8_t battery = max1704x_bat();
    char batlvl[5];
    if (battery > 100) {
        battery = 100;
    }
    //battery = 19;
    uint16_t x =  75;
    uint16_t y = 40;

    gfx_draw_rect(x, y,  164, 54, GFX_COLOR_WHITE);
    gfx_draw_filled_rect(x+164, y+15, 3, 20, GFX_COLOR_WHITE);

    if (battery < 20) {
        gfx_draw_filled_rect(x+2, y+2, battery/6 * 10, 50, GFX_COLOR_RED);
    } else {
        gfx_draw_filled_rect(x+2, y+2, battery/6 * 10, 50, GFX_COLOR_GREEN);
    }


    snprintf(batlvl, sizeof(batlvl), "%d%%", battery);
    if (battery > 20) {
        gfx_draw_string_aligned(batlvl, gfx_get_width() /2, 50, &large_sysfont, GFX_COLOR_TRANSPARENT, GFX_COLOR_WHITE, TEXT_POS_CENTER_X, TEXT_ALIGN_LEFT);
    } else {
        gfx_draw_string_aligned(batlvl, gfx_get_width() /2, 50, &large_sysfont, GFX_COLOR_TRANSPARENT, GFX_COLOR_WHITE, TEXT_POS_CENTER_X, TEXT_ALIGN_LEFT);
    }

    char atime[32];
    snprintf(atime, sizeof(atime), "Seconds Awake:    %lu", get_time_awake());
    gfx_draw_string_aligned(atime, 70, 100, &sysfont, GFX_COLOR_TRANSPARENT, GFX_COLOR_WHITE, TEXT_POS_LEFT, TEXT_ALIGN_LEFT);

    char stime[32];
    snprintf(stime, sizeof(stime), "Seconds Sleeping: %lu", get_time_sleep());
    gfx_draw_string_aligned(stime, 70, 120, &sysfont, GFX_COLOR_TRANSPARENT, GFX_COLOR_WHITE, TEXT_POS_LEFT, TEXT_ALIGN_LEFT);

    gfx_draw_filled_circle(gfx_get_width() /2,  80+80+10+10, 25, GFX_COLOR_WHITE, GFX_WHOLE);
    gfx_draw_string_aligned(SYMFONT_MOON, gfx_get_width() /2, 152+10, &symbol_sysfont, GFX_COLOR_TRANSPARENT, GFX_COLOR(200, 101, 18), TEXT_POS_CENTER_X, TEXT_ALIGN_CENTER);
    gfx_draw_string_aligned("Enter Sleep Mode", gfx_get_width() / 2, 152+15+30+15, &sysfont, GFX_COLOR_TRANSPARENT, GFX_COLOR_WHITE, TEXT_POS_CENTER_X, TEXT_ALIGN_LEFT);


	struct keyboard_event input;
    while(mma8451_orientation() != 6) {
        esp8266_check_buffer();
        if(mma8451_clear_interrupt() && is_low_power()) {
            exit_low_power();
        }

        keyboard_get_key_state(&input);
        if (input.type == KEYBOARD_RELEASE) {
            if (input.keycode == KEYBOARD_B) {
                break;
            } else if (input.keycode == KEYBOARD_A) {
                esp8266_enter_standby();
                enter_low_power();
                break;
            }
        }
    }
}
gfx_color_t gfx_hx8347a_color(uint8_t r, uint8_t g, uint8_t b)
{
	return GFX_COLOR(r, g, b);
}