Atmel Software Framework

 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Plot widget

Modules

 Plot widget options
 These options can be ORed together to specify the behaviour of a plot widget when creating it with wtk_plot_create.
 
 Plot widget grid options
 These options can be ORed together to specify the behaviour of a plot widget grid when adjusting it via wtk_plot_set_grid.
 

Functions

bool wtk_plot_add_value (struct wtk_plot *plot, uint8_t value)
 Add a value to the end of the plot. More...
 
struct win_windowwtk_plot_as_child (struct wtk_plot *plot)
 Get pointer to plot window. More...
 
struct wtk_plotwtk_plot_create (struct win_window *parent, struct win_area const *area, uint8_t maximum, uint8_t datapoints, gfx_color_t draw_color, struct gfx_bitmap *background, uint8_t option)
 Create a new plot widget. More...
 
void wtk_plot_set_colors (struct wtk_plot *plot, gfx_color_t draw_color, struct gfx_bitmap *background)
 Set new plot colors. More...
 
void wtk_plot_set_grid (struct wtk_plot *plot, uint8_t axis_option, uint8_t axis_spacing_x, uint8_t axis_offset_x, uint8_t axis_spacing_y, uint8_t axis_offset_y, gfx_color_t axis_color, gfx_color_t axis_zero_color)
 Set grid/axis parameters. More...
 
static void wtk_plot_grid_draw (struct wtk_plot *plot, struct win_area const *area, struct win_clip_region const *clip)
 Grid draw function. More...
 
static void wtk_plot_draw (struct wtk_plot *plot, struct win_area const *area, struct win_clip_region const *clip)
 Plot draw function. More...
 
static bool wtk_plot_handler (struct win_window *win, enum win_event_type type, void const *data)
 plot event handler. More...
 

bool wtk_plot_add_value ( struct wtk_plot plot,
uint8_t  value 
)

Add a value to the end of the plot.

Scales the input value to fit the plot dimensions and adds it to the end of the ring buffer.

Parameters
plotPointer to wtk_plot struct to set new value for.
valueNew value for the plot.
Returns
True.

References Assert, wtk_plot::buffer_start, wtk_plot::container, wtk_plot::maximum, maximum(), wtk_plot::num_datapoints, wtk_plot::plot_buffer, win_area::size, win_get_area(), wtk_rescale_value(), and win_point::y.

struct win_window* wtk_plot_as_child ( struct wtk_plot plot)

Get pointer to plot window.

Returns a reference to the window that should be used when managing the widget, such as destroying, moving or reparenting it.

Parameters
plotPointer to wtk_plot struct to manage.
Returns
Pointer to window to be used for managing the plot.

References Assert, and wtk_plot::container.

struct wtk_plot* wtk_plot_create ( struct win_window parent,
struct win_area const *  area,
uint8_t  maximum,
uint8_t  num_datapoints,
gfx_color_t  draw_color,
struct gfx_bitmap background,
uint8_t  option 
)

Create a new plot widget.

Allocates the necessary memory and intializes the window and data for plot widgets. If there is not enough memory, the function returns NULL.
To destroy a plot widget and all its contents, and free its memory, call win_destroy() on the plot's child reference, given by wtk_plot_as_child(), similar to:

The plotted graph will shift from right to left as new data values are added. Data values will be overwritten in the ring buffer as they shift out of the plot window. The maximum parameter scales the input value to fit the plot dimensions.

The num_datapoints parameter must not exceed the maximum membag size, and never over 255.

Refer to <gfx/wtk.h> for available configuration options.

Parameters
parentPointer to parent win_window struct.
areaPointer to win_area struct with position and size of the plot. Minimum size in both x and y direction is 4 pixels.
maximumMaximum value of the plot.
num_datapointsNumber of datapoints of the plot.
draw_colorPlot drawing color.
backgroundPointer to background bitmap for frame. NULL for transparent background. When background is transparent the parent window will automatically be redrawn when the basic frame is drawn.
optionConfiguration options for plot.
Returns
Pointer to new plot, if memory allocation was successful.

References win_attributes::area, Assert, wtk_plot::axis_color, wtk_plot::axis_offset_x, wtk_plot::axis_offset_y, wtk_plot::axis_option, wtk_plot::axis_spacing_x, wtk_plot::axis_spacing_y, wtk_plot::axis_zero_color, wtk_plot::background, win_attributes::background, win_attributes::behavior, wtk_plot::buffer_start, wtk_plot::container, win_attributes::custom, wtk_plot::draw_color, win_attributes::event_handler, length, wtk_plot::maximum, maximum(), membag_alloc(), membag_free(), NULL, wtk_plot::num_datapoints, wtk_plot::option, option, wtk_plot::plot_buffer, win_area::size, wtk_plot::spacing, wtk_plot::spacing_error, WIN_BEHAVIOR_REDRAW_PARENT, win_create(), WTK_PLOT_DONT_REDRAW_PARENT, wtk_plot_handler(), win_point::x, and win_point::y.

static void wtk_plot_draw ( struct wtk_plot plot,
struct win_area const *  area,
struct win_clip_region const *  clip 
)
static

Plot draw function.

Draws the plot itself.

Parameters
plotPointer to wtk_plot struct to draw.
areaPointer to win_area struct with position and size of the plot.
clipPointer to win_clip_region.

Called by the event handler to draw the plot.

References wtk_plot::buffer_start, wtk_plot::draw_color, gfx_draw_line, wtk_plot::num_datapoints, wtk_plot::option, option, win_clip_region::origin, wtk_plot::plot_buffer, win_area::size, wtk_plot::spacing, wtk_plot::spacing_error, WTK_PLOT_INVERT, WTK_PLOT_RIGHT_TO_LEFT, win_point::x, and win_point::y.

Referenced by wtk_plot_handler().

static void wtk_plot_grid_draw ( struct wtk_plot plot,
struct win_area const *  area,
struct win_clip_region const *  clip 
)
static

Grid draw function.

Draws the grid or axis, and zero line based on options.

Parameters
plotPointer to wtk_plot struct to draw.
areaPointer to win_area struct with position and size of the plot.
clipPointer to win_clip_region.

Called by the event handler to draw the grid.

References wtk_plot::axis_color, wtk_plot::axis_offset_x, wtk_plot::axis_offset_y, wtk_plot::axis_option, wtk_plot::axis_spacing_x, wtk_plot::axis_spacing_y, wtk_plot::axis_zero_color, gfx_draw_line, win_clip_region::origin, win_area::size, WTK_PLOT_GRID_HORIZONTAL, WTK_PLOT_GRID_VERTICAL, WTK_PLOT_TICKS_HORIZONTAL, WTK_PLOT_TICKS_VERTICAL, WTK_PLOT_ZERO, win_point::x, and win_point::y.

Referenced by wtk_plot_handler().

static bool wtk_plot_handler ( struct win_window win,
enum win_event_type  type,
void const *  data 
)
static

plot event handler.

This is the window event handler for plot widgets. It handles the two relevant event types sent to a plot's container window, i.e., drawing, and destroy events.

Parameters
winWindow receiving the event.
typeThe event type.
dataCustom data, depending on event type.
Returns
True if the event was recognized and accepted.

References Assert, wtk_plot::background, wtk_plot::container, gfx_draw_rect, membag_free(), NULL, win_clip_region::origin, wtk_plot::plot_buffer, win_area::size, WIN_EVENT_DESTROY, WIN_EVENT_DRAW, win_get_area(), win_get_custom_data(), wtk_plot_draw(), wtk_plot_grid_draw(), win_point::x, and win_point::y.

Referenced by wtk_plot_create().

void wtk_plot_set_colors ( struct wtk_plot plot,
gfx_color_t  draw_color,
struct gfx_bitmap background 
)

Set new plot colors.

This sets new draw and background colors for the plot.

Parameters
plotPointer to wtk_plot struct to set colors for.
draw_colorDraw color to set for plot.
backgroundBackground color to set for plot.

References Assert, wtk_plot::background, and wtk_plot::draw_color.

void wtk_plot_set_grid ( struct wtk_plot plot,
uint8_t  axis_option,
uint8_t  axis_spacing_x,
uint8_t  axis_offset_x,
uint8_t  axis_spacing_y,
uint8_t  axis_offset_y,
gfx_color_t  axis_color,
gfx_color_t  axis_zero_color 
)

Set grid/axis parameters.

This function sets the grid and axis options, colors for the plot. The axis_spacing_y and axis_offset_y parameter is rescaled to fit the plot. Both grid and axis can not be used on the same plot.

Refer to <gfx/wtk.h> for available configuration options.

Parameters
plotPointer to wtk_plot struct to set colors for.
axis_optionConfiguration of axis, grid and zero-line behaviour.
axis_spacing_xSpace between x-axis grid lines/tick marks.
axis_offset_xGrid/axis offset along the x-axis.
axis_spacing_ySpace between y-axis grid lines/tick marks.
axis_offset_yGrid/axis offset along the y-axis.
axis_colorColor for the tick marks and grid lines.
axis_zero_colorColor for the zero line.

References Assert, wtk_plot::axis_color, wtk_plot::axis_offset_x, wtk_plot::axis_offset_y, wtk_plot::axis_option, wtk_plot::axis_spacing_x, wtk_plot::axis_spacing_y, wtk_plot::axis_zero_color, wtk_plot::container, wtk_plot::maximum, win_area::size, win_get_area(), wtk_rescale_value(), and win_point::y.