[FL-2393][FL-2381] iButton, OneWire: move to plain C (#1068)
* iButton: getting started on the worker concept * Hal delay: added global instructions_per_us variable * iButton: one wire slave * iButton: ibutton key setter * iButton: one wire host, use ibutton_hal * iButton\RFID: common pulse decoder concept * iButton: cyfral decoder * iButton: worker thread concept * iButton: metakom decoder * iButton: write key through worker * iButton: worker mode holder * iButton: worker improvements * iButton: Cyfral encoder * iButton: Metakom encoder * lib: pulse protocol helpers * iButton: Metakom decoder * iButton: Cyfral decoder * iButton worker: separate modes * iButton: libs documentation * HAL: iButton gpio modes * iButton worker: rename modes file * iButton worker, hal: move to LL * iButton CLI: worker for reading and emulation commands * iButton HAL: correct init and emulation sequence * iButton cli: moved to plain C * iButton: move to worker, small step to plain C * Libs, one wire: move to plain C * Libs: added forgotten files to compilation * iButton writer: get rid of manual disable/enable irq
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
#include "ibutton_scene_add_type.h"
|
||||
#include "../ibutton_app.h"
|
||||
#include "../ibutton_view_manager.h"
|
||||
#include "../ibutton_event.h"
|
||||
#include <callback-connector.h>
|
||||
|
||||
typedef enum {
|
||||
@@ -10,14 +8,23 @@ typedef enum {
|
||||
SubmenuIndexMetakom,
|
||||
} SubmenuIndex;
|
||||
|
||||
static void submenu_callback(void* context, uint32_t index) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
|
||||
event.type = iButtonEvent::Type::EventTypeMenuSelected;
|
||||
event.payload.menu_index = index;
|
||||
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
||||
|
||||
void iButtonSceneAddType::on_enter(iButtonApp* app) {
|
||||
iButtonAppViewManager* view_manager = app->get_view_manager();
|
||||
Submenu* submenu = view_manager->get_submenu();
|
||||
auto callback = cbc::obtain_connector(this, &iButtonSceneAddType::submenu_callback);
|
||||
|
||||
submenu_add_item(submenu, "Cyfral", SubmenuIndexCyfral, callback, app);
|
||||
submenu_add_item(submenu, "Dallas", SubmenuIndexDallas, callback, app);
|
||||
submenu_add_item(submenu, "Metakom", SubmenuIndexMetakom, callback, app);
|
||||
submenu_add_item(submenu, "Cyfral", SubmenuIndexCyfral, submenu_callback, app);
|
||||
submenu_add_item(submenu, "Dallas", SubmenuIndexDallas, submenu_callback, app);
|
||||
submenu_add_item(submenu, "Metakom", SubmenuIndexMetakom, submenu_callback, app);
|
||||
submenu_set_selected_item(submenu, submenu_item_selected);
|
||||
|
||||
view_manager->switch_to(iButtonAppViewManager::Type::iButtonAppViewSubmenu);
|
||||
@@ -28,19 +35,21 @@ bool iButtonSceneAddType::on_event(iButtonApp* app, iButtonEvent* event) {
|
||||
|
||||
if(event->type == iButtonEvent::Type::EventTypeMenuSelected) {
|
||||
submenu_item_selected = event->payload.menu_index;
|
||||
iButtonKey* key = app->get_key();
|
||||
|
||||
switch(event->payload.menu_index) {
|
||||
case SubmenuIndexCyfral:
|
||||
app->get_key()->set_type(iButtonKeyType::KeyCyfral);
|
||||
ibutton_key_set_type(key, iButtonKeyCyfral);
|
||||
break;
|
||||
case SubmenuIndexDallas:
|
||||
app->get_key()->set_type(iButtonKeyType::KeyDallas);
|
||||
ibutton_key_set_type(key, iButtonKeyDS1990);
|
||||
break;
|
||||
case SubmenuIndexMetakom:
|
||||
app->get_key()->set_type(iButtonKeyType::KeyMetakom);
|
||||
ibutton_key_set_type(key, iButtonKeyMetakom);
|
||||
break;
|
||||
}
|
||||
app->get_key()->set_name("");
|
||||
app->get_key()->clear_data();
|
||||
ibutton_key_set_name(key, "");
|
||||
ibutton_key_clear_data(key);
|
||||
app->switch_to_next_scene(iButtonApp::Scene::SceneAddValue);
|
||||
consumed = true;
|
||||
}
|
||||
@@ -54,13 +63,3 @@ void iButtonSceneAddType::on_exit(iButtonApp* app) {
|
||||
|
||||
submenu_reset(submenu);
|
||||
}
|
||||
|
||||
void iButtonSceneAddType::submenu_callback(void* context, uint32_t index) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
|
||||
event.type = iButtonEvent::Type::EventTypeMenuSelected;
|
||||
event.payload.menu_index = index;
|
||||
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
||||
|
||||
@@ -8,6 +8,5 @@ public:
|
||||
void on_exit(iButtonApp* app) final;
|
||||
|
||||
private:
|
||||
void submenu_callback(void* context, uint32_t index);
|
||||
uint32_t submenu_item_selected = 0;
|
||||
};
|
||||
@@ -1,17 +1,30 @@
|
||||
#include "ibutton_scene_add_value.h"
|
||||
#include "../ibutton_app.h"
|
||||
#include "../ibutton_view_manager.h"
|
||||
#include "../ibutton_event.h"
|
||||
#include <callback-connector.h>
|
||||
#include <dolphin/dolphin.h>
|
||||
|
||||
static void byte_input_callback(void* context) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
|
||||
event.type = iButtonEvent::Type::EventTypeByteEditResult;
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
||||
|
||||
void iButtonSceneAddValue::on_enter(iButtonApp* app) {
|
||||
iButtonAppViewManager* view_manager = app->get_view_manager();
|
||||
ByteInput* byte_input = view_manager->get_byte_input();
|
||||
auto callback = cbc::obtain_connector(this, &iButtonSceneAddValue::byte_input_callback);
|
||||
memcpy(this->new_key_data, app->get_key()->get_data(), app->get_key()->get_type_data_size());
|
||||
iButtonKey* key = app->get_key();
|
||||
|
||||
memcpy(this->new_key_data, ibutton_key_get_data_p(key), ibutton_key_get_data_size(key));
|
||||
|
||||
byte_input_set_result_callback(
|
||||
byte_input, callback, NULL, app, this->new_key_data, app->get_key()->get_type_data_size());
|
||||
byte_input,
|
||||
byte_input_callback,
|
||||
NULL,
|
||||
app,
|
||||
this->new_key_data,
|
||||
ibutton_key_get_data_size(key));
|
||||
|
||||
byte_input_set_header_text(byte_input, "Enter the key");
|
||||
|
||||
view_manager->switch_to(iButtonAppViewManager::Type::iButtonAppViewByteInput);
|
||||
@@ -21,6 +34,7 @@ bool iButtonSceneAddValue::on_event(iButtonApp* app, iButtonEvent* event) {
|
||||
bool consumed = false;
|
||||
|
||||
if(event->type == iButtonEvent::Type::EventTypeByteEditResult) {
|
||||
ibutton_key_set_data(app->get_key(), this->new_key_data, IBUTTON_KEY_DATA_SIZE);
|
||||
DOLPHIN_DEED(DolphinDeedIbuttonAdd);
|
||||
app->switch_to_next_scene(iButtonApp::Scene::SceneSaveName);
|
||||
consumed = true;
|
||||
@@ -35,13 +49,4 @@ void iButtonSceneAddValue::on_exit(iButtonApp* app) {
|
||||
|
||||
byte_input_set_result_callback(byte_input, NULL, NULL, NULL, NULL, 0);
|
||||
byte_input_set_header_text(byte_input, {0});
|
||||
}
|
||||
|
||||
void iButtonSceneAddValue::byte_input_callback(void* context) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
|
||||
event.type = iButtonEvent::Type::EventTypeByteEditResult;
|
||||
memcpy(app->get_key()->get_data(), this->new_key_data, app->get_key()->get_type_data_size());
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
#include "ibutton_scene_generic.h"
|
||||
#include "../ibutton_key.h"
|
||||
#include <one_wire/ibutton/ibutton_key.h>
|
||||
|
||||
class iButtonSceneAddValue : public iButtonScene {
|
||||
public:
|
||||
@@ -9,6 +9,5 @@ public:
|
||||
void on_exit(iButtonApp* app) final;
|
||||
|
||||
private:
|
||||
void byte_input_callback(void* context);
|
||||
uint8_t new_key_data[IBUTTON_KEY_DATA_SIZE] = {};
|
||||
};
|
||||
@@ -1,25 +1,31 @@
|
||||
#include "ibutton_scene_delete_confirm.h"
|
||||
#include "../ibutton_app.h"
|
||||
#include "../ibutton_view_manager.h"
|
||||
#include "../ibutton_event.h"
|
||||
#include <callback-connector.h>
|
||||
|
||||
static void widget_callback(GuiButtonType result, InputType type, void* context) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
|
||||
if(type == InputTypeShort) {
|
||||
event.type = iButtonEvent::Type::EventTypeWidgetButtonResult;
|
||||
event.payload.widget_button_result = result;
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
||||
}
|
||||
|
||||
void iButtonSceneDeleteConfirm::on_enter(iButtonApp* app) {
|
||||
iButtonAppViewManager* view_manager = app->get_view_manager();
|
||||
Widget* widget = view_manager->get_widget();
|
||||
auto callback = cbc::obtain_connector(this, &iButtonSceneDeleteConfirm::widget_callback);
|
||||
|
||||
iButtonKey* key = app->get_key();
|
||||
uint8_t* key_data = key->get_data();
|
||||
const uint8_t* key_data = ibutton_key_get_data_p(key);
|
||||
|
||||
app->set_text_store("\e#Delete %s?\e#", key->get_name());
|
||||
app->set_text_store("\e#Delete %s?\e#", ibutton_key_get_name_p(key));
|
||||
widget_add_text_box_element(
|
||||
widget, 0, 0, 128, 27, AlignCenter, AlignCenter, app->get_text_store());
|
||||
widget_add_button_element(widget, GuiButtonTypeLeft, "Back", callback, app);
|
||||
widget_add_button_element(widget, GuiButtonTypeRight, "Delete", callback, app);
|
||||
widget_add_button_element(widget, GuiButtonTypeLeft, "Back", widget_callback, app);
|
||||
widget_add_button_element(widget, GuiButtonTypeRight, "Delete", widget_callback, app);
|
||||
|
||||
switch(key->get_key_type()) {
|
||||
case iButtonKeyType::KeyDallas:
|
||||
switch(ibutton_key_get_type(key)) {
|
||||
case iButtonKeyDS1990:
|
||||
app->set_text_store(
|
||||
"%02X %02X %02X %02X %02X %02X %02X %02X",
|
||||
key_data[0],
|
||||
@@ -33,12 +39,12 @@ void iButtonSceneDeleteConfirm::on_enter(iButtonApp* app) {
|
||||
widget_add_string_element(
|
||||
widget, 64, 45, AlignCenter, AlignBottom, FontSecondary, "Dallas");
|
||||
break;
|
||||
case iButtonKeyType::KeyCyfral:
|
||||
case iButtonKeyCyfral:
|
||||
app->set_text_store("%02X %02X", key_data[0], key_data[1]);
|
||||
widget_add_string_element(
|
||||
widget, 64, 45, AlignCenter, AlignBottom, FontSecondary, "Cyfral");
|
||||
break;
|
||||
case iButtonKeyType::KeyMetakom:
|
||||
case iButtonKeyMetakom:
|
||||
app->set_text_store(
|
||||
"%02X %02X %02X %02X", key_data[0], key_data[1], key_data[2], key_data[3]);
|
||||
widget_add_string_element(
|
||||
@@ -77,18 +83,3 @@ void iButtonSceneDeleteConfirm::on_exit(iButtonApp* app) {
|
||||
|
||||
widget_reset(widget);
|
||||
}
|
||||
|
||||
void iButtonSceneDeleteConfirm::widget_callback(
|
||||
GuiButtonType result,
|
||||
InputType type,
|
||||
void* context) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
|
||||
if(type == InputTypeShort) {
|
||||
event.type = iButtonEvent::Type::EventTypeWidgetButtonResult;
|
||||
event.payload.widget_button_result = result;
|
||||
}
|
||||
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,4 @@ public:
|
||||
void on_enter(iButtonApp* app) final;
|
||||
bool on_event(iButtonApp* app, iButtonEvent* event) final;
|
||||
void on_exit(iButtonApp* app) final;
|
||||
|
||||
private:
|
||||
void widget_callback(GuiButtonType result, InputType type, void* context);
|
||||
};
|
||||
@@ -1,19 +1,21 @@
|
||||
#include "ibutton_scene_delete_success.h"
|
||||
#include "../ibutton_app.h"
|
||||
#include "../ibutton_view_manager.h"
|
||||
#include "../ibutton_event.h"
|
||||
#include "../ibutton_key.h"
|
||||
#include <callback-connector.h>
|
||||
|
||||
static void popup_callback(void* context) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
event.type = iButtonEvent::Type::EventTypeBack;
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
||||
|
||||
void iButtonSceneDeleteSuccess::on_enter(iButtonApp* app) {
|
||||
iButtonAppViewManager* view_manager = app->get_view_manager();
|
||||
Popup* popup = view_manager->get_popup();
|
||||
auto callback = cbc::obtain_connector(this, &iButtonSceneDeleteSuccess::popup_callback);
|
||||
|
||||
popup_set_icon(popup, 0, 2, &I_DolphinMafia_115x62);
|
||||
popup_set_text(popup, "Deleted", 83, 19, AlignLeft, AlignBottom);
|
||||
|
||||
popup_set_callback(popup, callback);
|
||||
popup_set_callback(popup, popup_callback);
|
||||
popup_set_context(popup, app);
|
||||
popup_set_timeout(popup, 1500);
|
||||
popup_enable_timeout(popup);
|
||||
@@ -41,11 +43,4 @@ void iButtonSceneDeleteSuccess::on_exit(iButtonApp* app) {
|
||||
popup_disable_timeout(popup);
|
||||
popup_set_context(popup, NULL);
|
||||
popup_set_callback(popup, NULL);
|
||||
}
|
||||
|
||||
void iButtonSceneDeleteSuccess::popup_callback(void* context) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
event.type = iButtonEvent::Type::EventTypeBack;
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
||||
@@ -6,7 +6,4 @@ public:
|
||||
void on_enter(iButtonApp* app) final;
|
||||
bool on_event(iButtonApp* app, iButtonEvent* event) final;
|
||||
void on_exit(iButtonApp* app) final;
|
||||
|
||||
private:
|
||||
void popup_callback(void* context);
|
||||
};
|
||||
@@ -1,17 +1,21 @@
|
||||
#include "ibutton_scene_emulate.h"
|
||||
#include "../ibutton_app.h"
|
||||
#include "../ibutton_view_manager.h"
|
||||
#include "../ibutton_event.h"
|
||||
#include "../ibutton_key.h"
|
||||
#include <dolphin/dolphin.h>
|
||||
#include <callback-connector.h>
|
||||
|
||||
static void emulate_callback(void* context, bool emulated) {
|
||||
if(emulated) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event = {.type = iButtonEvent::Type::EventTypeWorkerEmulated};
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
||||
}
|
||||
|
||||
void iButtonSceneEmulate::on_enter(iButtonApp* app) {
|
||||
iButtonAppViewManager* view_manager = app->get_view_manager();
|
||||
Popup* popup = view_manager->get_popup();
|
||||
iButtonKey* key = app->get_key();
|
||||
uint8_t* key_data = key->get_data();
|
||||
const char* key_name = key->get_name();
|
||||
const uint8_t* key_data = ibutton_key_get_data_p(key);
|
||||
const char* key_name = ibutton_key_get_name_p(key);
|
||||
uint8_t line_count = 2;
|
||||
DOLPHIN_DEED(DolphinDeedIbuttonEmulate);
|
||||
|
||||
@@ -21,8 +25,8 @@ void iButtonSceneEmulate::on_enter(iButtonApp* app) {
|
||||
line_count = 2;
|
||||
} else {
|
||||
// if not, show key data
|
||||
switch(key->get_key_type()) {
|
||||
case iButtonKeyType::KeyDallas:
|
||||
switch(ibutton_key_get_type(key)) {
|
||||
case iButtonKeyDS1990:
|
||||
app->set_text_store(
|
||||
"emulating\n%02X %02X %02X %02X\n%02X %02X %02X %02X",
|
||||
key_data[0],
|
||||
@@ -35,11 +39,11 @@ void iButtonSceneEmulate::on_enter(iButtonApp* app) {
|
||||
key_data[7]);
|
||||
line_count = 3;
|
||||
break;
|
||||
case iButtonKeyType::KeyCyfral:
|
||||
case iButtonKeyCyfral:
|
||||
app->set_text_store("emulating\n%02X %02X", key_data[0], key_data[1]);
|
||||
line_count = 2;
|
||||
break;
|
||||
case iButtonKeyType::KeyMetakom:
|
||||
case iButtonKeyMetakom:
|
||||
app->set_text_store(
|
||||
"emulating\n%02X %02X %02X %02X",
|
||||
key_data[0],
|
||||
@@ -66,29 +70,28 @@ void iButtonSceneEmulate::on_enter(iButtonApp* app) {
|
||||
popup_set_icon(popup, 2, 10, &I_iButtonKey_49x44);
|
||||
|
||||
view_manager->switch_to(iButtonAppViewManager::Type::iButtonAppViewPopup);
|
||||
app->get_key_worker()->start_emulate(app->get_key());
|
||||
|
||||
ibutton_worker_emulate_set_callback(app->get_key_worker(), emulate_callback, app);
|
||||
ibutton_worker_emulate_start(app->get_key_worker(), key);
|
||||
}
|
||||
|
||||
bool iButtonSceneEmulate::on_event(iButtonApp* app, iButtonEvent* event) {
|
||||
bool consumed = false;
|
||||
|
||||
if(event->type == iButtonEvent::Type::EventTypeTick) {
|
||||
if(event->type == iButtonEvent::Type::EventTypeWorkerEmulated) {
|
||||
app->notify_yellow_blink();
|
||||
consumed = true;
|
||||
} else if(event->type == iButtonEvent::Type::EventTypeTick) {
|
||||
app->notify_red_blink();
|
||||
consumed = true;
|
||||
if(app->get_key_worker()->emulated()) {
|
||||
app->notify_yellow_blink();
|
||||
} else {
|
||||
app->notify_red_blink();
|
||||
}
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void iButtonSceneEmulate::on_exit(iButtonApp* app) {
|
||||
app->get_key_worker()->stop_emulate();
|
||||
|
||||
Popup* popup = app->get_view_manager()->get_popup();
|
||||
|
||||
ibutton_worker_stop(app->get_key_worker());
|
||||
popup_set_header(popup, NULL, 0, 0, AlignCenter, AlignBottom);
|
||||
popup_set_text(popup, NULL, 0, 0, AlignCenter, AlignTop);
|
||||
popup_set_icon(popup, 0, 0, NULL);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#pragma once
|
||||
#include "ibutton_scene_generic.h"
|
||||
#include "../helpers/key_emulator.h"
|
||||
|
||||
class iButtonSceneEmulate : public iButtonScene {
|
||||
public:
|
||||
|
||||
@@ -1,24 +1,30 @@
|
||||
#include "ibutton_scene_info.h"
|
||||
#include "../ibutton_app.h"
|
||||
#include "../ibutton_view_manager.h"
|
||||
#include "../ibutton_event.h"
|
||||
#include <callback-connector.h>
|
||||
|
||||
static void widget_callback(GuiButtonType result, InputType type, void* context) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
|
||||
if(type == InputTypeShort) {
|
||||
event.type = iButtonEvent::Type::EventTypeWidgetButtonResult;
|
||||
event.payload.widget_button_result = result;
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
||||
}
|
||||
|
||||
void iButtonSceneInfo::on_enter(iButtonApp* app) {
|
||||
iButtonAppViewManager* view_manager = app->get_view_manager();
|
||||
Widget* widget = view_manager->get_widget();
|
||||
auto callback = cbc::obtain_connector(this, &iButtonSceneInfo::widget_callback);
|
||||
|
||||
iButtonKey* key = app->get_key();
|
||||
uint8_t* key_data = key->get_data();
|
||||
const uint8_t* key_data = ibutton_key_get_data_p(key);
|
||||
|
||||
app->set_text_store("%s", key->get_name());
|
||||
app->set_text_store("%s", ibutton_key_get_name_p(key));
|
||||
widget_add_text_box_element(
|
||||
widget, 0, 0, 128, 27, AlignCenter, AlignCenter, app->get_text_store());
|
||||
widget_add_button_element(widget, GuiButtonTypeLeft, "Back", callback, app);
|
||||
widget_add_button_element(widget, GuiButtonTypeLeft, "Back", widget_callback, app);
|
||||
|
||||
switch(key->get_key_type()) {
|
||||
case iButtonKeyType::KeyDallas:
|
||||
switch(ibutton_key_get_type(key)) {
|
||||
case iButtonKeyDS1990:
|
||||
app->set_text_store(
|
||||
"%02X %02X %02X %02X %02X %02X %02X %02X",
|
||||
key_data[0],
|
||||
@@ -32,13 +38,13 @@ void iButtonSceneInfo::on_enter(iButtonApp* app) {
|
||||
widget_add_string_element(
|
||||
widget, 64, 45, AlignCenter, AlignBottom, FontSecondary, "Dallas");
|
||||
break;
|
||||
case iButtonKeyType::KeyMetakom:
|
||||
case iButtonKeyMetakom:
|
||||
app->set_text_store(
|
||||
"%02X %02X %02X %02X", key_data[0], key_data[1], key_data[2], key_data[3]);
|
||||
widget_add_string_element(
|
||||
widget, 64, 45, AlignCenter, AlignBottom, FontSecondary, "Metakom");
|
||||
break;
|
||||
case iButtonKeyType::KeyCyfral:
|
||||
case iButtonKeyCyfral:
|
||||
app->set_text_store("%02X %02X", key_data[0], key_data[1]);
|
||||
widget_add_string_element(
|
||||
widget, 64, 45, AlignCenter, AlignBottom, FontSecondary, "Cyfral");
|
||||
@@ -71,15 +77,3 @@ void iButtonSceneInfo::on_exit(iButtonApp* app) {
|
||||
|
||||
widget_reset(widget);
|
||||
}
|
||||
|
||||
void iButtonSceneInfo::widget_callback(GuiButtonType result, InputType type, void* context) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
|
||||
if(type == InputTypeShort) {
|
||||
event.type = iButtonEvent::Type::EventTypeWidgetButtonResult;
|
||||
event.payload.widget_button_result = result;
|
||||
}
|
||||
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,4 @@ public:
|
||||
void on_enter(iButtonApp* app) final;
|
||||
bool on_event(iButtonApp* app, iButtonEvent* event) final;
|
||||
void on_exit(iButtonApp* app) final;
|
||||
|
||||
private:
|
||||
void widget_callback(GuiButtonType result, InputType type, void* context);
|
||||
};
|
||||
@@ -1,12 +1,18 @@
|
||||
#include "ibutton_scene_read.h"
|
||||
#include "../ibutton_app.h"
|
||||
#include "../ibutton_view_manager.h"
|
||||
#include "../ibutton_event.h"
|
||||
#include <dolphin/dolphin.h>
|
||||
|
||||
static void read_callback(void* context) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event = {.type = iButtonEvent::Type::EventTypeWorkerRead};
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
||||
|
||||
void iButtonSceneRead::on_enter(iButtonApp* app) {
|
||||
iButtonAppViewManager* view_manager = app->get_view_manager();
|
||||
Popup* popup = view_manager->get_popup();
|
||||
iButtonKey* key = app->get_key();
|
||||
iButtonWorker* worker = app->get_key_worker();
|
||||
DOLPHIN_DEED(DolphinDeedIbuttonRead);
|
||||
|
||||
popup_set_header(popup, "iButton", 95, 26, AlignCenter, AlignBottom);
|
||||
@@ -14,41 +20,41 @@ void iButtonSceneRead::on_enter(iButtonApp* app) {
|
||||
popup_set_icon(popup, 0, 5, &I_DolphinWait_61x59);
|
||||
|
||||
view_manager->switch_to(iButtonAppViewManager::Type::iButtonAppViewPopup);
|
||||
app->get_key()->set_name("");
|
||||
ibutton_key_set_name(key, "");
|
||||
|
||||
app->get_key_worker()->start_read();
|
||||
ibutton_worker_read_set_callback(worker, read_callback, app);
|
||||
ibutton_worker_read_start(worker, key);
|
||||
}
|
||||
|
||||
bool iButtonSceneRead::on_event(iButtonApp* app, iButtonEvent* event) {
|
||||
bool consumed = false;
|
||||
|
||||
if(event->type == iButtonEvent::Type::EventTypeTick) {
|
||||
if(event->type == iButtonEvent::Type::EventTypeWorkerRead) {
|
||||
consumed = true;
|
||||
|
||||
iButtonKey* key = app->get_key();
|
||||
if(ibutton_key_get_type(key) == iButtonKeyDS1990) {
|
||||
if(!ibutton_key_dallas_crc_is_valid(key)) {
|
||||
app->switch_to_next_scene(iButtonApp::Scene::SceneReadCRCError);
|
||||
} else if(!ibutton_key_dallas_is_1990_key(key)) {
|
||||
app->switch_to_next_scene(iButtonApp::Scene::SceneReadNotKeyError);
|
||||
} else {
|
||||
app->switch_to_next_scene(iButtonApp::Scene::SceneReadSuccess);
|
||||
}
|
||||
} else {
|
||||
app->switch_to_next_scene(iButtonApp::Scene::SceneReadSuccess);
|
||||
}
|
||||
} else if(event->type == iButtonEvent::Type::EventTypeTick) {
|
||||
consumed = true;
|
||||
app->notify_red_blink();
|
||||
|
||||
switch(app->get_key_worker()->read(app->get_key())) {
|
||||
case KeyReader::Error::EMPTY:
|
||||
break;
|
||||
case KeyReader::Error::OK:
|
||||
app->switch_to_next_scene(iButtonApp::Scene::SceneReadSuccess);
|
||||
break;
|
||||
case KeyReader::Error::CRC_ERROR:
|
||||
app->switch_to_next_scene(iButtonApp::Scene::SceneReadCRCError);
|
||||
break;
|
||||
case KeyReader::Error::NOT_ARE_KEY:
|
||||
app->switch_to_next_scene(iButtonApp::Scene::SceneReadNotKeyError);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void iButtonSceneRead::on_exit(iButtonApp* app) {
|
||||
app->get_key_worker()->stop_read();
|
||||
|
||||
Popup* popup = app->get_view_manager()->get_popup();
|
||||
|
||||
ibutton_worker_stop(app->get_key_worker());
|
||||
popup_set_header(popup, NULL, 0, 0, AlignCenter, AlignBottom);
|
||||
popup_set_text(popup, NULL, 0, 0, AlignCenter, AlignTop);
|
||||
popup_set_icon(popup, 0, 0, NULL);
|
||||
|
||||
@@ -6,6 +6,4 @@ public:
|
||||
void on_enter(iButtonApp* app) final;
|
||||
bool on_event(iButtonApp* app, iButtonEvent* event) final;
|
||||
void on_exit(iButtonApp* app) final;
|
||||
|
||||
private:
|
||||
};
|
||||
@@ -1,16 +1,21 @@
|
||||
#include "ibutton_scene_read_crc_error.h"
|
||||
#include "../ibutton_app.h"
|
||||
#include "../ibutton_view_manager.h"
|
||||
#include "../ibutton_event.h"
|
||||
#include <callback-connector.h>
|
||||
#include <one_wire/maxim_crc.h>
|
||||
|
||||
static void dialog_ex_callback(DialogExResult result, void* context) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
|
||||
event.type = iButtonEvent::Type::EventTypeDialogResult;
|
||||
event.payload.dialog_result = result;
|
||||
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
||||
|
||||
void iButtonSceneReadCRCError::on_enter(iButtonApp* app) {
|
||||
iButtonAppViewManager* view_manager = app->get_view_manager();
|
||||
DialogEx* dialog_ex = view_manager->get_dialog_ex();
|
||||
auto callback = cbc::obtain_connector(this, &iButtonSceneReadCRCError::dialog_ex_callback);
|
||||
|
||||
iButtonKey* key = app->get_key();
|
||||
uint8_t* key_data = key->get_data();
|
||||
const uint8_t* key_data = ibutton_key_get_data_p(app->get_key());
|
||||
|
||||
app->set_text_store(
|
||||
"%02X %02X %02X %02X %02X %02X %02X %02X\nExpected CRC: %X",
|
||||
@@ -22,13 +27,13 @@ void iButtonSceneReadCRCError::on_enter(iButtonApp* app) {
|
||||
key_data[5],
|
||||
key_data[6],
|
||||
key_data[7],
|
||||
maxim_crc8(key_data, 7));
|
||||
maxim_crc8(key_data, 7, MAXIM_CRC8_INIT));
|
||||
|
||||
dialog_ex_set_header(dialog_ex, "CRC ERROR", 64, 10, AlignCenter, AlignCenter);
|
||||
dialog_ex_set_text(dialog_ex, app->get_text_store(), 64, 19, AlignCenter, AlignTop);
|
||||
dialog_ex_set_left_button_text(dialog_ex, "Retry");
|
||||
dialog_ex_set_right_button_text(dialog_ex, "More");
|
||||
dialog_ex_set_result_callback(dialog_ex, callback);
|
||||
dialog_ex_set_result_callback(dialog_ex, dialog_ex_callback);
|
||||
dialog_ex_set_context(dialog_ex, app);
|
||||
|
||||
view_manager->switch_to(iButtonAppViewManager::Type::iButtonAppViewDialogEx);
|
||||
@@ -65,14 +70,4 @@ void iButtonSceneReadCRCError::on_exit(iButtonApp* app) {
|
||||
dialog_ex_set_context(dialog_ex, NULL);
|
||||
|
||||
app->notify_red_off();
|
||||
}
|
||||
|
||||
void iButtonSceneReadCRCError::dialog_ex_callback(DialogExResult result, void* context) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
|
||||
event.type = iButtonEvent::Type::EventTypeDialogResult;
|
||||
event.payload.dialog_result = result;
|
||||
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
||||
@@ -1,13 +1,9 @@
|
||||
#pragma once
|
||||
#include "ibutton_scene_generic.h"
|
||||
#include <gui/modules/dialog_ex.h>
|
||||
|
||||
class iButtonSceneReadCRCError : public iButtonScene {
|
||||
public:
|
||||
void on_enter(iButtonApp* app) final;
|
||||
bool on_event(iButtonApp* app, iButtonEvent* event) final;
|
||||
void on_exit(iButtonApp* app) final;
|
||||
|
||||
private:
|
||||
void dialog_ex_callback(DialogExResult result, void* context);
|
||||
};
|
||||
@@ -1,16 +1,21 @@
|
||||
#include "ibutton_scene_read_not_key_error.h"
|
||||
#include "../ibutton_app.h"
|
||||
#include "../ibutton_view_manager.h"
|
||||
#include "../ibutton_event.h"
|
||||
#include <callback-connector.h>
|
||||
#include <one_wire/maxim_crc.h>
|
||||
|
||||
static void dialog_ex_callback(DialogExResult result, void* context) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
|
||||
event.type = iButtonEvent::Type::EventTypeDialogResult;
|
||||
event.payload.dialog_result = result;
|
||||
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
||||
|
||||
void iButtonSceneReadNotKeyError::on_enter(iButtonApp* app) {
|
||||
iButtonAppViewManager* view_manager = app->get_view_manager();
|
||||
DialogEx* dialog_ex = view_manager->get_dialog_ex();
|
||||
auto callback = cbc::obtain_connector(this, &iButtonSceneReadNotKeyError::dialog_ex_callback);
|
||||
|
||||
iButtonKey* key = app->get_key();
|
||||
uint8_t* key_data = key->get_data();
|
||||
const uint8_t* key_data = ibutton_key_get_data_p(app->get_key());
|
||||
|
||||
app->set_text_store(
|
||||
"THIS IS NOT A KEY\n%02X %02X %02X %02X %02X %02X %02X %02X",
|
||||
@@ -22,13 +27,13 @@ void iButtonSceneReadNotKeyError::on_enter(iButtonApp* app) {
|
||||
key_data[5],
|
||||
key_data[6],
|
||||
key_data[7],
|
||||
maxim_crc8(key_data, 7));
|
||||
maxim_crc8(key_data, 7, MAXIM_CRC8_INIT));
|
||||
|
||||
dialog_ex_set_header(dialog_ex, "ERROR:", 64, 10, AlignCenter, AlignCenter);
|
||||
dialog_ex_set_text(dialog_ex, app->get_text_store(), 64, 19, AlignCenter, AlignTop);
|
||||
dialog_ex_set_left_button_text(dialog_ex, "Retry");
|
||||
dialog_ex_set_right_button_text(dialog_ex, "More");
|
||||
dialog_ex_set_result_callback(dialog_ex, callback);
|
||||
dialog_ex_set_result_callback(dialog_ex, dialog_ex_callback);
|
||||
dialog_ex_set_context(dialog_ex, app);
|
||||
|
||||
view_manager->switch_to(iButtonAppViewManager::Type::iButtonAppViewDialogEx);
|
||||
@@ -65,14 +70,4 @@ void iButtonSceneReadNotKeyError::on_exit(iButtonApp* app) {
|
||||
dialog_ex_set_context(dialog_ex, NULL);
|
||||
|
||||
app->notify_red_off();
|
||||
}
|
||||
|
||||
void iButtonSceneReadNotKeyError::dialog_ex_callback(DialogExResult result, void* context) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
|
||||
event.type = iButtonEvent::Type::EventTypeDialogResult;
|
||||
event.payload.dialog_result = result;
|
||||
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
||||
@@ -1,13 +1,9 @@
|
||||
#pragma once
|
||||
#include "ibutton_scene_generic.h"
|
||||
#include <gui/modules/dialog_ex.h>
|
||||
|
||||
class iButtonSceneReadNotKeyError : public iButtonScene {
|
||||
public:
|
||||
void on_enter(iButtonApp* app) final;
|
||||
bool on_event(iButtonApp* app, iButtonEvent* event) final;
|
||||
void on_exit(iButtonApp* app) final;
|
||||
|
||||
private:
|
||||
void dialog_ex_callback(DialogExResult result, void* context);
|
||||
};
|
||||
@@ -1,21 +1,26 @@
|
||||
#include "ibutton_scene_read_success.h"
|
||||
#include "../ibutton_app.h"
|
||||
#include "../ibutton_view_manager.h"
|
||||
#include "../ibutton_event.h"
|
||||
#include <dolphin/dolphin.h>
|
||||
#include <callback-connector.h>
|
||||
|
||||
static void dialog_ex_callback(DialogExResult result, void* context) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
|
||||
event.type = iButtonEvent::Type::EventTypeDialogResult;
|
||||
event.payload.dialog_result = result;
|
||||
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
||||
|
||||
void iButtonSceneReadSuccess::on_enter(iButtonApp* app) {
|
||||
iButtonAppViewManager* view_manager = app->get_view_manager();
|
||||
DialogEx* dialog_ex = view_manager->get_dialog_ex();
|
||||
auto callback = cbc::obtain_connector(this, &iButtonSceneReadSuccess::dialog_ex_callback);
|
||||
iButtonKey* key = app->get_key();
|
||||
const uint8_t* key_data = ibutton_key_get_data_p(key);
|
||||
DOLPHIN_DEED(DolphinDeedIbuttonReadSuccess);
|
||||
|
||||
iButtonKey* key = app->get_key();
|
||||
uint8_t* key_data = key->get_data();
|
||||
|
||||
switch(key->get_key_type()) {
|
||||
case iButtonKeyType::KeyDallas:
|
||||
switch(ibutton_key_get_type(key)) {
|
||||
case iButtonKeyDS1990:
|
||||
app->set_text_store(
|
||||
"Dallas\n%02X %02X %02X %02X\n%02X %02X %02X %02X",
|
||||
key_data[0],
|
||||
@@ -27,10 +32,10 @@ void iButtonSceneReadSuccess::on_enter(iButtonApp* app) {
|
||||
key_data[6],
|
||||
key_data[7]);
|
||||
break;
|
||||
case iButtonKeyType::KeyCyfral:
|
||||
case iButtonKeyCyfral:
|
||||
app->set_text_store("Cyfral\n%02X %02X", key_data[0], key_data[1]);
|
||||
break;
|
||||
case iButtonKeyType::KeyMetakom:
|
||||
case iButtonKeyMetakom:
|
||||
app->set_text_store(
|
||||
"Metakom\n%02X %02X %02X %02X", key_data[0], key_data[1], key_data[2], key_data[3]);
|
||||
break;
|
||||
@@ -40,7 +45,7 @@ void iButtonSceneReadSuccess::on_enter(iButtonApp* app) {
|
||||
dialog_ex_set_left_button_text(dialog_ex, "Retry");
|
||||
dialog_ex_set_right_button_text(dialog_ex, "More");
|
||||
dialog_ex_set_icon(dialog_ex, 0, 1, &I_DolphinExcited_64x63);
|
||||
dialog_ex_set_result_callback(dialog_ex, callback);
|
||||
dialog_ex_set_result_callback(dialog_ex, dialog_ex_callback);
|
||||
dialog_ex_set_context(dialog_ex, app);
|
||||
|
||||
view_manager->switch_to(iButtonAppViewManager::Type::iButtonAppViewDialogEx);
|
||||
@@ -80,13 +85,3 @@ void iButtonSceneReadSuccess::on_exit(iButtonApp* app) {
|
||||
|
||||
app->notify_green_off();
|
||||
}
|
||||
|
||||
void iButtonSceneReadSuccess::dialog_ex_callback(DialogExResult result, void* context) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
|
||||
event.type = iButtonEvent::Type::EventTypeDialogResult;
|
||||
event.payload.dialog_result = result;
|
||||
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
#pragma once
|
||||
#include "ibutton_scene_generic.h"
|
||||
#include <gui/modules/dialog_ex.h>
|
||||
|
||||
class iButtonSceneReadSuccess : public iButtonScene {
|
||||
public:
|
||||
void on_enter(iButtonApp* app) final;
|
||||
bool on_event(iButtonApp* app, iButtonEvent* event) final;
|
||||
void on_exit(iButtonApp* app) final;
|
||||
|
||||
private:
|
||||
void dialog_ex_callback(DialogExResult result, void* context);
|
||||
};
|
||||
@@ -1,8 +1,5 @@
|
||||
#include "ibutton_scene_readed_key_menu.h"
|
||||
#include "../ibutton_app.h"
|
||||
#include "../ibutton_view_manager.h"
|
||||
#include "../ibutton_event.h"
|
||||
#include <callback-connector.h>
|
||||
|
||||
typedef enum {
|
||||
SubmenuIndexWrite,
|
||||
@@ -11,17 +8,26 @@ typedef enum {
|
||||
SubmenuIndexReadNewKey,
|
||||
} SubmenuIndex;
|
||||
|
||||
static void submenu_callback(void* context, uint32_t index) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
|
||||
event.type = iButtonEvent::Type::EventTypeMenuSelected;
|
||||
event.payload.menu_index = index;
|
||||
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
||||
|
||||
void iButtonSceneReadedKeyMenu::on_enter(iButtonApp* app) {
|
||||
iButtonAppViewManager* view_manager = app->get_view_manager();
|
||||
Submenu* submenu = view_manager->get_submenu();
|
||||
auto callback = cbc::obtain_connector(this, &iButtonSceneReadedKeyMenu::submenu_callback);
|
||||
|
||||
if(app->get_key()->get_key_type() == iButtonKeyType::KeyDallas) {
|
||||
submenu_add_item(submenu, "Write", SubmenuIndexWrite, callback, app);
|
||||
if(ibutton_key_get_type(app->get_key()) == iButtonKeyDS1990) {
|
||||
submenu_add_item(submenu, "Write", SubmenuIndexWrite, submenu_callback, app);
|
||||
}
|
||||
submenu_add_item(submenu, "Name and save", SubmenuIndexNameAndSave, callback, app);
|
||||
submenu_add_item(submenu, "Emulate", SubmenuIndexEmulate, callback, app);
|
||||
submenu_add_item(submenu, "Read new key", SubmenuIndexReadNewKey, callback, app);
|
||||
submenu_add_item(submenu, "Name and save", SubmenuIndexNameAndSave, submenu_callback, app);
|
||||
submenu_add_item(submenu, "Emulate", SubmenuIndexEmulate, submenu_callback, app);
|
||||
submenu_add_item(submenu, "Read new key", SubmenuIndexReadNewKey, submenu_callback, app);
|
||||
submenu_set_selected_item(submenu, submenu_item_selected);
|
||||
|
||||
view_manager->switch_to(iButtonAppViewManager::Type::iButtonAppViewSubmenu);
|
||||
@@ -60,14 +66,4 @@ void iButtonSceneReadedKeyMenu::on_exit(iButtonApp* app) {
|
||||
Submenu* submenu = view->get_submenu();
|
||||
|
||||
submenu_reset(submenu);
|
||||
}
|
||||
|
||||
void iButtonSceneReadedKeyMenu::submenu_callback(void* context, uint32_t index) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
|
||||
event.type = iButtonEvent::Type::EventTypeMenuSelected;
|
||||
event.payload.menu_index = index;
|
||||
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,5 @@ public:
|
||||
void on_exit(iButtonApp* app) final;
|
||||
|
||||
private:
|
||||
void submenu_callback(void* context, uint32_t index);
|
||||
uint32_t submenu_item_selected = 0;
|
||||
};
|
||||
@@ -1,18 +1,21 @@
|
||||
#include "ibutton_scene_save_name.h"
|
||||
#include "../ibutton_app.h"
|
||||
#include "../ibutton_view_manager.h"
|
||||
#include "../ibutton_event.h"
|
||||
#include "../ibutton_key.h"
|
||||
#include <callback-connector.h>
|
||||
#include <lib/toolbox/random_name.h>
|
||||
|
||||
static void text_input_callback(void* context) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
|
||||
event.type = iButtonEvent::Type::EventTypeTextEditResult;
|
||||
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
||||
|
||||
void iButtonSceneSaveName::on_enter(iButtonApp* app) {
|
||||
iButtonAppViewManager* view_manager = app->get_view_manager();
|
||||
TextInput* text_input = view_manager->get_text_input();
|
||||
auto callback = cbc::obtain_connector(this, &iButtonSceneSaveName::text_input_callback);
|
||||
|
||||
iButtonKey* key = app->get_key();
|
||||
const char* key_name = key->get_name();
|
||||
const char* key_name = ibutton_key_get_name_p(app->get_key());
|
||||
bool key_name_empty = !strcmp(key_name, "");
|
||||
|
||||
if(key_name_empty) {
|
||||
@@ -23,7 +26,12 @@ void iButtonSceneSaveName::on_enter(iButtonApp* app) {
|
||||
|
||||
text_input_set_header_text(text_input, "Name the key");
|
||||
text_input_set_result_callback(
|
||||
text_input, callback, app, app->get_text_store(), IBUTTON_KEY_NAME_SIZE, key_name_empty);
|
||||
text_input,
|
||||
text_input_callback,
|
||||
app,
|
||||
app->get_text_store(),
|
||||
IBUTTON_KEY_NAME_SIZE,
|
||||
key_name_empty);
|
||||
|
||||
ValidatorIsFile* validator_is_file =
|
||||
validator_is_file_alloc_init(app->app_folder, app->app_extension);
|
||||
@@ -59,12 +67,3 @@ void iButtonSceneSaveName::on_exit(iButtonApp* app) {
|
||||
|
||||
text_input_reset(text_input);
|
||||
}
|
||||
|
||||
void iButtonSceneSaveName::text_input_callback(void* context) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
|
||||
event.type = iButtonEvent::Type::EventTypeTextEditResult;
|
||||
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,4 @@ public:
|
||||
void on_enter(iButtonApp* app) final;
|
||||
bool on_event(iButtonApp* app, iButtonEvent* event) final;
|
||||
void on_exit(iButtonApp* app) final;
|
||||
|
||||
private:
|
||||
void text_input_callback(void* context);
|
||||
};
|
||||
@@ -1,21 +1,23 @@
|
||||
#include "ibutton_scene_save_success.h"
|
||||
#include "../ibutton_app.h"
|
||||
#include "../ibutton_view_manager.h"
|
||||
#include "../ibutton_event.h"
|
||||
#include "../ibutton_key.h"
|
||||
#include <dolphin/dolphin.h>
|
||||
#include <callback-connector.h>
|
||||
|
||||
static void popup_callback(void* context) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
event.type = iButtonEvent::Type::EventTypeBack;
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
||||
|
||||
void iButtonSceneSaveSuccess::on_enter(iButtonApp* app) {
|
||||
iButtonAppViewManager* view_manager = app->get_view_manager();
|
||||
Popup* popup = view_manager->get_popup();
|
||||
auto callback = cbc::obtain_connector(this, &iButtonSceneSaveSuccess::popup_callback);
|
||||
DOLPHIN_DEED(DolphinDeedIbuttonSave);
|
||||
|
||||
popup_set_icon(popup, 32, 5, &I_DolphinNice_96x59);
|
||||
popup_set_text(popup, "Saved!", 13, 22, AlignLeft, AlignBottom);
|
||||
|
||||
popup_set_callback(popup, callback);
|
||||
popup_set_callback(popup, popup_callback);
|
||||
popup_set_context(popup, app);
|
||||
popup_set_timeout(popup, 1500);
|
||||
popup_enable_timeout(popup);
|
||||
@@ -46,11 +48,4 @@ void iButtonSceneSaveSuccess::on_exit(iButtonApp* app) {
|
||||
popup_disable_timeout(popup);
|
||||
popup_set_context(popup, NULL);
|
||||
popup_set_callback(popup, NULL);
|
||||
}
|
||||
|
||||
void iButtonSceneSaveSuccess::popup_callback(void* context) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
event.type = iButtonEvent::Type::EventTypeBack;
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,4 @@ public:
|
||||
void on_enter(iButtonApp* app) final;
|
||||
bool on_event(iButtonApp* app, iButtonEvent* event) final;
|
||||
void on_exit(iButtonApp* app) final;
|
||||
|
||||
private:
|
||||
void popup_callback(void* context);
|
||||
};
|
||||
@@ -1,7 +1,5 @@
|
||||
#include "ibutton_scene_saved_key_menu.h"
|
||||
#include "../ibutton_app.h"
|
||||
#include "../ibutton_view_manager.h"
|
||||
#include "../ibutton_event.h"
|
||||
#include <callback-connector.h>
|
||||
|
||||
typedef enum {
|
||||
@@ -12,18 +10,27 @@ typedef enum {
|
||||
SubmenuIndexInfo,
|
||||
} SubmenuIndex;
|
||||
|
||||
static void submenu_callback(void* context, uint32_t index) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
|
||||
event.type = iButtonEvent::Type::EventTypeMenuSelected;
|
||||
event.payload.menu_index = index;
|
||||
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
||||
|
||||
void iButtonSceneSavedKeyMenu::on_enter(iButtonApp* app) {
|
||||
iButtonAppViewManager* view_manager = app->get_view_manager();
|
||||
Submenu* submenu = view_manager->get_submenu();
|
||||
auto callback = cbc::obtain_connector(this, &iButtonSceneSavedKeyMenu::submenu_callback);
|
||||
|
||||
submenu_add_item(submenu, "Emulate", SubmenuIndexEmulate, callback, app);
|
||||
if(app->get_key()->get_key_type() == iButtonKeyType::KeyDallas) {
|
||||
submenu_add_item(submenu, "Write", SubmenuIndexWrite, callback, app);
|
||||
submenu_add_item(submenu, "Emulate", SubmenuIndexEmulate, submenu_callback, app);
|
||||
if(ibutton_key_get_type(app->get_key()) == iButtonKeyDS1990) {
|
||||
submenu_add_item(submenu, "Write", SubmenuIndexWrite, submenu_callback, app);
|
||||
}
|
||||
submenu_add_item(submenu, "Edit", SubmenuIndexEdit, callback, app);
|
||||
submenu_add_item(submenu, "Delete", SubmenuIndexDelete, callback, app);
|
||||
submenu_add_item(submenu, "Info", SubmenuIndexInfo, callback, app);
|
||||
submenu_add_item(submenu, "Edit", SubmenuIndexEdit, submenu_callback, app);
|
||||
submenu_add_item(submenu, "Delete", SubmenuIndexDelete, submenu_callback, app);
|
||||
submenu_add_item(submenu, "Info", SubmenuIndexInfo, submenu_callback, app);
|
||||
submenu_set_selected_item(submenu, submenu_item_selected);
|
||||
|
||||
view_manager->switch_to(iButtonAppViewManager::Type::iButtonAppViewSubmenu);
|
||||
@@ -63,13 +70,3 @@ void iButtonSceneSavedKeyMenu::on_exit(iButtonApp* app) {
|
||||
|
||||
submenu_reset(submenu);
|
||||
}
|
||||
|
||||
void iButtonSceneSavedKeyMenu::submenu_callback(void* context, uint32_t index) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
|
||||
event.type = iButtonEvent::Type::EventTypeMenuSelected;
|
||||
event.payload.menu_index = index;
|
||||
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
||||
|
||||
@@ -8,6 +8,5 @@ public:
|
||||
void on_exit(iButtonApp* app) final;
|
||||
|
||||
private:
|
||||
void submenu_callback(void* context, uint32_t index);
|
||||
uint32_t submenu_item_selected = 0;
|
||||
};
|
||||
@@ -1,7 +1,5 @@
|
||||
#include "ibutton_scene_select_key.h"
|
||||
#include "../ibutton_app.h"
|
||||
#include "../ibutton_event.h"
|
||||
#include "../ibutton_key.h"
|
||||
|
||||
void iButtonSceneSelectKey::on_enter(iButtonApp* app) {
|
||||
// Process file_select return
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
#include "ibutton_scene_start.h"
|
||||
#include "../ibutton_app.h"
|
||||
#include "../ibutton_view_manager.h"
|
||||
#include "../ibutton_event.h"
|
||||
#include <callback-connector.h>
|
||||
|
||||
typedef enum {
|
||||
SubmenuIndexRead,
|
||||
@@ -10,14 +7,23 @@ typedef enum {
|
||||
SubmenuIndexAdd,
|
||||
} SubmenuIndex;
|
||||
|
||||
static void submenu_callback(void* context, uint32_t index) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
|
||||
event.type = iButtonEvent::Type::EventTypeMenuSelected;
|
||||
event.payload.menu_index = index;
|
||||
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
||||
|
||||
void iButtonSceneStart::on_enter(iButtonApp* app) {
|
||||
iButtonAppViewManager* view_manager = app->get_view_manager();
|
||||
Submenu* submenu = view_manager->get_submenu();
|
||||
auto callback = cbc::obtain_connector(this, &iButtonSceneStart::submenu_callback);
|
||||
|
||||
submenu_add_item(submenu, "Read", SubmenuIndexRead, callback, app);
|
||||
submenu_add_item(submenu, "Saved", SubmenuIndexSaved, callback, app);
|
||||
submenu_add_item(submenu, "Add manually", SubmenuIndexAdd, callback, app);
|
||||
submenu_add_item(submenu, "Read", SubmenuIndexRead, submenu_callback, app);
|
||||
submenu_add_item(submenu, "Saved", SubmenuIndexSaved, submenu_callback, app);
|
||||
submenu_add_item(submenu, "Add manually", SubmenuIndexAdd, submenu_callback, app);
|
||||
submenu_set_selected_item(submenu, submenu_item_selected);
|
||||
|
||||
view_manager->switch_to(iButtonAppViewManager::Type::iButtonAppViewSubmenu);
|
||||
@@ -51,13 +57,3 @@ void iButtonSceneStart::on_exit(iButtonApp* app) {
|
||||
|
||||
submenu_reset(submenu);
|
||||
}
|
||||
|
||||
void iButtonSceneStart::submenu_callback(void* context, uint32_t index) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
|
||||
event.type = iButtonEvent::Type::EventTypeMenuSelected;
|
||||
event.payload.menu_index = index;
|
||||
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
||||
|
||||
@@ -8,6 +8,5 @@ public:
|
||||
void on_exit(iButtonApp* app) final;
|
||||
|
||||
private:
|
||||
void submenu_callback(void* context, uint32_t index);
|
||||
uint32_t submenu_item_selected = 0;
|
||||
};
|
||||
@@ -1,15 +1,22 @@
|
||||
#include "ibutton_scene_write.h"
|
||||
#include "../ibutton_app.h"
|
||||
#include "../ibutton_view_manager.h"
|
||||
#include "../ibutton_event.h"
|
||||
#include "../ibutton_key.h"
|
||||
|
||||
static void ibutton_worker_write_cb(void* context, iButtonWorkerWriteResult result) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
event.type = iButtonEvent::Type::EventTypeWorkerWrite;
|
||||
event.payload.worker_write_result = result;
|
||||
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
||||
|
||||
void iButtonSceneWrite::on_enter(iButtonApp* app) {
|
||||
iButtonAppViewManager* view_manager = app->get_view_manager();
|
||||
Popup* popup = view_manager->get_popup();
|
||||
iButtonKey* key = app->get_key();
|
||||
uint8_t* key_data = key->get_data();
|
||||
const char* key_name = key->get_name();
|
||||
iButtonWorker* worker = app->get_key_worker();
|
||||
const uint8_t* key_data = ibutton_key_get_data_p(key);
|
||||
const char* key_name = ibutton_key_get_name_p(key);
|
||||
uint8_t line_count = 2;
|
||||
|
||||
// check that stored key has name
|
||||
@@ -18,8 +25,8 @@ void iButtonSceneWrite::on_enter(iButtonApp* app) {
|
||||
line_count = 2;
|
||||
} else {
|
||||
// if not, show key data
|
||||
switch(key->get_key_type()) {
|
||||
case iButtonKeyType::KeyDallas:
|
||||
switch(ibutton_key_get_type(key)) {
|
||||
case iButtonKeyDS1990:
|
||||
app->set_text_store(
|
||||
"writing\n%02X %02X %02X %02X\n%02X %02X %02X %02X",
|
||||
key_data[0],
|
||||
@@ -32,11 +39,11 @@ void iButtonSceneWrite::on_enter(iButtonApp* app) {
|
||||
key_data[7]);
|
||||
line_count = 3;
|
||||
break;
|
||||
case iButtonKeyType::KeyCyfral:
|
||||
case iButtonKeyCyfral:
|
||||
app->set_text_store("writing\n%02X %02X", key_data[0], key_data[1]);
|
||||
line_count = 2;
|
||||
break;
|
||||
case iButtonKeyType::KeyMetakom:
|
||||
case iButtonKeyMetakom:
|
||||
app->set_text_store(
|
||||
"writing\n%02X %02X %02X %02X", key_data[0], key_data[1], key_data[2], key_data[3]);
|
||||
line_count = 2;
|
||||
@@ -60,27 +67,34 @@ void iButtonSceneWrite::on_enter(iButtonApp* app) {
|
||||
|
||||
view_manager->switch_to(iButtonAppViewManager::Type::iButtonAppViewPopup);
|
||||
|
||||
app->get_key_worker()->start_write();
|
||||
blink_yellow = false;
|
||||
ibutton_worker_write_set_callback(worker, ibutton_worker_write_cb, app);
|
||||
ibutton_worker_write_start(worker, key);
|
||||
}
|
||||
|
||||
bool iButtonSceneWrite::on_event(iButtonApp* app, iButtonEvent* event) {
|
||||
bool consumed = false;
|
||||
|
||||
if(event->type == iButtonEvent::Type::EventTypeTick) {
|
||||
if(event->type == iButtonEvent::Type::EventTypeWorkerWrite) {
|
||||
consumed = true;
|
||||
KeyWriter::Error result = app->get_key_worker()->write(app->get_key());
|
||||
|
||||
switch(result) {
|
||||
case KeyWriter::Error::SAME_KEY:
|
||||
case KeyWriter::Error::OK:
|
||||
switch(event->payload.worker_write_result) {
|
||||
case iButtonWorkerWriteOK:
|
||||
case iButtonWorkerWriteSameKey:
|
||||
app->switch_to_next_scene(iButtonApp::Scene::SceneWriteSuccess);
|
||||
break;
|
||||
case KeyWriter::Error::NO_DETECT:
|
||||
app->notify_red_blink();
|
||||
case iButtonWorkerWriteNoDetect:
|
||||
blink_yellow = false;
|
||||
break;
|
||||
case KeyWriter::Error::CANNOT_WRITE:
|
||||
case iButtonWorkerWriteCannotWrite:
|
||||
blink_yellow = true;
|
||||
break;
|
||||
}
|
||||
} else if(event->type == iButtonEvent::Type::EventTypeTick) {
|
||||
if(blink_yellow) {
|
||||
app->notify_yellow_blink();
|
||||
break;
|
||||
} else {
|
||||
app->notify_red_blink();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,10 +103,8 @@ bool iButtonSceneWrite::on_event(iButtonApp* app, iButtonEvent* event) {
|
||||
|
||||
void iButtonSceneWrite::on_exit(iButtonApp* app) {
|
||||
Popup* popup = app->get_view_manager()->get_popup();
|
||||
|
||||
ibutton_worker_stop(app->get_key_worker());
|
||||
popup_set_header(popup, NULL, 0, 0, AlignCenter, AlignBottom);
|
||||
popup_set_text(popup, NULL, 0, 0, AlignCenter, AlignTop);
|
||||
popup_set_icon(popup, 0, 0, NULL);
|
||||
|
||||
app->get_key_worker()->stop_write();
|
||||
}
|
||||
@@ -8,4 +8,5 @@ public:
|
||||
void on_exit(iButtonApp* app) final;
|
||||
|
||||
private:
|
||||
bool blink_yellow;
|
||||
};
|
||||
@@ -1,19 +1,22 @@
|
||||
#include "ibutton_scene_write_success.h"
|
||||
#include "../ibutton_app.h"
|
||||
#include "../ibutton_view_manager.h"
|
||||
#include "../ibutton_event.h"
|
||||
#include "../ibutton_key.h"
|
||||
#include <callback-connector.h>
|
||||
|
||||
static void popup_callback(void* context) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
event.type = iButtonEvent::Type::EventTypeBack;
|
||||
app->get_view_manager()->send_event(&event);
|
||||
app->notify_green_off();
|
||||
}
|
||||
|
||||
void iButtonSceneWriteSuccess::on_enter(iButtonApp* app) {
|
||||
iButtonAppViewManager* view_manager = app->get_view_manager();
|
||||
Popup* popup = view_manager->get_popup();
|
||||
auto callback = cbc::obtain_connector(this, &iButtonSceneWriteSuccess::popup_callback);
|
||||
|
||||
popup_set_icon(popup, 0, 12, &I_iButtonDolphinVerySuccess_108x52);
|
||||
popup_set_text(popup, "Successfully written!", 40, 12, AlignLeft, AlignBottom);
|
||||
|
||||
popup_set_callback(popup, callback);
|
||||
popup_set_callback(popup, popup_callback);
|
||||
popup_set_context(popup, app);
|
||||
popup_set_timeout(popup, 1500);
|
||||
popup_enable_timeout(popup);
|
||||
@@ -45,12 +48,4 @@ void iButtonSceneWriteSuccess::on_exit(iButtonApp* app) {
|
||||
popup_disable_timeout(popup);
|
||||
popup_set_context(popup, NULL);
|
||||
popup_set_callback(popup, NULL);
|
||||
}
|
||||
|
||||
void iButtonSceneWriteSuccess::popup_callback(void* context) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
event.type = iButtonEvent::Type::EventTypeBack;
|
||||
app->get_view_manager()->send_event(&event);
|
||||
app->notify_green_off();
|
||||
}
|
||||
@@ -6,7 +6,4 @@ public:
|
||||
void on_enter(iButtonApp* app) final;
|
||||
bool on_event(iButtonApp* app, iButtonEvent* event) final;
|
||||
void on_exit(iButtonApp* app) final;
|
||||
|
||||
private:
|
||||
void popup_callback(void* context);
|
||||
};
|
||||
Reference in New Issue
Block a user