SSD1306 OLED display driver  1.6.99
This library is developed to control SSD1306/SSD1331/SSD1351/IL9163/PCD8554 RGB i2c/spi LED displays
core.h
Go to the documentation of this file.
1 /*
2  MIT License
3 
4  Copyright (c) 2018, Alexey Dynda
5 
6  Permission is hereby granted, free of charge, to any person obtaining a copy
7  of this software and associated documentation files (the "Software"), to deal
8  in the Software without restriction, including without limitation the rights
9  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  copies of the Software, and to permit persons to whom the Software is
11  furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in all
14  copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  SOFTWARE.
23 */
29 #ifndef _NANO_ENGINE_CORE_H_
30 #define _NANO_ENGINE_CORE_H_
31 
32 #include "tiler.h"
33 #include "canvas.h"
34 
36 typedef uint8_t (*TNanoEngineGetButtons)(void);
37 
39 typedef void (*TLoopCallback)(void);
40 
44 
45 enum
46 {
47  BUTTON_NONE = 0B00000000,
48  BUTTON_DOWN = 0B00000001,
49  BUTTON_LEFT = 0B00000010,
50  BUTTON_RIGHT = 0B00000100,
51  BUTTON_UP = 0B00001000,
52  BUTTON_A = 0B00010000,
53  BUTTON_B = 0B00100000,
54 };
55 
60 {
61 protected:
66 public:
73  static bool pressed(uint8_t buttons);
74 
81  static bool notPressed(uint8_t buttons);
82 
87  static uint8_t buttonsState()
88  {
89  return m_onButtons();
90  }
91 
96  static void connectCustomKeys(TNanoEngineGetButtons handler);
97 
103  static void connectZKeypad(uint8_t analogPin);
104 
109  static void connectArduboyKeys();
110 
111 protected:
114 
115 private:
116  static uint8_t s_zkeypadPin;
117  static uint8_t zkeypadButtons();
118  static uint8_t arduboyButtons();
119 };
120 
121 
125 
130 {
131 protected:
133 
134 public:
138  static void begin();
139 
144  static void setFrameRate(uint8_t fps);
145 
149  static uint8_t getFrameRate() { return m_fps; };
150 
157  static uint8_t getCpuLoad() { return m_cpuLoad; };
158 
162  static bool nextFrame();
163 
168  static void loopCallback(TLoopCallback callback) { m_loop = callback; };
169 
170 protected:
171 
173  static uint8_t m_frameDurationMs;
175  static uint8_t m_fps;
177  static uint8_t m_cpuLoad;
179  static uint32_t m_lastFrameTs;
182 };
183 
187 template<class C, uint8_t W, uint8_t H, uint8_t B>
189  public NanoEngineTiler<C,W,H,B>
190 {
191 public:
195  NanoEngine();
196 
203  static void display();
204 
209  static void begin();
210 
216  static void notify(const char *str);
217 
218 protected:
219 };
220 
221 template<class C, uint8_t W, uint8_t H, uint8_t B>
223  : NanoEngineCore(), NanoEngineTiler<C,W,H,B>()
224 {
225 }
226 
227 template<class C, uint8_t W, uint8_t H, uint8_t B>
229 {
230  m_lastFrameTs = millis();
232  m_cpuLoad = ((millis() - m_lastFrameTs)*100)/m_frameDurationMs;
233 }
234 
235 template<class C, uint8_t W, uint8_t H, uint8_t B>
237 {
239  if (C::BITS_PER_PIXEL > 1)
240  {
242  }
243 }
244 
245 template<class C, uint8_t W, uint8_t H, uint8_t B>
246 void NanoEngine<C,W,H,B>::notify(const char *str)
247 {
249  delay(1000);
250  m_lastFrameTs = millis();
252 }
253 
254 
255 #endif
256 
void ssd1306_setMode(lcd_mode_t mode)
Sets library display mode for direct draw functions.
Definition: lcd_common.c:74
void(* TLoopCallback)(void)
Definition: core.h:39
static TLoopCallback m_loop
Definition: core.h:181
static void connectZKeypad(uint8_t analogPin)
Enables engine to use Z-Keypad. Enables engine to use Z-Keypad. Please refer to arkanoid example for ...
static void connectArduboyKeys()
Configures NanoEngine8 to use Arduboy keys layout. Configures NanoEngine8 to use Arduboy keys layout...
static bool pressed(uint8_t buttons)
Returns true if button or specific combination of buttons is not pressed. Returns true if button or s...
static uint8_t m_fps
Definition: core.h:175
static void refresh()
Definition: tiler.h:91
static void connectCustomKeys(TNanoEngineGetButtons handler)
static void begin()
Definition: core.h:236
uint8_t(* TNanoEngineGetButtons)(void)
Definition: core.h:36
static void begin()
static uint8_t m_cpuLoad
Definition: core.h:177
static uint32_t m_lastFrameTs
Definition: core.h:179
static uint8_t buttonsState()
Returns bits of all pressed buttons Returns bits of all pressed buttons.
Definition: core.h:87
NanoEngine()
Definition: core.h:222
static uint8_t getFrameRate()
Definition: core.h:149
static uint8_t getCpuLoad()
Definition: core.h:157
static void displayBuffer()
refreshes content on oled display. Refreshes content on oled display. Call it, if you want to update ...
Definition: tiler.h:195
static void displayPopup(const char *msg)
prints popup message over display content prints popup message over display content ...
Definition: tiler.h:219
static bool notPressed(uint8_t buttons)
Returns true if button or specific combination of buttons is not pressed. Returns true if button or s...
static void notify(const char *str)
shows notification to a user for 1 seconds Shows notification to a user for 1 seconds ...
Definition: core.h:246
NanoEngineInputs()
Definition: core.h:65
static uint8_t m_frameDurationMs
Definition: core.h:168
static void display()
refreshes content on oled display. Refreshes content on oled display. Call it, if you want to update ...
Definition: core.h:228
static TNanoEngineGetButtons m_onButtons
Definition: core.h:113