2020-11-25 10:25:13 +03:00
|
|
|
#pragma once
|
|
|
|
#include "ibutton.h"
|
|
|
|
#include "cyfral_emulator.h"
|
|
|
|
|
|
|
|
class AppiButtonModeCyfralEmulate : public AppTemplateMode<AppiButtonState, AppiButtonEvent> {
|
|
|
|
public:
|
|
|
|
const char* name = "cyfral emulate";
|
|
|
|
AppiButton* app;
|
|
|
|
CyfralEmulator* cyfral_emulator;
|
|
|
|
|
|
|
|
void event(AppiButtonEvent* event, AppiButtonState* state);
|
2020-12-14 13:50:32 +03:00
|
|
|
void render(Canvas* canvas, AppiButtonState* state);
|
2020-11-25 10:25:13 +03:00
|
|
|
void acquire();
|
|
|
|
void release();
|
|
|
|
|
|
|
|
AppiButtonModeCyfralEmulate(AppiButton* parent_app) {
|
|
|
|
app = parent_app;
|
|
|
|
|
|
|
|
// TODO open record
|
|
|
|
const GpioPin* one_wire_pin_record = &ibutton_gpio;
|
|
|
|
cyfral_emulator = new CyfralEmulator(one_wire_pin_record);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
void AppiButtonModeCyfralEmulate::event(AppiButtonEvent* event, AppiButtonState* state) {
|
|
|
|
if(event->type == AppiButtonEvent::EventTypeTick) {
|
|
|
|
// repeat key sending 8 times
|
|
|
|
cyfral_emulator->send(state->cyfral_address[state->cyfral_address_index], 4, 8);
|
|
|
|
app->blink_green();
|
|
|
|
|
|
|
|
} else if(event->type == AppiButtonEvent::EventTypeKey) {
|
2021-02-10 11:56:05 +03:00
|
|
|
if(event->value.input.type == InputTypeShort && event->value.input.key == InputKeyUp) {
|
2020-11-25 10:25:13 +03:00
|
|
|
app->decrease_cyfral_address();
|
|
|
|
}
|
|
|
|
|
2021-02-10 11:56:05 +03:00
|
|
|
if(event->value.input.type == InputTypeShort && event->value.input.key == InputKeyDown) {
|
2020-11-25 10:25:13 +03:00
|
|
|
app->increase_cyfral_address();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-14 13:50:32 +03:00
|
|
|
void AppiButtonModeCyfralEmulate::render(Canvas* canvas, AppiButtonState* state) {
|
|
|
|
canvas_set_font(canvas, FontSecondary);
|
|
|
|
canvas_draw_str(canvas, 2, 25, "< Cyfral emulate");
|
2020-11-25 10:25:13 +03:00
|
|
|
|
|
|
|
app->render_cyfral_list(canvas, state);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AppiButtonModeCyfralEmulate::acquire() {
|
|
|
|
cyfral_emulator->start();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AppiButtonModeCyfralEmulate::release() {
|
|
|
|
cyfral_emulator->stop();
|
|
|
|
}
|