flipperzero-firmware/applications/ibutton/ibutton.h

56 lines
1.2 KiB
C
Raw Normal View History

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-16 21:10:58 +00:00
// test key = {0x01, 0xFD, 0x0E, 0x84, 0x01, 0x00, 0x00, 0xDB};
uint8_t dallas_address[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
2020-11-16 11:21:58 +00:00
uint8_t mode_index;
// state initializer
AppiButtonState() {
mode_index = 0;
}
};
// 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:
GpioPin* red_led_record;
GpioPin* green_led_record;
static const uint8_t modes_count = 2;
AppTemplateMode<AppiButtonState, AppiButtonEvent>* mode[modes_count] = {NULL, NULL};
2020-11-16 11:21:58 +00:00
void run();
void render(CanvasApi* canvas);
void blink_red();
void blink_green();
void increase_mode();
void decrease_mode();
2020-11-16 21:10:58 +00:00
void switch_to_mode(uint8_t mode_index);
2020-11-16 11:21:58 +00:00
};