2020-11-16 11:21:58 +00:00
|
|
|
#pragma once
|
|
|
|
#include "app-template.h"
|
|
|
|
#include "ibutton_mode_template.h"
|
|
|
|
|
|
|
|
// event enumeration type
|
|
|
|
typedef uint8_t event_t;
|
|
|
|
|
|
|
|
class AppiButtonState {
|
|
|
|
public:
|
|
|
|
// state data
|
2020-11-25 07:25:13 +00:00
|
|
|
static const uint8_t dallas_address_count = 3;
|
|
|
|
uint8_t dallas_address[dallas_address_count][8] = {
|
|
|
|
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
|
|
|
{0x01, 0x41, 0xCE, 0x67, 0x0F, 0x00, 0x00, 0xB6},
|
|
|
|
{0x01, 0xFD, 0x0E, 0x84, 0x01, 0x00, 0x00, 0xDB}};
|
|
|
|
|
|
|
|
uint8_t dallas_address_index;
|
|
|
|
|
|
|
|
static const uint8_t cyfral_address_count = 3;
|
|
|
|
uint8_t cyfral_address[cyfral_address_count][4] = {
|
|
|
|
{0x00, 0x00, 0x00, 0x00},
|
|
|
|
{0xBB, 0xBB, 0x7B, 0xBD},
|
|
|
|
{0x7B, 0xDE, 0x7B, 0xDE}};
|
|
|
|
uint8_t cyfral_address_index;
|
|
|
|
|
2020-11-16 11:21:58 +00:00
|
|
|
uint8_t mode_index;
|
|
|
|
|
|
|
|
// state initializer
|
|
|
|
AppiButtonState() {
|
|
|
|
mode_index = 0;
|
2020-11-25 07:25:13 +00:00
|
|
|
dallas_address_index = 0;
|
|
|
|
cyfral_address_index = 0;
|
2020-11-16 11:21:58 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// events class
|
|
|
|
class AppiButtonEvent {
|
|
|
|
public:
|
|
|
|
// events enum
|
|
|
|
static const event_t EventTypeTick = 0;
|
|
|
|
static const event_t EventTypeKey = 1;
|
|
|
|
|
|
|
|
// payload
|
|
|
|
union {
|
|
|
|
InputEvent input;
|
|
|
|
} value;
|
|
|
|
|
|
|
|
// event type
|
|
|
|
event_t type;
|
|
|
|
};
|
|
|
|
|
|
|
|
// our app derived from base AppTemplate class
|
|
|
|
// with template variables <state, events>
|
|
|
|
class AppiButton : public AppTemplate<AppiButtonState, AppiButtonEvent> {
|
|
|
|
public:
|
2020-11-19 12:25:32 +00:00
|
|
|
const GpioPin* red_led_record;
|
|
|
|
const GpioPin* green_led_record;
|
2020-11-16 11:21:58 +00:00
|
|
|
|
2020-11-25 07:25:13 +00:00
|
|
|
static const uint8_t modes_count = 4;
|
2020-11-19 12:25:32 +00:00
|
|
|
AppTemplateMode<AppiButtonState, AppiButtonEvent>* mode[modes_count];
|
2020-11-16 11:21:58 +00:00
|
|
|
|
|
|
|
void run();
|
2020-12-14 10:50:32 +00:00
|
|
|
void render(Canvas* canvas);
|
|
|
|
void render_dallas_list(Canvas* canvas, AppiButtonState* state);
|
|
|
|
void render_cyfral_list(Canvas* canvas, AppiButtonState* state);
|
2020-11-16 11:21:58 +00:00
|
|
|
|
|
|
|
void blink_red();
|
|
|
|
void blink_green();
|
|
|
|
|
|
|
|
void increase_mode();
|
|
|
|
void decrease_mode();
|
2020-11-25 07:25:13 +00:00
|
|
|
void increase_dallas_address();
|
|
|
|
void decrease_dallas_address();
|
|
|
|
void increase_cyfral_address();
|
|
|
|
void decrease_cyfral_address();
|
2020-11-16 21:10:58 +00:00
|
|
|
void switch_to_mode(uint8_t mode_index);
|
2020-11-16 11:21:58 +00:00
|
|
|
};
|