Dilbert
Firmware for the Dilbert interactive badge.
 All Classes Files Functions Variables Enumerations Macros Pages
AppManager.h
Go to the documentation of this file.
1 
3 #ifndef _APPMANAGER_H_
4 #define _APPMANAGER_H_
5 
6 #include <Arduino.h>
7 #include <IButton.h>
8 #include <IInputDevice.h>
9 #include <IUniversalInputCallback.h>
10 #include <UniversalInputTypes.h>
11 
12 #include "Dilbert.h"
13 
17 #define MAX_NUM_APPS 16
18 
19 #define BACKLIGHT_STATE_FULL 2
20 #define BACKLIGHT_STATE_DIM 1
21 #define BACKLIGHT_STATE_OFF 0
22 
23 class App;
24 
30 class AppManager : public IUniversalInputCallback
31 {
32 public:
34  virtual ~AppManager();
35 
36  void begin();
37 
38  uint8_t addApp(App *app);
39 
40  bool activateAppByName(char *name);
41  bool activateAppByIdx(uint8_t idx);
42 
43  uint8_t appIdx(char *name);
44  uint8_t appIdx(App *app) const;
45 
51  inline App *app(uint8_t idx)
52  {
53  return m_apps[idx];
54  }
55 
56  size_t numApps() const;
57 
62  inline App *activeApp()
63  {
64  return m_apps[m_activeAppIdx];
65  }
66 
67  void feedBacklight(uint8_t status = BACKLIGHT_STATE_FULL);
68 
69  void run();
70 
71  void handleUniversalInputEvent(inputtype_t type, IInputDevice *device);
72 
73 private:
74  void updateBacklightOutput();
75 
76 private:
77  Dilbert *m_badge;
78  App *m_apps[MAX_NUM_APPS];
79  char *m_appNames[MAX_NUM_APPS];
80  uint8_t m_activeAppIdx;
81 
82  IButton *m_bButton;
83  bool m_appExitFlag;
84 
85  uint8_t m_backlightStatus;
86  uint32_t m_lastBacklightFeedTime;
87 };
88 
89 #endif
void handleUniversalInputEvent(inputtype_t type, IInputDevice *device)
Handles a state change of an input device.
Definition: AppManager.cpp:213
App * activeApp()
Gets the active application.
Definition: AppManager.h:62
uint8_t addApp(App *app)
Adds an application to the manager.
Definition: AppManager.cpp:52
#define MAX_NUM_APPS
Maximum number of apps that can be registered with the manager.
Definition: AppManager.h:17
Used to manage several applications on the badge.
Definition: AppManager.h:30
App * app(uint8_t idx)
Gets an application given it's index.
Definition: AppManager.h:51
AppManager(Dilbert *badge)
Creates a new application manager.
Definition: AppManager.cpp:12
void run()
Runs the loop of the active application.
Definition: AppManager.cpp:168
Dilbert badge
Badge driver.
Definition: main.cpp:35
Main hardware abstraction class.
Definition: Dilbert.h:17
bool activateAppByName(char *name)
Activates an application given it's name.
Definition: AppManager.cpp:73
void begin()
Initialises the application manager.
Definition: AppManager.cpp:29
size_t numApps() const
Gets the number of applications in the manager.
Definition: AppManager.cpp:136
bool activateAppByIdx(uint8_t idx)
Activates an application given it's index.
Definition: AppManager.cpp:84
uint8_t appIdx(char *name)
Gets the index of an app given it's name.
Definition: AppManager.cpp:105
Used to encapsulate an individual application.
Definition: App.h:15
void feedBacklight(uint8_t status=BACKLIGHT_STATE_FULL)
Ensures that the backlight stays on, otherwise it is susceptible to the timeouts set in SystemConfigD...
Definition: AppManager.cpp:152