Commit 64805071 authored by Projects's avatar Projects

apps: Added a template for applications.

parent d9cb2636
#include <bitmaps.h>
static const uint8_t example_icon_data[] = {
0x2e,
0x81,
0x05,
0x81,
0x04,
0x81,
0x05,
0x82,
0x16,
0x80,
0x0d,
0x80,
0x0d,
0x80,
0x08,
0x80,
0x09,
0x80,
0x02,
0x80,
0x08,
0x81,
0x02,
0x81,
0x06,
0x81,
0x04,
0x83,
0x01,
0x82,
0x08,
0x83,
0x14};
const struct rle_bitmap example_icon = { 15, 15, example_icon_data };
static const uint8_t gps_receiving_data[] = {
0x06,
0x83,
......
......@@ -10,10 +10,11 @@ struct rle_bitmap
uint8_t *data;
};
extern const struct rle_bitmap example_icon;
extern const struct rle_bitmap gps_receiving;
extern const struct rle_bitmap battery;
extern const struct rle_bitmap gps_disconnected;
extern const struct rle_bitmap battery_charging;
extern const struct rle_bitmap gps_searching;
#endif BITMAPS_H
#endif /* BITMAPS_H */
......@@ -165,6 +165,7 @@ FreeRTOS/Source/portable/GCC/ARM_CM3/port.c \
src/apps/widgets/status_bar.c \
src/apps/application.c \
src/apps/clock.c \
src/apps/example_app.c \
src/apps/menu.c \
src/apps/menu_struct.c \
src/main.c \
......
......@@ -31,6 +31,7 @@
extern application menu;
extern application clock;
extern application example;
#endif /* APP_LIST_H */
/*
* Copyright (C) 2014 Julian Lewis
* @author Maciej Suminski <maciej.suminski@cern.ch>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* Application template.
*/
#include "application.h"
#include "widgets/status_bar.h"
#include <string.h> // for strcpy
static char message[32] = "hello world";
static void widget_redraw(struct ui_widget *w)
{
gfx_clear(&w->dc, 0);
gfx_text(&w->dc, &font_helv17b, 0, 0, message, 1);
}
static void widget_event(struct ui_widget *w, const struct event *evt)
{
// screen needs redrawing
w->flags |= WF_DIRTY;
switch(evt->type) {
case BUTTON_PRESSED:
switch(evt->data.button) {
case BUT_TR:
strcpy(message, "top right");
break;
case BUT_BR:
strcpy(message, "bottom right");
break;
case BUT_BL:
strcpy(message, "bottom left");
break;
case BUT_TL: // this should not happen, it is handled
break; // in the main loop
}
case RTC_TICK:
// commented out, because it interferes with other messages
//strcpy(message, "tick-tock");
break;
default: // suppress warnings
// ok, we do not need redrawing
w->flags &= ~WF_DIRTY;
break;
}
}
struct ui_widget widget = {
widget_redraw, // drawing function, called when widget is marked as dirty
widget_event, // event handler
{ 0, 20, 127, 59 }, // dimensions
0, // surface pointer; do not change
WF_ACTIVE | WF_VISIBLE // flags
};
struct ui_widget example_screen = { // main screen, contains all widgets
NULL,
NULL,
{ 0, 0, 127, 127 },
0,
WF_ACTIVE | WF_VISIBLE
};
void example_main(void* params) {
(void)(params); // suppress unused parameter warning
struct event evt;
// this is a good place for hardware initialization
// (configure interrupts, backlight settings, etc.)
// initialize user interface
ui_clear();
// initialize widgets before adding them
ui_init_widget(&example_screen);
ui_init_widget(&widget);
ui_add_widget(&widget);
// widget belongs to the main screen
ui_add_child(&example_screen, &widget);
ui_add_widget(&example_screen);
// if you want to have fullscreen just for you
// commenting the lines below will disable the status bar
ui_init_widget(&status_bar);
ui_add_widget(&status_bar);
// draw the screen for the first time
ui_update(NULL);
// event loop
while(1) {
// "0" in the line below, if you set it to a positive value then
// you may have a block of code that is executed when no event arrives
// for details, see below (else block)
if(xQueueReceive(appQueue, &evt, 0)) {
switch(evt.type) {
// decide which events are relevant and should be handled
// you may save some cycles if you list them here instead of
// lazily handling all of them
case BUTTON_PRESSED:
// current convention is to use the top left button to go back
if(evt.data.button == BUT_TL)
return; // go back to the main menu
// no break; fall through
case RTC_TICK: // there was no break, it handles BUTTON_PRESSED too
ui_update(&evt); // forward event to widgets
default: // suppress warnings
// ignore events that were not mentioned above
break;
}
}
else {
// that part is executed if timeout occurs
}
}
}
application example = {
.name = "Example", // this will be shown in menu
.main = example_main
};
/*
* Copyright (C) 2014 Julian Lewis
* @author Maciej Suminski <maciej.suminski@cern.ch>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* Clock application.
*/
#ifndef CLOCK_H
#define CLOCK_H
#include "application.h"
extern application clock;
#endif /* CLOCK_H */
......@@ -50,6 +50,7 @@ menu_list sub_menu = {
menu_list main_menu = {
"Main menu",
{
{ APP, &example_icon, { .app = &example } },
{ APP, &gps_receiving, { .app = &clock } },
{ APP, &battery_charging, { .app = &clock } },
{ SUBMENU, NULL, { .submenu = &sub_menu } },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment