2020-11-16 11:21:58 +00:00
|
|
|
#include "ibutton.h"
|
|
|
|
#include "ibutton_mode_dallas_read.h"
|
|
|
|
#include "ibutton_mode_dallas_emulate.h"
|
2021-01-28 12:30:31 +00:00
|
|
|
#include "ibutton_mode_dallas_write.h"
|
2020-11-25 07:25:13 +00:00
|
|
|
#include "ibutton_mode_cyfral_read.h"
|
|
|
|
#include "ibutton_mode_cyfral_emulate.h"
|
2020-11-16 11:21:58 +00:00
|
|
|
|
|
|
|
// start app
|
|
|
|
void AppiButton::run() {
|
|
|
|
mode[0] = new AppiButtonModeDallasRead(this);
|
|
|
|
mode[1] = new AppiButtonModeDallasEmulate(this);
|
2021-01-28 12:30:31 +00:00
|
|
|
mode[2] = new AppiButtonModeDallasWrite(this);
|
|
|
|
mode[3] = new AppiButtonModeCyfralRead(this);
|
|
|
|
mode[4] = new AppiButtonModeCyfralEmulate(this);
|
2020-11-16 21:10:58 +00:00
|
|
|
|
|
|
|
switch_to_mode(0);
|
2020-11-16 11:21:58 +00:00
|
|
|
|
|
|
|
// TODO open record
|
2020-11-19 12:25:32 +00:00
|
|
|
red_led_record = &led_gpio[0];
|
|
|
|
green_led_record = &led_gpio[1];
|
2020-11-16 11:21:58 +00:00
|
|
|
|
|
|
|
// configure pin
|
|
|
|
gpio_init(red_led_record, GpioModeOutputOpenDrain);
|
|
|
|
gpio_init(green_led_record, GpioModeOutputOpenDrain);
|
|
|
|
|
2021-01-28 12:30:31 +00:00
|
|
|
api_hal_timebase_insomnia_enter();
|
2020-11-19 12:25:32 +00:00
|
|
|
app_ready();
|
|
|
|
|
2020-11-16 11:21:58 +00:00
|
|
|
AppiButtonEvent event;
|
|
|
|
while(1) {
|
2020-11-25 07:25:13 +00:00
|
|
|
if(get_event(&event, 20)) {
|
2020-11-16 11:21:58 +00:00
|
|
|
if(event.type == AppiButtonEvent::EventTypeKey) {
|
|
|
|
// press events
|
|
|
|
if(event.value.input.state && event.value.input.input == InputBack) {
|
2021-01-29 13:52:16 +00:00
|
|
|
view_port_enabled_set(view_port, false);
|
|
|
|
gui_remove_view_port(gui, view_port);
|
2021-01-28 12:30:31 +00:00
|
|
|
api_hal_timebase_insomnia_exit();
|
|
|
|
|
[FL-140] Core api dynamic records (#296)
* SYSTEM: tickless mode with deep sleep.
* Move FreeRTOS ticks to lptim2
* API: move all sumbodules init routines to one place. Timebase: working lptim2 at tick source.
* API Timebase: lp-timer routines, timer access safe zones prediction and synchronization. FreeRTOS: adjust configuration for tickless mode.
* NFC: support for tickless mode.
* API Timebase: improve tick error handling in IRQ. Apploader: use insomnia mode to run applications.
* BLE: prevent sleep while core2 starting
* HAL: nap while in insomnia mode
* init records work
* try to implement record delete
* tests and flapp
* flapp subsystem
* new core functions to get app stat, simplify core code
* fix thread termination
* add strdup to core
* fix tests
* Refactoring: remove all unusued parts, update API usage, aggreagate API sources and headers, new record storage
* Refactoring: update furi record api usage, cleanup code
* Fix broken merge for freertos apps
* Core, Target: fix compilation warnings
* Drop firmware target local
* HAL Timebase, Power, Clock: semaphore guarded access to clock and power modes, better sleep mode.
* SD-Filesystem: wait for all deps to arrive before adding widget. Core, BLE: disable debug dump to serial.
* delete old app example-ipc
* delete old app fatfs list
* fix strobe app, add input header
* delete old display driver
* comment old app qr-code
* fix sd-card test, add forced widget update
* remove unused new core test
* increase heap to 128k
* comment and assert old core tests
* fix syntax
Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2021-01-20 16:09:26 +00:00
|
|
|
osThreadExit();
|
2020-11-16 11:21:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(event.value.input.state && event.value.input.input == InputLeft) {
|
|
|
|
decrease_mode();
|
|
|
|
}
|
|
|
|
|
|
|
|
if(event.value.input.state && event.value.input.input == InputRight) {
|
|
|
|
increase_mode();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
event.type = AppiButtonEvent::EventTypeTick;
|
|
|
|
}
|
|
|
|
|
|
|
|
acquire_state();
|
|
|
|
mode[state.mode_index]->event(&event, &state);
|
|
|
|
release_state();
|
|
|
|
|
2021-01-29 13:52:16 +00:00
|
|
|
view_port_update(view_port);
|
2020-11-16 11:21:58 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// render app
|
2020-12-14 10:50:32 +00:00
|
|
|
void AppiButton::render(Canvas* canvas) {
|
|
|
|
canvas_set_color(canvas, ColorBlack);
|
|
|
|
canvas_set_font(canvas, FontPrimary);
|
|
|
|
canvas_draw_str(canvas, 2, 12, "iButton");
|
2020-11-16 11:21:58 +00:00
|
|
|
|
2020-11-19 12:25:32 +00:00
|
|
|
mode[state.mode_index]->render(canvas, &state);
|
2020-11-16 11:21:58 +00:00
|
|
|
}
|
|
|
|
|
2020-12-14 10:50:32 +00:00
|
|
|
void AppiButton::render_dallas_list(Canvas* canvas, AppiButtonState* state) {
|
2020-11-25 07:25:13 +00:00
|
|
|
const uint8_t buffer_size = 50;
|
|
|
|
char buf[buffer_size];
|
|
|
|
for(uint8_t i = 0; i < state->dallas_address_count; i++) {
|
|
|
|
snprintf(
|
|
|
|
buf,
|
|
|
|
buffer_size,
|
|
|
|
"%s[%u] %x:%x:%x:%x:%x:%x:%x:%x",
|
|
|
|
(i == state->dallas_address_index) ? "> " : "",
|
|
|
|
i + 1,
|
|
|
|
state->dallas_address[i][0],
|
|
|
|
state->dallas_address[i][1],
|
|
|
|
state->dallas_address[i][2],
|
|
|
|
state->dallas_address[i][3],
|
|
|
|
state->dallas_address[i][4],
|
|
|
|
state->dallas_address[i][5],
|
|
|
|
state->dallas_address[i][6],
|
|
|
|
state->dallas_address[i][7]);
|
2020-12-14 10:50:32 +00:00
|
|
|
canvas_draw_str(canvas, 2, 37 + i * 12, buf);
|
2020-11-25 07:25:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-14 10:50:32 +00:00
|
|
|
void AppiButton::render_cyfral_list(Canvas* canvas, AppiButtonState* state) {
|
2020-11-25 07:25:13 +00:00
|
|
|
const uint8_t buffer_size = 50;
|
|
|
|
char buf[buffer_size];
|
|
|
|
for(uint8_t i = 0; i < state->cyfral_address_count; i++) {
|
|
|
|
snprintf(
|
|
|
|
buf,
|
|
|
|
buffer_size,
|
|
|
|
"%s[%u] %x:%x:%x:%x",
|
|
|
|
(i == state->cyfral_address_index) ? "> " : "",
|
|
|
|
i + 1,
|
|
|
|
state->cyfral_address[i][0],
|
|
|
|
state->cyfral_address[i][1],
|
|
|
|
state->cyfral_address[i][2],
|
|
|
|
state->cyfral_address[i][3]);
|
2020-12-14 10:50:32 +00:00
|
|
|
canvas_draw_str(canvas, 2, 37 + i * 12, buf);
|
2020-11-25 07:25:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-16 11:21:58 +00:00
|
|
|
void AppiButton::blink_red() {
|
|
|
|
gpio_write(red_led_record, 0);
|
|
|
|
delay(10);
|
|
|
|
gpio_write(red_led_record, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AppiButton::blink_green() {
|
|
|
|
gpio_write(green_led_record, 0);
|
|
|
|
delay(10);
|
|
|
|
gpio_write(green_led_record, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AppiButton::increase_mode() {
|
|
|
|
acquire_state();
|
|
|
|
if(state.mode_index < (modes_count - 1)) {
|
|
|
|
mode[state.mode_index]->release();
|
|
|
|
state.mode_index++;
|
|
|
|
mode[state.mode_index]->acquire();
|
|
|
|
}
|
|
|
|
release_state();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AppiButton::decrease_mode() {
|
|
|
|
acquire_state();
|
|
|
|
if(state.mode_index > 0) {
|
|
|
|
mode[state.mode_index]->release();
|
|
|
|
state.mode_index--;
|
|
|
|
mode[state.mode_index]->acquire();
|
|
|
|
}
|
|
|
|
release_state();
|
|
|
|
}
|
|
|
|
|
2020-11-25 07:25:13 +00:00
|
|
|
void AppiButton::increase_dallas_address() {
|
|
|
|
if(state.dallas_address_index < (state.dallas_address_count - 1)) {
|
|
|
|
state.dallas_address_index++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AppiButton::decrease_dallas_address() {
|
|
|
|
if(state.dallas_address_index > 0) {
|
|
|
|
state.dallas_address_index--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AppiButton::increase_cyfral_address() {
|
|
|
|
if(state.cyfral_address_index < (state.cyfral_address_count - 1)) {
|
|
|
|
state.cyfral_address_index++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AppiButton::decrease_cyfral_address() {
|
|
|
|
if(state.cyfral_address_index > 0) {
|
|
|
|
state.cyfral_address_index--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-16 21:10:58 +00:00
|
|
|
void AppiButton::switch_to_mode(uint8_t mode_index) {
|
|
|
|
mode[state.mode_index]->release();
|
|
|
|
state.mode_index = mode_index;
|
|
|
|
mode[state.mode_index]->acquire();
|
|
|
|
}
|
|
|
|
|
2020-11-16 11:21:58 +00:00
|
|
|
// app enter function
|
|
|
|
extern "C" void app_ibutton(void* p) {
|
|
|
|
AppiButton* app = new AppiButton();
|
|
|
|
app->run();
|
|
|
|
}
|