Dilbert
Firmware for the Dilbert interactive badge.
 All Classes Files Functions Variables Enumerations Macros Pages
App.h
Go to the documentation of this file.
1 
3 #ifndef _APP_H_
4 #define _APP_H_
5 
6 #include <IButton.h>
7 
8 #include "AppManager.h"
9 
15 class App
16 {
17 public:
22  App(char *name)
23  : m_ready(false)
24  , m_backgroundColour(ILI9341_BLACK)
25  {
26  m_name = new char[strlen(name) + 1]();
27  strcpy(m_name, name);
28  }
29 
30  virtual ~App()
31  {
32  if (m_ready)
33  destroy();
34  }
35 
40  inline char *name()
41  {
42  return m_name;
43  }
44 
50  inline void setBackgroundColour(uint16_t colour)
51  {
52  m_backgroundColour = colour;
53  }
54 
60  virtual void create()
61  {
62  m_ready = true;
63  }
64 
70  virtual void onEntry()
71  {
72  if (!m_ready)
73  create();
74 
75  m_badge->display().fillScreen(m_backgroundColour);
76  }
77 
83  virtual void run()
84  {
85  delay(50);
86  }
87 
91  virtual void exit()
92  {
94  }
95 
101  virtual void onExit()
102  {
103  }
104 
110  virtual void destroy()
111  {
112  m_ready = false;
113  }
114 
115 protected:
121  virtual bool handleButton(IButton *button)
122  {
123  return false;
124  }
125 
126 protected:
127  friend class AppManager;
128 
131 
132  char *m_name;
133  bool m_ready;
134 
136 };
137 
138 #endif
char * m_name
Name of application.
Definition: App.h:132
bool m_ready
If the application has been created.
Definition: App.h:133
virtual void destroy()
Destroys the application.
Definition: App.h:110
Adafruit_ILI9341 & display()
Gets the TFT display driver.
Definition: Dilbert.h:44
AppManager * m_manager
Pointer to application manager.
Definition: App.h:130
Used to manage several applications on the badge.
Definition: AppManager.h:30
virtual void onEntry()
Called when the application is entered.
Definition: App.h:70
virtual void exit()
Exits the application.
Definition: App.h:91
virtual bool handleButton(IButton *button)
Handle button presses.
Definition: App.h:121
Main hardware abstraction class.
Definition: Dilbert.h:17
virtual void run()
Called in a loop while the application is active.
Definition: App.h:83
virtual void onExit()
Called when the application exits.
Definition: App.h:101
uint16_t m_backgroundColour
Background colour.
Definition: App.h:135
virtual void create()
Creates the application.
Definition: App.h:60
App(char *name)
Creates a new instance of a badge application.
Definition: App.h:22
char * name()
Gets the name of the application.
Definition: App.h:40
bool activateAppByIdx(uint8_t idx)
Activates an application given it's index.
Definition: AppManager.cpp:84
Dilbert * m_badge
Pointer to badge driver.
Definition: App.h:129
Used to encapsulate an individual application.
Definition: App.h:15
void setBackgroundColour(uint16_t colour)
Sets the background fill colour of the display for this application.
Definition: App.h:50