Microchip® Advanced Software Framework

paint_demo.c File Reference

mXT143E Xplained paint demo application

Copyright (c) 2012-2018 Microchip Technology Inc. and its subsidiaries.

#include <asf.h>
#include <stdio.h>

Macros

#define MAXTOUCH_TWI_ADDRESS   0x4a
 Address of the mXT143E on TWI bus. More...
 
#define MULTI_COLOR_INCREMENT   4
 Color increment/decrement amount when in multi-color mode; larger values will cause the colors to cycle faster. More...
 
#define NUM_PALLET_COLORS   (sizeof(pallet_colors) / sizeof(pallet_colors[0]))
 Number of colors in the pallet (computed automatically from number of entries in the pallet_colors[] array) More...
 
#define PALLET_COLOR_WIDTH   (gfx_get_width() / NUM_PALLET_COLORS)
 Width of each color entry in the pallet on the display. More...
 
#define PALLET_HEIGHT   22
 Height of the pallet on the display. More...
 

Functions

static void draw_paint_pallet (void)
 Draws the color pallet to the display. More...
 
static void draw_pallet_labels (const bool clearing_display)
 Draws the special function pallet entry text labels. More...
 
static gfx_color_t get_next_rainbow_color (void)
 Compute the next rainbow color for multi-color drawing mode. More...
 
int main (void)
 Main application loop. More...
 
static void mxt_handler (struct mxt_device *device)
 Handle maXTouch messages. More...
 
static void mxt_init (struct mxt_device *device)
 Set maXTouch configuration. More...
 
static void update_pallet_selection (void)
 Updates the color pallet to the display. More...
 

Variables

const gfx_color_t pallet_colors []
 Color pallet for the application; add or remove colors here to update the pallet in the application. More...
 
uint8_t selected_pallet_color = 0
 Pallet index of the currently selected color by the user. More...
 

#define MAXTOUCH_TWI_ADDRESS   0x4a

Address of the mXT143E on TWI bus.

Referenced by mxt_init().

#define MULTI_COLOR_INCREMENT   4

Color increment/decrement amount when in multi-color mode; larger values will cause the colors to cycle faster.

Referenced by get_next_rainbow_color().

#define NUM_PALLET_COLORS   (sizeof(pallet_colors) / sizeof(pallet_colors[0]))

Number of colors in the pallet (computed automatically from number of entries in the pallet_colors[] array)

Referenced by draw_paint_pallet(), draw_pallet_labels(), and mxt_handler().

#define PALLET_COLOR_WIDTH   (gfx_get_width() / NUM_PALLET_COLORS)

Width of each color entry in the pallet on the display.

Referenced by draw_paint_pallet(), draw_pallet_labels(), mxt_handler(), and update_pallet_selection().

#define PALLET_HEIGHT   22

Height of the pallet on the display.

Referenced by draw_paint_pallet(), draw_pallet_labels(), main(), mxt_handler(), and update_pallet_selection().

static void draw_paint_pallet ( void  )
static

Draws the color pallet to the display.

This function draws the paint pallet to the display, including the special function entries (such as display clear) and the selection box.

References draw_pallet_labels(), GFX_COLOR_GRAY, gfx_draw_filled_rect, gfx_draw_horizontal_line, gfx_get_height(), gfx_get_width(), NUM_PALLET_COLORS, PALLET_COLOR_WIDTH, pallet_colors, PALLET_HEIGHT, and update_pallet_selection().

Referenced by main().

static void draw_pallet_labels ( const bool  clearing_display)
static

Draws the special function pallet entry text labels.

This function draws the special function pallet entry text labels to the appropriate positions on the display.

Parameters
clearing_displayTrue if the display is currently being cleared

References GFX_COLOR_RED, GFX_COLOR_TRANSPARENT, GFX_COLOR_WHITE, gfx_draw_string_aligned(), gfx_get_height(), NUM_PALLET_COLORS, PALLET_COLOR_WIDTH, PALLET_HEIGHT, sysfont, TEXT_ALIGN_LEFT, and TEXT_POS_CENTER.

Referenced by draw_paint_pallet(), and mxt_handler().

static gfx_color_t get_next_rainbow_color ( void  )
static

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.

Returns
The next color in the rainbow sequence as a gfx_color_t.

References GFX_COLOR, and MULTI_COLOR_INCREMENT.

Referenced by mxt_handler().

int main ( void  )

Main application loop.

This is the main application function, which runs all the initialization code, clears the display and enters a loop in which it continuously polls for new messages from the maXTouch device. If one or more messages are pending, the maXTouch message handler is invoked.

References board_init(), draw_paint_pallet(), GFX_COLOR_TRANSPARENT, GFX_COLOR_WHITE, gfx_draw_string_aligned(), gfx_get_height(), gfx_get_width(), gfx_init, mxt_handler(), mxt_init(), mxt_is_message_pending(), PALLET_HEIGHT, sysclk_init(), sysfont, TEXT_ALIGN_LEFT, and TEXT_POS_CENTER.

static void mxt_handler ( struct mxt_device device)
static
static void mxt_init ( struct mxt_device device)
static
static void update_pallet_selection ( void  )
static

Updates the color pallet to the display.

This function should be called whenever a new color is selected on the pallet. It will then move the selection box to the newly chosen color.

References GFX_COLOR_GRAY, gfx_draw_rect, gfx_get_height(), PALLET_COLOR_WIDTH, pallet_colors, PALLET_HEIGHT, and selected_pallet_color.

Referenced by draw_paint_pallet(), and mxt_handler().

const gfx_color_t pallet_colors[]
Initial value:
= {
0,
0,
}
#define GFX_COLOR_GREEN
Definition: gfx.h:160
#define GFX_COLOR_WHITE
Definition: gfx.h:156
#define GFX_COLOR_BLACK
Definition: gfx.h:155
#define GFX_COLOR_YELLOW
Definition: gfx.h:166
#define GFX_COLOR_MAGENTA
Definition: gfx.h:164
#define GFX_COLOR_CYAN
Definition: gfx.h:168
#define GFX_COLOR_RED
Definition: gfx.h:158
#define GFX_COLOR_BLUE
Definition: gfx.h:162

Color pallet for the application; add or remove colors here to update the pallet in the application.

Referenced by draw_paint_pallet(), mxt_handler(), and update_pallet_selection().

uint8_t selected_pallet_color = 0

Pallet index of the currently selected color by the user.

Referenced by mxt_handler(), and update_pallet_selection().