Dilbert
Firmware for the Dilbert interactive badge.
 All Classes Files Functions Variables Enumerations Macros Pages
NeoTestApp.h
Go to the documentation of this file.
1 
3 #ifndef _NEOTESTAPP_H_
4 #define _NEOTESTAPP_H_
5 
6 #include "RainbowChase.h"
7 #include "RainbowCycle.h"
8 #include <Adafruit_NeoPixel.h>
9 #include <App.h>
10 
11 class NeoTestApp : public App
12 {
13 public:
14  static const size_t PATTERN_COUNT = 2;
15 
16 public:
17  NeoTestApp()
18  : App("NeoTestApp")
19  {
20  }
21 
22  ~NeoTestApp()
23  {
24  }
25 
29  void create()
30  {
31  m_patterns[0] = new RainbowCycle(m_badge->neoPixels(), 20);
32  m_patterns[1] = new RainbowChase(m_badge->neoPixels(), 50);
33  m_currentPattern = 0;
34  }
35 
39  void onEntry()
40  {
41  App::onEntry();
42 
43  /* Clear the screen */
44  m_badge->display().fillScreen(ILI9341_BLACK);
45 
46  /* Set font style */
47  /* It is important for each app to do this here */
48  m_badge->display().setCursor(0, 0);
49  m_badge->display().setTextColor(ILI9341_PINK);
50  m_badge->display().setTextSize(2);
51  m_badge->display().println(m_name);
52  m_badge->display().setTextSize(1);
53  m_badge->display().print("The classic\nNeopixel strandtest\napp.\n\n");
54  m_badge->display().println("Long press B to return to app menu.\n");
55  }
56 
60  void destroy()
61  {
62  for (size_t i = 0; i < PATTERN_COUNT; i++)
63  {
64  if (m_patterns[i])
65  delete m_patterns[i];
66  }
67  }
68 
72  bool handleButton(IButton *button)
73  {
74  if (App::handleButton(button))
75  return true;
76 
77  if (!button->isActive())
78  { // button released
79  if (button->lastActiveDuration() < 800)
80  { // short press
81  if (button->getID() == 1)
82  { // up
83  m_patterns[m_currentPattern]->setBrightness(m_patterns[m_currentPattern]->getBrightness() + 10);
84  }
85  if (button->getID() == 2)
86  { // down
87  m_patterns[m_currentPattern]->setBrightness(m_patterns[m_currentPattern]->getBrightness() - 10);
88  }
89  if (button->getID() == 0)
90  { // left
91  m_patterns[m_currentPattern]->setBrightness(m_patterns[m_currentPattern]->getBrightness() - 1);
92  }
93  if (button->getID() == 3)
94  { // right
95  m_patterns[m_currentPattern]->setBrightness(m_patterns[m_currentPattern]->getBrightness() + 1);
96  }
97  }
98  else
99  { // long press
100  if (button->getID() == 1)
101  { // up
102  m_currentPattern++;
103  }
104  if (button->getID() == 2)
105  { // down
106  m_currentPattern--;
107  }
108  m_currentPattern = m_currentPattern >= PATTERN_COUNT
109  ? PATTERN_COUNT - 1
110  : m_currentPattern = m_currentPattern < 0 ? 0 : m_currentPattern;
111  }
112  }
113 
114  return true;
115  }
116 
120  void run()
121  {
122  m_patterns[m_currentPattern]->run();
123  }
124 
128  void onExit()
129  {
130  App::onExit();
131 
132  m_badge->neoPixels().setBrightness(0);
133  m_badge->neoPixels().show();
134  }
135 
136 private:
137  int m_currentPattern = 0;
138  NPPattern *m_patterns[PATTERN_COUNT];
139 };
140 
141 #endif
char * m_name
Name of application.
Definition: App.h:132
Definition: RainbowCycle.h:8
Definition: RainbowChase.h:8
bool handleButton(IButton *button)
Definition: NeoTestApp.h:72
Adafruit_ILI9341 & display()
Gets the TFT display driver.
Definition: Dilbert.h:44
void onExit()
Definition: NeoTestApp.h:128
virtual void onEntry()
Called when the application is entered.
Definition: App.h:70
Definition: NPPattern.h:6
virtual bool handleButton(IButton *button)
Handle button presses.
Definition: App.h:121
virtual void onExit()
Called when the application exits.
Definition: App.h:101
App(char *name)
Creates a new instance of a badge application.
Definition: App.h:22
void run()
Definition: NeoTestApp.h:120
void onEntry()
Definition: NeoTestApp.h:39
void destroy()
Definition: NeoTestApp.h:60
void create()
Definition: NeoTestApp.h:29
Adafruit_NeoPixel & neoPixels()
Gets the NeoPixel LED driver.
Definition: Dilbert.h:67
Dilbert * m_badge
Pointer to badge driver.
Definition: App.h:129
Definition: NeoTestApp.h:11
Used to encapsulate an individual application.
Definition: App.h:15