2020-11-16 14:21:58 +03: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 10:25:13 +03: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 14:21:58 +03:00
|
|
|
uint8_t mode_index;
|
|
|
|
|
|
|
|
// state initializer
|
|
|
|
AppiButtonState() {
|
|
|
|
mode_index = 0;
|
2020-11-25 10:25:13 +03:00
|
|
|
dallas_address_index = 0;
|
|
|
|
cyfral_address_index = 0;
|
2020-11-16 14:21:58 +03: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 15:25:32 +03:00
|
|
|
const GpioPin* red_led_record;
|
|
|
|
const GpioPin* green_led_record;
|
2020-11-16 14:21:58 +03:00
|
|
|
|
2020-11-25 10:25:13 +03:00
|
|
|
static const uint8_t modes_count = 4;
|
2020-11-19 15:25:32 +03:00
|
|
|
AppTemplateMode<AppiButtonState, AppiButtonEvent>* mode[modes_count];
|
2020-11-16 14:21:58 +03:00
|
|
|
|
|
|
|
void run();
|
|
|
|
void render(CanvasApi* canvas);
|
2020-11-25 10:25:13 +03:00
|
|
|
void render_dallas_list(CanvasApi* canvas, AppiButtonState* state);
|
|
|
|
void render_cyfral_list(CanvasApi* canvas, AppiButtonState* state);
|
2020-11-16 14:21:58 +03:00
|
|
|
|
|
|
|
void blink_red();
|
|
|
|
void blink_green();
|
|
|
|
|
|
|
|
void increase_mode();
|
|
|
|
void decrease_mode();
|
2020-11-25 10:25:13 +03:00
|
|
|
void increase_dallas_address();
|
|
|
|
void decrease_dallas_address();
|
|
|
|
void increase_cyfral_address();
|
|
|
|
void decrease_cyfral_address();
|
2020-11-17 00:10:58 +03:00
|
|
|
void switch_to_mode(uint8_t mode_index);
|
2020-11-16 14:21:58 +03:00
|
|
|
};
|