mirror of https://github.com/meshcore-dev/MeshCore
26 changed files with 836 additions and 319 deletions
@ -0,0 +1,118 @@ |
|||||
|
#pragma once |
||||
|
|
||||
|
#include <stdint.h> |
||||
|
|
||||
|
// 'meshcore', 128x13px
|
||||
|
static const uint8_t meshcore_logo [] = { |
||||
|
0x3c, 0x01, 0xe3, 0xff, 0xc7, 0xff, 0x8f, 0x03, 0x87, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, |
||||
|
0x3c, 0x03, 0xe3, 0xff, 0xc7, 0xff, 0x8e, 0x03, 0x8f, 0xfe, 0x3f, 0xfe, 0x1f, 0xff, 0x1f, 0xfe, |
||||
|
0x3e, 0x03, 0xc3, 0xff, 0x8f, 0xff, 0x0e, 0x07, 0x8f, 0xfe, 0x7f, 0xfe, 0x1f, 0xff, 0x1f, 0xfc, |
||||
|
0x3e, 0x07, 0xc7, 0x80, 0x0e, 0x00, 0x0e, 0x07, 0x9e, 0x00, 0x78, 0x0e, 0x3c, 0x0f, 0x1c, 0x00, |
||||
|
0x3e, 0x0f, 0xc7, 0x80, 0x1e, 0x00, 0x0e, 0x07, 0x1e, 0x00, 0x70, 0x0e, 0x38, 0x0f, 0x3c, 0x00, |
||||
|
0x7f, 0x0f, 0xc7, 0xfe, 0x1f, 0xfc, 0x1f, 0xff, 0x1c, 0x00, 0x70, 0x0e, 0x38, 0x0e, 0x3f, 0xf8, |
||||
|
0x7f, 0x1f, 0xc7, 0xfe, 0x0f, 0xff, 0x1f, 0xff, 0x1c, 0x00, 0xf0, 0x0e, 0x38, 0x0e, 0x3f, 0xf8, |
||||
|
0x7f, 0x3f, 0xc7, 0xfe, 0x0f, 0xff, 0x1f, 0xff, 0x1c, 0x00, 0xf0, 0x1e, 0x3f, 0xfe, 0x3f, 0xf0, |
||||
|
0x77, 0x3b, 0x87, 0x00, 0x00, 0x07, 0x1c, 0x0f, 0x3c, 0x00, 0xe0, 0x1c, 0x7f, 0xfc, 0x38, 0x00, |
||||
|
0x77, 0xfb, 0x8f, 0x00, 0x00, 0x07, 0x1c, 0x0f, 0x3c, 0x00, 0xe0, 0x1c, 0x7f, 0xf8, 0x38, 0x00, |
||||
|
0x73, 0xf3, 0x8f, 0xff, 0x0f, 0xff, 0x1c, 0x0e, 0x3f, 0xf8, 0xff, 0xfc, 0x70, 0x78, 0x7f, 0xf8, |
||||
|
0xe3, 0xe3, 0x8f, 0xff, 0x1f, 0xfe, 0x3c, 0x0e, 0x3f, 0xf8, 0xff, 0xfc, 0x70, 0x3c, 0x7f, 0xf8, |
||||
|
0xe3, 0xe3, 0x8f, 0xff, 0x1f, 0xfc, 0x3c, 0x0e, 0x1f, 0xf8, 0xff, 0xf8, 0x70, 0x3c, 0x7f, 0xf8, |
||||
|
}; |
||||
|
|
||||
|
static const uint8_t bluetooth_on[] = { |
||||
|
0x00, 0x00, 0x00, 0x00, |
||||
|
0x00, 0x00, 0x00, 0x00, |
||||
|
0x00, 0x00, 0x00, 0x00, |
||||
|
0x00, 0x30, 0x00, 0x00, |
||||
|
0x00, 0x3C, 0x00, 0x00, |
||||
|
0x00, 0x3E, 0x00, 0x00, |
||||
|
0x00, 0x3F, 0x80, 0x00, |
||||
|
0x00, 0x3F, 0xC0, 0x00, |
||||
|
0x00, 0x3B, 0xE0, 0x00, |
||||
|
0x30, 0x38, 0xF8, 0x00, |
||||
|
0x3C, 0x38, 0x7C, 0x00, |
||||
|
0x3E, 0x38, 0x7C, 0x00, |
||||
|
0x1F, 0xB8, 0xF8, 0x70, |
||||
|
0x07, 0xF9, 0xF0, 0x78, |
||||
|
0x03, 0xFF, 0xC0, 0x78, |
||||
|
0x00, 0xFF, 0x80, 0x3C, |
||||
|
0x00, 0x7F, 0x07, 0x1C, |
||||
|
0x00, 0x7E, 0x07, 0x1C, |
||||
|
0x03, 0xFF, 0x82, 0x1C, |
||||
|
0x03, 0xFF, 0xC0, 0x78, |
||||
|
0x07, 0xFB, 0xE0, 0x78, |
||||
|
0x0F, 0xB8, 0xF8, 0x70, |
||||
|
0x3E, 0x38, 0x7C, 0x00, |
||||
|
0x3C, 0x38, 0x7C, 0x00, |
||||
|
0x38, 0x38, 0xF8, 0x00, |
||||
|
0x00, 0x39, 0xF0, 0x00, |
||||
|
0x00, 0x3F, 0xC0, 0x00, |
||||
|
0x00, 0x3F, 0x80, 0x00, |
||||
|
0x00, 0x3E, 0x00, 0x00, |
||||
|
0x00, 0x3C, 0x00, 0x00, |
||||
|
0x00, 0x38, 0x00, 0x00, |
||||
|
0x00, 0x00, 0x00, 0x00, |
||||
|
}; |
||||
|
|
||||
|
static const uint8_t bluetooth_off[] = { |
||||
|
0x00, 0x00, 0x00, 0x00, |
||||
|
0x00, 0x00, 0x00, 0x00, |
||||
|
0x00, 0x03, 0x80, 0x00, |
||||
|
0x00, 0x03, 0xC0, 0x00, |
||||
|
0x00, 0x03, 0xE0, 0x00, |
||||
|
0x38, 0x03, 0xF8, 0x00, |
||||
|
0x3C, 0x03, 0xFC, 0x00, |
||||
|
0x3E, 0x03, 0xBF, 0x00, |
||||
|
0x0F, 0x83, 0x8F, 0x80, |
||||
|
0x07, 0xC3, 0x87, 0xC0, |
||||
|
0x03, 0xF0, 0x03, 0xC0, |
||||
|
0x00, 0xF8, 0x0F, 0x80, |
||||
|
0x00, 0x7C, 0x0F, 0x00, |
||||
|
0x00, 0x1F, 0x0E, 0x00, |
||||
|
0x00, 0x0F, 0x80, 0x00, |
||||
|
0x00, 0x07, 0xE0, 0x00, |
||||
|
0x00, 0x07, 0xF0, 0x00, |
||||
|
0x00, 0x0F, 0xF8, 0x00, |
||||
|
0x00, 0x3F, 0xBE, 0x00, |
||||
|
0x00, 0x7F, 0x9F, 0x00, |
||||
|
0x00, 0xFB, 0x8F, 0xC0, |
||||
|
0x03, 0xE3, 0x83, 0xE0, |
||||
|
0x03, 0xC3, 0x87, 0xF0, |
||||
|
0x03, 0x83, 0x8F, 0xFC, |
||||
|
0x00, 0x03, 0xBF, 0x3C, |
||||
|
0x00, 0x03, 0xFC, 0x1C, |
||||
|
0x00, 0x03, 0xF8, 0x00, |
||||
|
0x00, 0x03, 0xE0, 0x00, |
||||
|
0x00, 0x03, 0xC0, 0x00, |
||||
|
0x00, 0x03, 0x80, 0x00, |
||||
|
0x00, 0x00, 0x00, 0x00, |
||||
|
0x00, 0x00, 0x00, 0x00, |
||||
|
}; |
||||
|
|
||||
|
static const uint8_t power_icon[] = { |
||||
|
0x00, 0x01, 0x80, 0x00, 0x00, 0x03, 0xC0, 0x00, 0x00, 0x03, 0xC0, 0x00, |
||||
|
0x00, 0x33, 0xCC, 0x00, 0x00, 0xF3, 0xCF, 0x00, 0x01, 0xF3, 0xCF, 0x80, |
||||
|
0x03, 0xF3, 0xCF, 0xC0, 0x07, 0xF3, 0xCF, 0xE0, 0x0F, 0xE3, 0xC7, 0xF0, |
||||
|
0x1F, 0xC3, 0xC3, 0xF8, 0x1F, 0x83, 0xC1, 0xF8, 0x3F, 0x03, 0xC0, 0xFC, |
||||
|
0x3E, 0x03, 0xC0, 0x7C, 0x3E, 0x03, 0xC0, 0x7C, 0x7E, 0x01, 0x80, 0x7E, |
||||
|
0x7C, 0x00, 0x00, 0x3E, 0x7C, 0x00, 0x00, 0x3E, 0x7C, 0x00, 0x00, 0x3E, |
||||
|
0x7C, 0x00, 0x00, 0x3E, 0x7C, 0x00, 0x00, 0x3E, 0x3E, 0x00, 0x00, 0x7C, |
||||
|
0x3E, 0x00, 0x00, 0x7C, 0x3F, 0x00, 0x00, 0xFC, 0x1F, 0x80, 0x01, 0xF8, |
||||
|
0x1F, 0xC0, 0x03, 0xF8, 0x0F, 0xE0, 0x07, 0xF0, 0x0F, 0xF8, 0x1F, 0xF0, |
||||
|
0x07, 0xFF, 0xFF, 0xE0, 0x03, 0xFF, 0xFF, 0xC0, 0x00, 0xFF, 0xFF, 0x00, |
||||
|
0x00, 0x3F, 0xFC, 0x00, 0x00, 0x0F, 0xF0, 0x00, |
||||
|
}; |
||||
|
|
||||
|
static const uint8_t advert_icon[] = { |
||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x30, |
||||
|
0x1C, 0x00, 0x00, 0x38, 0x18, 0x00, 0x00, 0x18, 0x30, 0x00, 0x00, 0x0C, |
||||
|
0x30, 0x60, 0x06, 0x0C, 0x60, 0xE0, 0x07, 0x06, 0x61, 0xC0, 0x03, 0x86, |
||||
|
0xE1, 0x81, 0x81, 0x87, 0xC3, 0x07, 0xE0, 0xC3, 0xC3, 0x0F, 0xF0, 0xC3, |
||||
|
0xC3, 0x0F, 0xF0, 0xC3, 0xC3, 0x0F, 0xF0, 0xC3, 0xC3, 0x0F, 0xF0, 0xC3, |
||||
|
0xC3, 0x07, 0xE0, 0xC3, 0xC1, 0x83, 0xC1, 0x83, 0x61, 0x80, 0x01, 0x86, |
||||
|
0x60, 0xC0, 0x03, 0x06, 0x70, 0xE0, 0x07, 0x0E, 0x30, 0x40, 0x02, 0x0C, |
||||
|
0x38, 0x00, 0x00, 0x1C, 0x18, 0x00, 0x00, 0x18, 0x0C, 0x00, 0x00, 0x30, |
||||
|
0x04, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
|
}; |
||||
@ -0,0 +1,74 @@ |
|||||
|
#include "MomentaryButton.h" |
||||
|
|
||||
|
MomentaryButton::MomentaryButton(int8_t pin, int long_press_millis, bool reverse) { |
||||
|
_pin = pin; |
||||
|
_reverse = reverse; |
||||
|
down_at = 0; |
||||
|
prev = _reverse ? HIGH : LOW; |
||||
|
cancel = 0; |
||||
|
_long_millis = long_press_millis; |
||||
|
} |
||||
|
|
||||
|
void MomentaryButton::begin(bool pulldownup) { |
||||
|
if (_pin >= 0) { |
||||
|
pinMode(_pin, pulldownup ? (_reverse ? INPUT_PULLUP : INPUT_PULLDOWN) : INPUT); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
bool MomentaryButton::isPressed() const { |
||||
|
return isPressed(digitalRead(_pin)); |
||||
|
} |
||||
|
|
||||
|
void MomentaryButton::cancelClick() { |
||||
|
cancel = 1; |
||||
|
} |
||||
|
|
||||
|
bool MomentaryButton::isPressed(int level) const { |
||||
|
if (_reverse) { |
||||
|
return level == LOW; |
||||
|
} else { |
||||
|
return level != LOW; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
int MomentaryButton::check(bool repeat_click) { |
||||
|
if (_pin < 0) return BUTTON_EVENT_NONE; |
||||
|
|
||||
|
int event = BUTTON_EVENT_NONE; |
||||
|
int btn = digitalRead(_pin); |
||||
|
if (btn != prev) { |
||||
|
if (isPressed(btn)) { |
||||
|
down_at = millis(); |
||||
|
} else { |
||||
|
// button UP
|
||||
|
if (_long_millis > 0) { |
||||
|
if (down_at > 0 && (unsigned long)(millis() - down_at) < _long_millis) { // only a CLICK if still within the long_press millis
|
||||
|
event = BUTTON_EVENT_CLICK; |
||||
|
} |
||||
|
} else { |
||||
|
event = BUTTON_EVENT_CLICK; // any UP results in CLICK event when NOT using long_press feature
|
||||
|
} |
||||
|
if (event == BUTTON_EVENT_CLICK && cancel) { |
||||
|
event = BUTTON_EVENT_NONE; |
||||
|
} |
||||
|
down_at = 0; |
||||
|
} |
||||
|
prev = btn; |
||||
|
} |
||||
|
if (!isPressed(btn) && cancel) { // always clear the pending 'cancel' once button is back in UP state
|
||||
|
cancel = 0; |
||||
|
} |
||||
|
|
||||
|
if (_long_millis > 0 && down_at > 0 && (unsigned long)(millis() - down_at) >= _long_millis) { |
||||
|
event = BUTTON_EVENT_LONG_PRESS; |
||||
|
down_at = 0; |
||||
|
} |
||||
|
if (down_at > 0 && repeat_click) { |
||||
|
unsigned long diff = (unsigned long)(millis() - down_at); |
||||
|
if (diff >= 700) { |
||||
|
event = BUTTON_EVENT_CLICK; // wait 700 millis before repeating the click events
|
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return event; |
||||
|
} |
||||
@ -0,0 +1,25 @@ |
|||||
|
#pragma once |
||||
|
|
||||
|
#include <Arduino.h> |
||||
|
|
||||
|
#define BUTTON_EVENT_NONE 0 |
||||
|
#define BUTTON_EVENT_CLICK 1 |
||||
|
#define BUTTON_EVENT_LONG_PRESS 2 |
||||
|
|
||||
|
class MomentaryButton { |
||||
|
int8_t _pin; |
||||
|
int8_t prev, cancel; |
||||
|
bool _reverse; |
||||
|
int _long_millis; |
||||
|
unsigned long down_at; |
||||
|
|
||||
|
bool isPressed(int level) const; |
||||
|
|
||||
|
public: |
||||
|
MomentaryButton(int8_t pin, int long_press_mills=0, bool reverse=false); |
||||
|
void begin(bool pulldownup=false); |
||||
|
int check(bool repeat_click=false); // returns one of BUTTON_EVENT_*
|
||||
|
void cancelClick(); // suppress next BUTTON_EVENT_CLICK (if already in DOWN state)
|
||||
|
uint8_t getPin() { return _pin; } |
||||
|
bool isPressed() const; |
||||
|
}; |
||||
@ -0,0 +1,21 @@ |
|||||
|
#pragma once |
||||
|
|
||||
|
#include "DisplayDriver.h" |
||||
|
|
||||
|
#define KEY_LEFT 0xB4 |
||||
|
#define KEY_UP 0xB5 |
||||
|
#define KEY_DOWN 0xB6 |
||||
|
#define KEY_RIGHT 0xB7 |
||||
|
#define KEY_SELECT 10 |
||||
|
#define KEY_ENTER 13 |
||||
|
#define KEY_BACK 27 // Esc
|
||||
|
|
||||
|
class UIScreen { |
||||
|
protected: |
||||
|
UIScreen() { } |
||||
|
public: |
||||
|
virtual int render(DisplayDriver& display) =0; // return value is number of millis until next render
|
||||
|
virtual bool handleInput(char c) { return false; } |
||||
|
virtual void poll() { } |
||||
|
}; |
||||
|
|
||||
Loading…
Reference in new issue