[FL-2220, FL-2221, FL-1883] RFID and iButton GUI update (#1107)
* RFID and iButton gui update * Grammar nazi: readed -> read * Grammar nazi pt.2: writed -> written Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
parent
72a6bbb8ad
commit
779d319069
@ -9,7 +9,9 @@
|
||||
#include "scene/ibutton_scene_read_crc_error.h"
|
||||
#include "scene/ibutton_scene_read_not_key_error.h"
|
||||
#include "scene/ibutton_scene_read_success.h"
|
||||
#include "scene/ibutton_scene_readed_key_menu.h"
|
||||
#include "scene/ibutton_scene_retry_confirm.h"
|
||||
#include "scene/ibutton_scene_exit_confirm.h"
|
||||
#include "scene/ibutton_scene_read_key_menu.h"
|
||||
#include "scene/ibutton_scene_write.h"
|
||||
#include "scene/ibutton_scene_write_success.h"
|
||||
#include "scene/ibutton_scene_saved_key_menu.h"
|
||||
@ -42,7 +44,9 @@ public:
|
||||
SceneReadNotKeyError,
|
||||
SceneReadCRCError,
|
||||
SceneReadSuccess,
|
||||
SceneReadedKeyMenu,
|
||||
SceneRetryConfirm,
|
||||
SceneExitConfirm,
|
||||
SceneReadKeyMenu,
|
||||
SceneWrite,
|
||||
SceneWriteSuccess,
|
||||
SceneEmulate,
|
||||
@ -105,7 +109,9 @@ private:
|
||||
{Scene::SceneReadCRCError, new iButtonSceneReadCRCError()},
|
||||
{Scene::SceneReadNotKeyError, new iButtonSceneReadNotKeyError()},
|
||||
{Scene::SceneReadSuccess, new iButtonSceneReadSuccess()},
|
||||
{Scene::SceneReadedKeyMenu, new iButtonSceneReadedKeyMenu()},
|
||||
{Scene::SceneRetryConfirm, new iButtonSceneRetryConfirm()},
|
||||
{Scene::SceneExitConfirm, new iButtonSceneExitConfirm()},
|
||||
{Scene::SceneReadKeyMenu, new iButtonSceneReadKeyMenu()},
|
||||
{Scene::SceneWrite, new iButtonSceneWrite()},
|
||||
{Scene::SceneWriteSuccess, new iButtonSceneWriteSuccess()},
|
||||
{Scene::SceneEmulate, new iButtonSceneEmulate()},
|
||||
|
@ -14,7 +14,7 @@ void iButtonSceneDeleteSuccess::on_enter(iButtonApp* app) {
|
||||
Popup* popup = view_manager->get_popup();
|
||||
|
||||
popup_set_icon(popup, 0, 2, &I_DolphinMafia_115x62);
|
||||
popup_set_text(popup, "Deleted", 83, 19, AlignLeft, AlignBottom);
|
||||
popup_set_header(popup, "Deleted", 83, 19, AlignLeft, AlignBottom);
|
||||
|
||||
popup_set_callback(popup, popup_callback);
|
||||
popup_set_context(popup, app);
|
||||
|
51
applications/ibutton/scene/ibutton_scene_exit_confirm.cpp
Normal file
51
applications/ibutton/scene/ibutton_scene_exit_confirm.cpp
Normal file
@ -0,0 +1,51 @@
|
||||
#include "ibutton_scene_exit_confirm.h"
|
||||
#include "../ibutton_app.h"
|
||||
|
||||
static void widget_callback(GuiButtonType result, InputType type, void* context) {
|
||||
furi_assert(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 iButtonSceneExitConfirm::on_enter(iButtonApp* app) {
|
||||
iButtonAppViewManager* view_manager = app->get_view_manager();
|
||||
Widget* widget = view_manager->get_widget();
|
||||
|
||||
widget_add_button_element(widget, GuiButtonTypeLeft, "Exit", widget_callback, app);
|
||||
widget_add_button_element(widget, GuiButtonTypeRight, "Stay", widget_callback, app);
|
||||
widget_add_string_element(
|
||||
widget, 64, 19, AlignCenter, AlignBottom, FontPrimary, "Exit to iButton menu");
|
||||
widget_add_string_element(
|
||||
widget, 64, 29, AlignCenter, AlignBottom, FontSecondary, "All unsaved data will be lost");
|
||||
|
||||
view_manager->switch_to(iButtonAppViewManager::Type::iButtonAppViewWidget);
|
||||
}
|
||||
|
||||
bool iButtonSceneExitConfirm::on_event(iButtonApp* app, iButtonEvent* event) {
|
||||
bool consumed = false;
|
||||
|
||||
if(event->type == iButtonEvent::Type::EventTypeWidgetButtonResult) {
|
||||
if(event->payload.widget_button_result == GuiButtonTypeLeft) {
|
||||
app->search_and_switch_to_previous_scene({iButtonApp::Scene::SceneStart});
|
||||
} else if(event->payload.widget_button_result == GuiButtonTypeRight) {
|
||||
app->switch_to_previous_scene();
|
||||
}
|
||||
consumed = true;
|
||||
} else if(event->type == iButtonEvent::Type::EventTypeBack) {
|
||||
consumed = true;
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void iButtonSceneExitConfirm::on_exit(iButtonApp* app) {
|
||||
iButtonAppViewManager* view_manager = app->get_view_manager();
|
||||
Widget* widget = view_manager->get_widget();
|
||||
widget_reset(widget);
|
||||
}
|
9
applications/ibutton/scene/ibutton_scene_exit_confirm.h
Normal file
9
applications/ibutton/scene/ibutton_scene_exit_confirm.h
Normal file
@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
#include "ibutton_scene_generic.h"
|
||||
|
||||
class iButtonSceneExitConfirm : public iButtonScene {
|
||||
public:
|
||||
void on_enter(iButtonApp* app) final;
|
||||
bool on_event(iButtonApp* app, iButtonEvent* event) final;
|
||||
void on_exit(iButtonApp* app) final;
|
||||
};
|
@ -34,15 +34,22 @@ bool iButtonSceneRead::on_event(iButtonApp* app, iButtonEvent* event) {
|
||||
consumed = true;
|
||||
|
||||
iButtonKey* key = app->get_key();
|
||||
bool success = false;
|
||||
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);
|
||||
success = true;
|
||||
}
|
||||
} else {
|
||||
success = true;
|
||||
}
|
||||
if(success) {
|
||||
app->notify_success();
|
||||
app->notify_green_on();
|
||||
DOLPHIN_DEED(DolphinDeedIbuttonReadSuccess);
|
||||
app->switch_to_next_scene(iButtonApp::Scene::SceneReadSuccess);
|
||||
}
|
||||
} else if(event->type == iButtonEvent::Type::EventTypeTick) {
|
||||
|
@ -47,7 +47,7 @@ bool iButtonSceneReadCRCError::on_event(iButtonApp* app, iButtonEvent* event) {
|
||||
|
||||
if(event->type == iButtonEvent::Type::EventTypeDialogResult) {
|
||||
if(event->payload.dialog_result == DialogExResultRight) {
|
||||
app->switch_to_next_scene(iButtonApp::Scene::SceneReadedKeyMenu);
|
||||
app->switch_to_next_scene(iButtonApp::Scene::SceneReadKeyMenu);
|
||||
} else {
|
||||
app->switch_to_previous_scene();
|
||||
}
|
||||
|
@ -1,11 +1,10 @@
|
||||
#include "ibutton_scene_readed_key_menu.h"
|
||||
#include "ibutton_scene_read_key_menu.h"
|
||||
#include "../ibutton_app.h"
|
||||
|
||||
typedef enum {
|
||||
SubmenuIndexWrite,
|
||||
SubmenuIndexEmulate,
|
||||
SubmenuIndexSave,
|
||||
SubmenuIndexReadNewKey,
|
||||
} SubmenuIndex;
|
||||
|
||||
static void submenu_callback(void* context, uint32_t index) {
|
||||
@ -19,7 +18,7 @@ static void submenu_callback(void* context, uint32_t index) {
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
||||
|
||||
void iButtonSceneReadedKeyMenu::on_enter(iButtonApp* app) {
|
||||
void iButtonSceneReadKeyMenu::on_enter(iButtonApp* app) {
|
||||
iButtonAppViewManager* view_manager = app->get_view_manager();
|
||||
Submenu* submenu = view_manager->get_submenu();
|
||||
|
||||
@ -28,13 +27,12 @@ void iButtonSceneReadedKeyMenu::on_enter(iButtonApp* app) {
|
||||
}
|
||||
submenu_add_item(submenu, "Save", SubmenuIndexSave, 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);
|
||||
}
|
||||
|
||||
bool iButtonSceneReadedKeyMenu::on_event(iButtonApp* app, iButtonEvent* event) {
|
||||
bool iButtonSceneReadKeyMenu::on_event(iButtonApp* app, iButtonEvent* event) {
|
||||
bool consumed = false;
|
||||
|
||||
if(event->type == iButtonEvent::Type::EventTypeMenuSelected) {
|
||||
@ -49,20 +47,17 @@ bool iButtonSceneReadedKeyMenu::on_event(iButtonApp* app, iButtonEvent* event) {
|
||||
case SubmenuIndexSave:
|
||||
app->switch_to_next_scene(iButtonApp::Scene::SceneSaveName);
|
||||
break;
|
||||
case SubmenuIndexReadNewKey:
|
||||
app->search_and_switch_to_previous_scene({iButtonApp::Scene::SceneRead});
|
||||
break;
|
||||
}
|
||||
consumed = true;
|
||||
} else if(event->type == iButtonEvent::Type::EventTypeBack) {
|
||||
app->search_and_switch_to_previous_scene({iButtonApp::Scene::SceneStart});
|
||||
app->switch_to_previous_scene();
|
||||
consumed = true;
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void iButtonSceneReadedKeyMenu::on_exit(iButtonApp* app) {
|
||||
void iButtonSceneReadKeyMenu::on_exit(iButtonApp* app) {
|
||||
iButtonAppViewManager* view = app->get_view_manager();
|
||||
Submenu* submenu = view->get_submenu();
|
||||
|
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
#include "ibutton_scene_generic.h"
|
||||
|
||||
class iButtonSceneReadedKeyMenu : public iButtonScene {
|
||||
class iButtonSceneReadKeyMenu : public iButtonScene {
|
||||
public:
|
||||
void on_enter(iButtonApp* app) final;
|
||||
bool on_event(iButtonApp* app, iButtonEvent* event) final;
|
@ -47,7 +47,7 @@ bool iButtonSceneReadNotKeyError::on_event(iButtonApp* app, iButtonEvent* event)
|
||||
|
||||
if(event->type == iButtonEvent::Type::EventTypeDialogResult) {
|
||||
if(event->payload.dialog_result == DialogExResultRight) {
|
||||
app->switch_to_next_scene(iButtonApp::Scene::SceneReadedKeyMenu);
|
||||
app->switch_to_next_scene(iButtonApp::Scene::SceneReadKeyMenu);
|
||||
} else {
|
||||
app->switch_to_previous_scene();
|
||||
}
|
||||
|
@ -18,7 +18,6 @@ void iButtonSceneReadSuccess::on_enter(iButtonApp* app) {
|
||||
DialogEx* dialog_ex = view_manager->get_dialog_ex();
|
||||
iButtonKey* key = app->get_key();
|
||||
const uint8_t* key_data = ibutton_key_get_data_p(key);
|
||||
DOLPHIN_DEED(DolphinDeedIbuttonReadSuccess);
|
||||
|
||||
switch(ibutton_key_get_type(key)) {
|
||||
case iButtonKeyDS1990:
|
||||
@ -50,9 +49,6 @@ void iButtonSceneReadSuccess::on_enter(iButtonApp* app) {
|
||||
dialog_ex_set_context(dialog_ex, app);
|
||||
|
||||
view_manager->switch_to(iButtonAppViewManager::Type::iButtonAppViewDialogEx);
|
||||
|
||||
app->notify_success();
|
||||
app->notify_green_on();
|
||||
}
|
||||
|
||||
bool iButtonSceneReadSuccess::on_event(iButtonApp* app, iButtonEvent* event) {
|
||||
@ -60,11 +56,13 @@ bool iButtonSceneReadSuccess::on_event(iButtonApp* app, iButtonEvent* event) {
|
||||
|
||||
if(event->type == iButtonEvent::Type::EventTypeDialogResult) {
|
||||
if(event->payload.dialog_result == DialogExResultRight) {
|
||||
app->switch_to_next_scene(iButtonApp::Scene::SceneReadedKeyMenu);
|
||||
app->switch_to_next_scene(iButtonApp::Scene::SceneReadKeyMenu);
|
||||
} else {
|
||||
app->switch_to_previous_scene();
|
||||
app->switch_to_next_scene(iButtonApp::Scene::SceneRetryConfirm);
|
||||
}
|
||||
|
||||
consumed = true;
|
||||
} else if(event->type == iButtonEvent::Type::EventTypeBack) {
|
||||
app->switch_to_next_scene(iButtonApp::Scene::SceneExitConfirm);
|
||||
consumed = true;
|
||||
}
|
||||
|
||||
|
51
applications/ibutton/scene/ibutton_scene_retry_confirm.cpp
Normal file
51
applications/ibutton/scene/ibutton_scene_retry_confirm.cpp
Normal file
@ -0,0 +1,51 @@
|
||||
#include "ibutton_scene_retry_confirm.h"
|
||||
#include "../ibutton_app.h"
|
||||
|
||||
static void widget_callback(GuiButtonType result, InputType type, void* context) {
|
||||
furi_assert(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 iButtonSceneRetryConfirm::on_enter(iButtonApp* app) {
|
||||
iButtonAppViewManager* view_manager = app->get_view_manager();
|
||||
Widget* widget = view_manager->get_widget();
|
||||
|
||||
widget_add_button_element(widget, GuiButtonTypeLeft, "Exit", widget_callback, app);
|
||||
widget_add_button_element(widget, GuiButtonTypeRight, "Stay", widget_callback, app);
|
||||
widget_add_string_element(
|
||||
widget, 64, 19, AlignCenter, AlignBottom, FontPrimary, "Return to reading?");
|
||||
widget_add_string_element(
|
||||
widget, 64, 29, AlignCenter, AlignBottom, FontSecondary, "All unsaved data will be lost");
|
||||
|
||||
view_manager->switch_to(iButtonAppViewManager::Type::iButtonAppViewWidget);
|
||||
}
|
||||
|
||||
bool iButtonSceneRetryConfirm::on_event(iButtonApp* app, iButtonEvent* event) {
|
||||
bool consumed = false;
|
||||
|
||||
if(event->type == iButtonEvent::Type::EventTypeWidgetButtonResult) {
|
||||
if(event->payload.widget_button_result == GuiButtonTypeLeft) {
|
||||
app->search_and_switch_to_previous_scene({iButtonApp::Scene::SceneRead});
|
||||
} else if(event->payload.widget_button_result == GuiButtonTypeRight) {
|
||||
app->switch_to_previous_scene();
|
||||
}
|
||||
consumed = true;
|
||||
} else if(event->type == iButtonEvent::Type::EventTypeBack) {
|
||||
consumed = true;
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void iButtonSceneRetryConfirm::on_exit(iButtonApp* app) {
|
||||
iButtonAppViewManager* view_manager = app->get_view_manager();
|
||||
Widget* widget = view_manager->get_widget();
|
||||
widget_reset(widget);
|
||||
}
|
9
applications/ibutton/scene/ibutton_scene_retry_confirm.h
Normal file
9
applications/ibutton/scene/ibutton_scene_retry_confirm.h
Normal file
@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
#include "ibutton_scene_generic.h"
|
||||
|
||||
class iButtonSceneRetryConfirm : public iButtonScene {
|
||||
public:
|
||||
void on_enter(iButtonApp* app) final;
|
||||
bool on_event(iButtonApp* app, iButtonEvent* event) final;
|
||||
void on_exit(iButtonApp* app) final;
|
||||
};
|
@ -49,7 +49,7 @@ bool iButtonSceneSaveName::on_event(iButtonApp* app, iButtonEvent* event) {
|
||||
app->switch_to_next_scene(iButtonApp::Scene::SceneSaveSuccess);
|
||||
} else {
|
||||
app->search_and_switch_to_previous_scene(
|
||||
{iButtonApp::Scene::SceneReadedKeyMenu,
|
||||
{iButtonApp::Scene::SceneReadKeyMenu,
|
||||
iButtonApp::Scene::SceneSavedKeyMenu,
|
||||
iButtonApp::Scene::SceneAddType});
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ void iButtonSceneSaveSuccess::on_enter(iButtonApp* app) {
|
||||
DOLPHIN_DEED(DolphinDeedIbuttonSave);
|
||||
|
||||
popup_set_icon(popup, 32, 5, &I_DolphinNice_96x59);
|
||||
popup_set_text(popup, "Saved!", 13, 22, AlignLeft, AlignBottom);
|
||||
popup_set_header(popup, "Saved!", 5, 7, AlignLeft, AlignTop);
|
||||
|
||||
popup_set_callback(popup, popup_callback);
|
||||
popup_set_context(popup, app);
|
||||
@ -31,7 +31,7 @@ bool iButtonSceneSaveSuccess::on_event(iButtonApp* app, iButtonEvent* event) {
|
||||
|
||||
if(event->type == iButtonEvent::Type::EventTypeBack) {
|
||||
app->search_and_switch_to_previous_scene(
|
||||
{iButtonApp::Scene::SceneReadedKeyMenu,
|
||||
{iButtonApp::Scene::SceneReadKeyMenu,
|
||||
iButtonApp::Scene::SceneSavedKeyMenu,
|
||||
iButtonApp::Scene::SceneAddType});
|
||||
consumed = true;
|
||||
|
@ -33,7 +33,7 @@ bool iButtonSceneWriteSuccess::on_event(iButtonApp* app, iButtonEvent* event) {
|
||||
|
||||
if(event->type == iButtonEvent::Type::EventTypeBack) {
|
||||
app->search_and_switch_to_previous_scene(
|
||||
{iButtonApp::Scene::SceneReadedKeyMenu, iButtonApp::Scene::SceneStart});
|
||||
{iButtonApp::Scene::SceneReadKeyMenu, iButtonApp::Scene::SceneStart});
|
||||
consumed = true;
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,6 @@ void InfraredAppSceneEditRenameDone::on_enter(InfraredApp* app) {
|
||||
Popup* popup = view_manager->get_popup();
|
||||
|
||||
popup_set_icon(popup, 32, 5, &I_DolphinNice_96x59);
|
||||
|
||||
popup_set_header(popup, "Saved!", 5, 7, AlignLeft, AlignTop);
|
||||
|
||||
popup_set_callback(popup, InfraredApp::popup_callback);
|
||||
|
@ -15,7 +15,7 @@ constexpr uint32_t long_time_high = long_time + jitter_time;
|
||||
|
||||
void DecoderEMMarin::reset_state() {
|
||||
ready = false;
|
||||
readed_data = 0;
|
||||
read_data = 0;
|
||||
manchester_advance(
|
||||
manchester_saved_state, ManchesterEventReset, &manchester_saved_state, nullptr);
|
||||
}
|
||||
@ -26,7 +26,7 @@ bool DecoderEMMarin::read(uint8_t* data, uint8_t data_size) {
|
||||
if(ready) {
|
||||
result = true;
|
||||
em_marin.decode(
|
||||
reinterpret_cast<const uint8_t*>(&readed_data), sizeof(uint64_t), data, data_size);
|
||||
reinterpret_cast<const uint8_t*>(&read_data), sizeof(uint64_t), data, data_size);
|
||||
ready = false;
|
||||
}
|
||||
|
||||
@ -59,10 +59,10 @@ void DecoderEMMarin::process_front(bool polarity, uint32_t time) {
|
||||
manchester_advance(manchester_saved_state, event, &manchester_saved_state, &data);
|
||||
|
||||
if(data_ok) {
|
||||
readed_data = (readed_data << 1) | data;
|
||||
read_data = (read_data << 1) | data;
|
||||
|
||||
ready = em_marin.can_be_decoded(
|
||||
reinterpret_cast<const uint8_t*>(&readed_data), sizeof(uint64_t));
|
||||
reinterpret_cast<const uint8_t*>(&read_data), sizeof(uint64_t));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ public:
|
||||
private:
|
||||
void reset_state();
|
||||
|
||||
uint64_t readed_data = 0;
|
||||
uint64_t read_data = 0;
|
||||
std::atomic<bool> ready;
|
||||
|
||||
ManchesterState manchester_saved_state;
|
||||
|
@ -78,7 +78,7 @@ void RfidReader::start() {
|
||||
start_comparator();
|
||||
|
||||
switch_timer_reset();
|
||||
last_readed_count = 0;
|
||||
last_read_count = 0;
|
||||
}
|
||||
|
||||
void RfidReader::start_forced(RfidReader::Type _type) {
|
||||
@ -97,45 +97,45 @@ void RfidReader::stop() {
|
||||
|
||||
bool RfidReader::read(LfrfidKeyType* _type, uint8_t* data, uint8_t data_size, bool switch_enable) {
|
||||
bool result = false;
|
||||
bool something_readed = false;
|
||||
bool something_read = false;
|
||||
|
||||
// reading
|
||||
if(decoder_em.read(data, data_size)) {
|
||||
*_type = LfrfidKeyType::KeyEM4100;
|
||||
something_readed = true;
|
||||
something_read = true;
|
||||
}
|
||||
|
||||
if(decoder_hid26.read(data, data_size)) {
|
||||
*_type = LfrfidKeyType::KeyH10301;
|
||||
something_readed = true;
|
||||
something_read = true;
|
||||
}
|
||||
|
||||
if(decoder_indala.read(data, data_size)) {
|
||||
*_type = LfrfidKeyType::KeyI40134;
|
||||
something_readed = true;
|
||||
something_read = true;
|
||||
}
|
||||
|
||||
// validation
|
||||
if(something_readed) {
|
||||
if(something_read) {
|
||||
switch_timer_reset();
|
||||
|
||||
if(last_readed_type == *_type && memcmp(last_readed_data, data, data_size) == 0) {
|
||||
last_readed_count = last_readed_count + 1;
|
||||
if(last_read_type == *_type && memcmp(last_read_data, data, data_size) == 0) {
|
||||
last_read_count = last_read_count + 1;
|
||||
|
||||
if(last_readed_count > 2) {
|
||||
if(last_read_count > 2) {
|
||||
result = true;
|
||||
}
|
||||
} else {
|
||||
last_readed_type = *_type;
|
||||
memcpy(last_readed_data, data, data_size);
|
||||
last_readed_count = 0;
|
||||
last_read_type = *_type;
|
||||
memcpy(last_read_data, data, data_size);
|
||||
last_read_count = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// mode switching
|
||||
if(switch_enable && switch_timer_elapsed()) {
|
||||
switch_mode();
|
||||
last_readed_count = 0;
|
||||
last_read_count = 0;
|
||||
}
|
||||
|
||||
return result;
|
||||
@ -152,7 +152,7 @@ bool RfidReader::detect() {
|
||||
}
|
||||
|
||||
bool RfidReader::any_read() {
|
||||
return last_readed_count > 0;
|
||||
return last_read_count > 0;
|
||||
}
|
||||
|
||||
void RfidReader::start_comparator(void) {
|
||||
|
@ -49,9 +49,9 @@ private:
|
||||
void switch_timer_reset();
|
||||
void switch_mode();
|
||||
|
||||
LfrfidKeyType last_readed_type;
|
||||
uint8_t last_readed_data[LFRFID_KEY_SIZE];
|
||||
uint8_t last_readed_count;
|
||||
LfrfidKeyType last_read_type;
|
||||
uint8_t last_read_data[LFRFID_KEY_SIZE];
|
||||
uint8_t last_read_count;
|
||||
|
||||
Type type = Type::Normal;
|
||||
};
|
||||
|
@ -2,7 +2,9 @@
|
||||
#include "scene/lfrfid_app_scene_start.h"
|
||||
#include "scene/lfrfid_app_scene_read.h"
|
||||
#include "scene/lfrfid_app_scene_read_success.h"
|
||||
#include "scene/lfrfid_app_scene_readed_menu.h"
|
||||
#include "scene/lfrfid_app_scene_retry_confirm.h"
|
||||
#include "scene/lfrfid_app_scene_exit_confirm.h"
|
||||
#include "scene/lfrfid_app_scene_read_menu.h"
|
||||
#include "scene/lfrfid_app_scene_write.h"
|
||||
#include "scene/lfrfid_app_scene_write_success.h"
|
||||
#include "scene/lfrfid_app_scene_emulate.h"
|
||||
@ -48,8 +50,10 @@ void LfRfidApp::run(void* _args) {
|
||||
} else {
|
||||
scene_controller.add_scene(SceneType::Start, new LfRfidAppSceneStart());
|
||||
scene_controller.add_scene(SceneType::Read, new LfRfidAppSceneRead());
|
||||
scene_controller.add_scene(SceneType::RetryConfirm, new LfRfidAppSceneRetryConfirm());
|
||||
scene_controller.add_scene(SceneType::ExitConfirm, new LfRfidAppSceneExitConfirm());
|
||||
scene_controller.add_scene(SceneType::ReadSuccess, new LfRfidAppSceneReadSuccess());
|
||||
scene_controller.add_scene(SceneType::ReadedMenu, new LfRfidAppSceneReadedMenu());
|
||||
scene_controller.add_scene(SceneType::ReadKeyMenu, new LfRfidAppSceneReadKeyMenu());
|
||||
scene_controller.add_scene(SceneType::Write, new LfRfidAppSceneWrite());
|
||||
scene_controller.add_scene(SceneType::WriteSuccess, new LfRfidAppSceneWriteSuccess());
|
||||
scene_controller.add_scene(SceneType::Emulate, new LfRfidAppSceneEmulate());
|
||||
|
@ -27,13 +27,17 @@ public:
|
||||
GENERIC_EVENT_ENUM_VALUES,
|
||||
Next,
|
||||
MenuSelected,
|
||||
Stay,
|
||||
Retry,
|
||||
};
|
||||
|
||||
enum class SceneType : uint8_t {
|
||||
GENERIC_SCENE_ENUM_VALUES,
|
||||
Read,
|
||||
ReadSuccess,
|
||||
ReadedMenu,
|
||||
RetryConfirm,
|
||||
ExitConfirm,
|
||||
ReadKeyMenu,
|
||||
Write,
|
||||
WriteSuccess,
|
||||
Emulate,
|
||||
|
@ -73,6 +73,11 @@ bool LfRfidAppSceneDeleteConfirm::on_event(LfRfidApp* app, LfRfidApp::Event* eve
|
||||
app->delete_key(&app->worker.key);
|
||||
app->scene_controller.switch_to_next_scene(LfRfidApp::SceneType::DeleteSuccess);
|
||||
consumed = true;
|
||||
} else if(event->type == LfRfidApp::EventType::Stay) {
|
||||
app->scene_controller.switch_to_previous_scene();
|
||||
consumed = true;
|
||||
} else if(event->type == LfRfidApp::EventType::Back) {
|
||||
consumed = true;
|
||||
}
|
||||
|
||||
return consumed;
|
||||
@ -88,7 +93,7 @@ void LfRfidAppSceneDeleteConfirm::on_exit(LfRfidApp* app) {
|
||||
void LfRfidAppSceneDeleteConfirm::back_callback(void* context) {
|
||||
LfRfidApp* app = static_cast<LfRfidApp*>(context);
|
||||
LfRfidApp::Event event;
|
||||
event.type = LfRfidApp::EventType::Back;
|
||||
event.type = LfRfidApp::EventType::Stay;
|
||||
app->view_controller.send_event(&event);
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,7 @@ void LfRfidAppSceneDeleteSuccess::on_enter(LfRfidApp* app, bool need_restore) {
|
||||
auto popup = app->view_controller.get<PopupVM>();
|
||||
|
||||
popup->set_icon(0, 2, &I_DolphinMafia_115x62);
|
||||
popup->set_text("Deleted", 83, 19, AlignLeft, AlignBottom);
|
||||
popup->set_header("Deleted", 83, 19, AlignLeft, AlignBottom);
|
||||
popup->set_context(app);
|
||||
popup->set_callback(LfRfidAppSceneDeleteSuccess::timeout_callback);
|
||||
popup->set_timeout(1500);
|
||||
|
59
applications/lfrfid/scene/lfrfid_app_scene_exit_confirm.cpp
Normal file
59
applications/lfrfid/scene/lfrfid_app_scene_exit_confirm.cpp
Normal file
@ -0,0 +1,59 @@
|
||||
#include "lfrfid_app_scene_exit_confirm.h"
|
||||
#include "../view/elements/button_element.h"
|
||||
#include "../view/elements/icon_element.h"
|
||||
#include "../view/elements/string_element.h"
|
||||
|
||||
void LfRfidAppSceneExitConfirm::on_enter(LfRfidApp* app, bool need_restore) {
|
||||
auto container = app->view_controller.get<ContainerVM>();
|
||||
|
||||
auto button = container->add<ButtonElement>();
|
||||
button->set_type(ButtonElement::Type::Left, "Exit");
|
||||
button->set_callback(app, LfRfidAppSceneExitConfirm::exit_callback);
|
||||
|
||||
button = container->add<ButtonElement>();
|
||||
button->set_type(ButtonElement::Type::Right, "Stay");
|
||||
button->set_callback(app, LfRfidAppSceneExitConfirm::stay_callback);
|
||||
|
||||
auto line_1 = container->add<StringElement>();
|
||||
auto line_2 = container->add<StringElement>();
|
||||
|
||||
line_1->set_text("Exit to RFID menu?", 64, 19, 128 - 2, AlignCenter, AlignBottom, FontPrimary);
|
||||
line_2->set_text(
|
||||
"All unsaved data will be lost", 64, 29, 0, AlignCenter, AlignBottom, FontSecondary);
|
||||
|
||||
app->view_controller.switch_to<ContainerVM>();
|
||||
}
|
||||
|
||||
bool LfRfidAppSceneExitConfirm::on_event(LfRfidApp* app, LfRfidApp::Event* event) {
|
||||
bool consumed = false;
|
||||
|
||||
if(event->type == LfRfidApp::EventType::Next) {
|
||||
app->scene_controller.search_and_switch_to_previous_scene({LfRfidApp::SceneType::Start});
|
||||
consumed = true;
|
||||
} else if(event->type == LfRfidApp::EventType::Stay) {
|
||||
app->scene_controller.switch_to_previous_scene();
|
||||
consumed = true;
|
||||
} else if(event->type == LfRfidApp::EventType::Back) {
|
||||
consumed = true;
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void LfRfidAppSceneExitConfirm::on_exit(LfRfidApp* app) {
|
||||
app->view_controller.get<ContainerVM>()->clean();
|
||||
}
|
||||
|
||||
void LfRfidAppSceneExitConfirm::exit_callback(void* context) {
|
||||
LfRfidApp* app = static_cast<LfRfidApp*>(context);
|
||||
LfRfidApp::Event event;
|
||||
event.type = LfRfidApp::EventType::Next;
|
||||
app->view_controller.send_event(&event);
|
||||
}
|
||||
|
||||
void LfRfidAppSceneExitConfirm::stay_callback(void* context) {
|
||||
LfRfidApp* app = static_cast<LfRfidApp*>(context);
|
||||
LfRfidApp::Event event;
|
||||
event.type = LfRfidApp::EventType::Stay;
|
||||
app->view_controller.send_event(&event);
|
||||
}
|
13
applications/lfrfid/scene/lfrfid_app_scene_exit_confirm.h
Normal file
13
applications/lfrfid/scene/lfrfid_app_scene_exit_confirm.h
Normal file
@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
#include "../lfrfid_app.h"
|
||||
|
||||
class LfRfidAppSceneExitConfirm : public GenericScene<LfRfidApp> {
|
||||
public:
|
||||
void on_enter(LfRfidApp* app, bool need_restore) final;
|
||||
bool on_event(LfRfidApp* app, LfRfidApp::Event* event) final;
|
||||
void on_exit(LfRfidApp* app) final;
|
||||
|
||||
private:
|
||||
static void exit_callback(void* context);
|
||||
static void stay_callback(void* context);
|
||||
};
|
@ -1,4 +1,4 @@
|
||||
#include "lfrfid_app_scene_readed_menu.h"
|
||||
#include "lfrfid_app_scene_read_menu.h"
|
||||
|
||||
typedef enum {
|
||||
SubmenuWrite,
|
||||
@ -6,7 +6,7 @@ typedef enum {
|
||||
SubmenuEmulate,
|
||||
} SubmenuIndex;
|
||||
|
||||
void LfRfidAppSceneReadedMenu::on_enter(LfRfidApp* app, bool need_restore) {
|
||||
void LfRfidAppSceneReadKeyMenu::on_enter(LfRfidApp* app, bool need_restore) {
|
||||
auto submenu = app->view_controller.get<SubmenuVM>();
|
||||
|
||||
submenu->add_item("Write", SubmenuWrite, submenu_callback, app);
|
||||
@ -20,7 +20,7 @@ void LfRfidAppSceneReadedMenu::on_enter(LfRfidApp* app, bool need_restore) {
|
||||
app->view_controller.switch_to<SubmenuVM>();
|
||||
}
|
||||
|
||||
bool LfRfidAppSceneReadedMenu::on_event(LfRfidApp* app, LfRfidApp::Event* event) {
|
||||
bool LfRfidAppSceneReadKeyMenu::on_event(LfRfidApp* app, LfRfidApp::Event* event) {
|
||||
bool consumed = false;
|
||||
|
||||
if(event->type == LfRfidApp::EventType::MenuSelected) {
|
||||
@ -38,18 +38,18 @@ bool LfRfidAppSceneReadedMenu::on_event(LfRfidApp* app, LfRfidApp::Event* event)
|
||||
}
|
||||
consumed = true;
|
||||
} else if(event->type == LfRfidApp::EventType::Back) {
|
||||
app->scene_controller.search_and_switch_to_previous_scene({LfRfidApp::SceneType::Start});
|
||||
app->scene_controller.switch_to_previous_scene();
|
||||
consumed = true;
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void LfRfidAppSceneReadedMenu::on_exit(LfRfidApp* app) {
|
||||
void LfRfidAppSceneReadKeyMenu::on_exit(LfRfidApp* app) {
|
||||
app->view_controller.get<SubmenuVM>()->clean();
|
||||
}
|
||||
|
||||
void LfRfidAppSceneReadedMenu::submenu_callback(void* context, uint32_t index) {
|
||||
void LfRfidAppSceneReadKeyMenu::submenu_callback(void* context, uint32_t index) {
|
||||
LfRfidApp* app = static_cast<LfRfidApp*>(context);
|
||||
LfRfidApp::Event event;
|
||||
|
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
#include "../lfrfid_app.h"
|
||||
|
||||
class LfRfidAppSceneReadedMenu : public GenericScene<LfRfidApp> {
|
||||
class LfRfidAppSceneReadKeyMenu : public GenericScene<LfRfidApp> {
|
||||
public:
|
||||
void on_enter(LfRfidApp* app, bool need_restore) final;
|
||||
bool on_event(LfRfidApp* app, LfRfidApp::Event* event) final;
|
@ -85,7 +85,13 @@ bool LfRfidAppSceneReadSuccess::on_event(LfRfidApp* app, LfRfidApp::Event* event
|
||||
bool consumed = false;
|
||||
|
||||
if(event->type == LfRfidApp::EventType::Next) {
|
||||
app->scene_controller.switch_to_next_scene(LfRfidApp::SceneType::ReadedMenu);
|
||||
app->scene_controller.switch_to_next_scene(LfRfidApp::SceneType::ReadKeyMenu);
|
||||
consumed = true;
|
||||
} else if(event->type == LfRfidApp::EventType::Retry) {
|
||||
app->scene_controller.switch_to_next_scene({LfRfidApp::SceneType::RetryConfirm});
|
||||
consumed = true;
|
||||
} else if(event->type == LfRfidApp::EventType::Back) {
|
||||
app->scene_controller.switch_to_next_scene({LfRfidApp::SceneType::ExitConfirm});
|
||||
consumed = true;
|
||||
}
|
||||
|
||||
@ -103,7 +109,7 @@ void LfRfidAppSceneReadSuccess::on_exit(LfRfidApp* app) {
|
||||
void LfRfidAppSceneReadSuccess::back_callback(void* context) {
|
||||
LfRfidApp* app = static_cast<LfRfidApp*>(context);
|
||||
LfRfidApp::Event event;
|
||||
event.type = LfRfidApp::EventType::Back;
|
||||
event.type = LfRfidApp::EventType::Retry;
|
||||
app->view_controller.send_event(&event);
|
||||
}
|
||||
|
||||
|
59
applications/lfrfid/scene/lfrfid_app_scene_retry_confirm.cpp
Normal file
59
applications/lfrfid/scene/lfrfid_app_scene_retry_confirm.cpp
Normal file
@ -0,0 +1,59 @@
|
||||
#include "lfrfid_app_scene_retry_confirm.h"
|
||||
#include "../view/elements/button_element.h"
|
||||
#include "../view/elements/icon_element.h"
|
||||
#include "../view/elements/string_element.h"
|
||||
|
||||
void LfRfidAppSceneRetryConfirm::on_enter(LfRfidApp* app, bool need_restore) {
|
||||
auto container = app->view_controller.get<ContainerVM>();
|
||||
|
||||
auto button = container->add<ButtonElement>();
|
||||
button->set_type(ButtonElement::Type::Left, "Exit");
|
||||
button->set_callback(app, LfRfidAppSceneRetryConfirm::exit_callback);
|
||||
|
||||
button = container->add<ButtonElement>();
|
||||
button->set_type(ButtonElement::Type::Right, "Stay");
|
||||
button->set_callback(app, LfRfidAppSceneRetryConfirm::stay_callback);
|
||||
|
||||
auto line_1 = container->add<StringElement>();
|
||||
auto line_2 = container->add<StringElement>();
|
||||
|
||||
line_1->set_text("Return to reading?", 64, 19, 128 - 2, AlignCenter, AlignBottom, FontPrimary);
|
||||
line_2->set_text(
|
||||
"All unsaved data will be lost", 64, 29, 0, AlignCenter, AlignBottom, FontSecondary);
|
||||
|
||||
app->view_controller.switch_to<ContainerVM>();
|
||||
}
|
||||
|
||||
bool LfRfidAppSceneRetryConfirm::on_event(LfRfidApp* app, LfRfidApp::Event* event) {
|
||||
bool consumed = false;
|
||||
|
||||
if(event->type == LfRfidApp::EventType::Next) {
|
||||
app->scene_controller.search_and_switch_to_previous_scene({LfRfidApp::SceneType::Read});
|
||||
consumed = true;
|
||||
} else if(event->type == LfRfidApp::EventType::Stay) {
|
||||
app->scene_controller.switch_to_previous_scene();
|
||||
consumed = true;
|
||||
} else if(event->type == LfRfidApp::EventType::Back) {
|
||||
consumed = true;
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void LfRfidAppSceneRetryConfirm::on_exit(LfRfidApp* app) {
|
||||
app->view_controller.get<ContainerVM>()->clean();
|
||||
}
|
||||
|
||||
void LfRfidAppSceneRetryConfirm::exit_callback(void* context) {
|
||||
LfRfidApp* app = static_cast<LfRfidApp*>(context);
|
||||
LfRfidApp::Event event;
|
||||
event.type = LfRfidApp::EventType::Next;
|
||||
app->view_controller.send_event(&event);
|
||||
}
|
||||
|
||||
void LfRfidAppSceneRetryConfirm::stay_callback(void* context) {
|
||||
LfRfidApp* app = static_cast<LfRfidApp*>(context);
|
||||
LfRfidApp::Event event;
|
||||
event.type = LfRfidApp::EventType::Stay;
|
||||
app->view_controller.send_event(&event);
|
||||
}
|
13
applications/lfrfid/scene/lfrfid_app_scene_retry_confirm.h
Normal file
13
applications/lfrfid/scene/lfrfid_app_scene_retry_confirm.h
Normal file
@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
#include "../lfrfid_app.h"
|
||||
|
||||
class LfRfidAppSceneRetryConfirm : public GenericScene<LfRfidApp> {
|
||||
public:
|
||||
void on_enter(LfRfidApp* app, bool need_restore) final;
|
||||
bool on_event(LfRfidApp* app, LfRfidApp::Event* event) final;
|
||||
void on_exit(LfRfidApp* app) final;
|
||||
|
||||
private:
|
||||
static void exit_callback(void* context);
|
||||
static void stay_callback(void* context);
|
||||
};
|
@ -42,7 +42,7 @@ bool LfRfidAppSceneSaveName::on_event(LfRfidApp* app, LfRfidApp::Event* event) {
|
||||
app->scene_controller.switch_to_next_scene(LfRfidApp::SceneType::SaveSuccess);
|
||||
} else {
|
||||
app->scene_controller.search_and_switch_to_previous_scene(
|
||||
{LfRfidApp::SceneType::ReadedMenu});
|
||||
{LfRfidApp::SceneType::ReadKeyMenu});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,7 @@ void LfRfidAppSceneSaveSuccess::on_enter(LfRfidApp* app, bool need_restore) {
|
||||
|
||||
DOLPHIN_DEED(DolphinDeedRfidSave);
|
||||
popup->set_icon(32, 5, &I_DolphinNice_96x59);
|
||||
popup->set_text("Saved!", 13, 22, AlignLeft, AlignBottom);
|
||||
popup->set_header("Saved!", 5, 7, AlignLeft, AlignTop);
|
||||
popup->set_context(app);
|
||||
popup->set_callback(LfRfidAppSceneSaveSuccess::timeout_callback);
|
||||
popup->set_timeout(1500);
|
||||
@ -22,11 +22,11 @@ bool LfRfidAppSceneSaveSuccess::on_event(LfRfidApp* app, LfRfidApp::Event* event
|
||||
|
||||
if(event->type == LfRfidApp::EventType::Back) {
|
||||
bool result = app->scene_controller.has_previous_scene(
|
||||
{LfRfidApp::SceneType::ReadedMenu, LfRfidApp::SceneType::SelectKey});
|
||||
{LfRfidApp::SceneType::ReadKeyMenu, LfRfidApp::SceneType::SelectKey});
|
||||
|
||||
if(result) {
|
||||
app->scene_controller.search_and_switch_to_previous_scene(
|
||||
{LfRfidApp::SceneType::ReadedMenu, LfRfidApp::SceneType::SelectKey});
|
||||
{LfRfidApp::SceneType::ReadKeyMenu, LfRfidApp::SceneType::SelectKey});
|
||||
} else {
|
||||
app->scene_controller.search_and_switch_to_another_scene(
|
||||
{LfRfidApp::SceneType::SaveType}, LfRfidApp::SceneType::SelectKey);
|
||||
|
@ -18,7 +18,7 @@ bool LfRfidAppSceneWriteSuccess::on_event(LfRfidApp* app, LfRfidApp::Event* even
|
||||
|
||||
if(event->type == LfRfidApp::EventType::Back) {
|
||||
app->scene_controller.search_and_switch_to_previous_scene(
|
||||
{LfRfidApp::SceneType::ReadedMenu, LfRfidApp::SceneType::SelectKey});
|
||||
{LfRfidApp::SceneType::ReadKeyMenu, LfRfidApp::SceneType::SelectKey});
|
||||
consumed = true;
|
||||
}
|
||||
|
||||
|
@ -473,17 +473,17 @@ static void rpc_system_storage_md5sum_process(const PB_Main* request, void* cont
|
||||
File* file = storage_file_alloc(fs_api);
|
||||
|
||||
if(storage_file_open(file, filename, FSAM_READ, FSOM_OPEN_EXISTING)) {
|
||||
const uint16_t read_size = 512;
|
||||
const uint16_t size_to_read = 512;
|
||||
const uint8_t hash_size = 16;
|
||||
uint8_t* data = malloc(read_size);
|
||||
uint8_t* data = malloc(size_to_read);
|
||||
uint8_t* hash = malloc(sizeof(uint8_t) * hash_size);
|
||||
md5_context* md5_ctx = malloc(sizeof(md5_context));
|
||||
|
||||
md5_starts(md5_ctx);
|
||||
while(true) {
|
||||
uint16_t readed_size = storage_file_read(file, data, read_size);
|
||||
if(readed_size == 0) break;
|
||||
md5_update(md5_ctx, data, readed_size);
|
||||
uint16_t read_size = storage_file_read(file, data, size_to_read);
|
||||
if(read_size == 0) break;
|
||||
md5_update(md5_ctx, data, read_size);
|
||||
}
|
||||
md5_finish(md5_ctx, hash);
|
||||
free(md5_ctx);
|
||||
|
@ -33,14 +33,14 @@ struct File {
|
||||
* @param file pointer to file object
|
||||
* @param buff pointer to buffer for reading
|
||||
* @param bytes_to_read how many bytes to read, must be smaller or equal to buffer size
|
||||
* @return how many bytes actually has been readed
|
||||
* @return how many bytes actually has been read
|
||||
*
|
||||
* @var FS_File_Api::write
|
||||
* @brief Write bytes from buffer to file
|
||||
* @param file pointer to file object
|
||||
* @param buff pointer to buffer for writing
|
||||
* @param bytes_to_read how many bytes to write, must be smaller or equal to buffer size
|
||||
* @return how many bytes actually has been writed
|
||||
* @return how many bytes actually has been written
|
||||
*
|
||||
* @var FS_File_Api::seek
|
||||
* @brief Move r/w pointer
|
||||
@ -107,7 +107,7 @@ typedef struct {
|
||||
* @var FS_Dir_Api::read
|
||||
* @brief Read next object info in directory
|
||||
* @param file pointer to file object
|
||||
* @param fileinfo pointer to readed FileInfo, can be NULL
|
||||
* @param fileinfo pointer to read FileInfo, can be NULL
|
||||
* @param name pointer to name buffer, can be NULL
|
||||
* @param name_length name buffer length
|
||||
* @return success flag (if next object not exist also returns false and set error_id to FSE_NOT_EXIST)
|
||||
@ -133,7 +133,7 @@ typedef struct {
|
||||
* @var FS_Common_Api::stat
|
||||
* @brief Open directory to get objects from
|
||||
* @param path path to file/directory
|
||||
* @param fileinfo pointer to readed FileInfo, can be NULL
|
||||
* @param fileinfo pointer to read FileInfo, can be NULL
|
||||
* @param name pointer to name buffer, can be NULL
|
||||
* @param name_length name buffer length
|
||||
* @return FS_Error error info
|
||||
|
@ -76,7 +76,7 @@ bool storage_file_is_dir(File* file);
|
||||
* @param file pointer to file object.
|
||||
* @param buff pointer to a buffer, for reading
|
||||
* @param bytes_to_read how many bytes to read. Must be less than or equal to the size of the buffer.
|
||||
* @return uint16_t how many bytes were actually readed
|
||||
* @return uint16_t how many bytes were actually read
|
||||
*/
|
||||
uint16_t storage_file_read(File* file, void* buff, uint16_t bytes_to_read);
|
||||
|
||||
@ -144,7 +144,7 @@ bool storage_dir_close(File* file);
|
||||
|
||||
/** Reads the next object in the directory
|
||||
* @param file pointer to file object.
|
||||
* @param fileinfo pointer to the readed FileInfo, may be NULL
|
||||
* @param fileinfo pointer to the read FileInfo, may be NULL
|
||||
* @param name pointer to name buffer, may be NULL
|
||||
* @param name_length name buffer length
|
||||
* @return success flag (if the next object does not exist, it also returns false and sets the file error id to FSE_NOT_EXIST)
|
||||
@ -162,7 +162,7 @@ bool storage_dir_rewind(File* file);
|
||||
/** Retrieves information about a file/directory
|
||||
* @param app pointer to the api
|
||||
* @param path path to file/directory
|
||||
* @param fileinfo pointer to the readed FileInfo, may be NULL
|
||||
* @param fileinfo pointer to the read FileInfo, may be NULL
|
||||
* @return FS_Error operation result
|
||||
*/
|
||||
FS_Error storage_common_stat(Storage* storage, const char* path, FileInfo* fileinfo);
|
||||
|
@ -112,10 +112,10 @@ static void storage_cli_list(Cli* cli, string_t path) {
|
||||
if(storage_dir_open(file, string_get_cstr(path))) {
|
||||
FileInfo fileinfo;
|
||||
char name[MAX_NAME_LENGTH];
|
||||
bool readed = false;
|
||||
bool read_done = false;
|
||||
|
||||
while(storage_dir_read(file, &fileinfo, name, MAX_NAME_LENGTH)) {
|
||||
readed = true;
|
||||
read_done = true;
|
||||
if(fileinfo.flags & FSF_DIRECTORY) {
|
||||
printf("\t[D] %s\r\n", name);
|
||||
} else {
|
||||
@ -123,7 +123,7 @@ static void storage_cli_list(Cli* cli, string_t path) {
|
||||
}
|
||||
}
|
||||
|
||||
if(!readed) {
|
||||
if(!read_done) {
|
||||
printf("\tEmpty\r\n");
|
||||
}
|
||||
} else {
|
||||
@ -141,18 +141,18 @@ static void storage_cli_read(Cli* cli, string_t path) {
|
||||
File* file = storage_file_alloc(api);
|
||||
|
||||
if(storage_file_open(file, string_get_cstr(path), FSAM_READ, FSOM_OPEN_EXISTING)) {
|
||||
const uint16_t read_size = 128;
|
||||
uint16_t readed_size = 0;
|
||||
const uint16_t size_to_read = 128;
|
||||
uint16_t read_size = 0;
|
||||
uint8_t* data = malloc(read_size);
|
||||
|
||||
printf("Size: %lu\r\n", (uint32_t)storage_file_size(file));
|
||||
|
||||
do {
|
||||
readed_size = storage_file_read(file, data, read_size);
|
||||
for(uint16_t i = 0; i < readed_size; i++) {
|
||||
read_size = storage_file_read(file, data, size_to_read);
|
||||
for(uint16_t i = 0; i < read_size; i++) {
|
||||
printf("%c", data[i]);
|
||||
}
|
||||
} while(readed_size > 0);
|
||||
} while(read_size > 0);
|
||||
printf("\r\n");
|
||||
|
||||
free(data);
|
||||
@ -176,33 +176,33 @@ static void storage_cli_write(Cli* cli, string_t path) {
|
||||
if(storage_file_open(file, string_get_cstr(path), FSAM_WRITE, FSOM_OPEN_APPEND)) {
|
||||
printf("Just write your text data. New line by Ctrl+Enter, exit by Ctrl+C.\r\n");
|
||||
|
||||
uint32_t readed_index = 0;
|
||||
uint32_t read_index = 0;
|
||||
|
||||
while(true) {
|
||||
uint8_t symbol = cli_getc(cli);
|
||||
|
||||
if(symbol == CliSymbolAsciiETX) {
|
||||
uint16_t write_size = readed_index % buffer_size;
|
||||
uint16_t write_size = read_index % buffer_size;
|
||||
|
||||
if(write_size > 0) {
|
||||
uint16_t writed_size = storage_file_write(file, buffer, write_size);
|
||||
uint16_t written_size = storage_file_write(file, buffer, write_size);
|
||||
|
||||
if(writed_size != write_size) {
|
||||
if(written_size != write_size) {
|
||||
storage_cli_print_error(storage_file_get_error(file));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
buffer[readed_index % buffer_size] = symbol;
|
||||
printf("%c", buffer[readed_index % buffer_size]);
|
||||
buffer[read_index % buffer_size] = symbol;
|
||||
printf("%c", buffer[read_index % buffer_size]);
|
||||
fflush(stdout);
|
||||
readed_index++;
|
||||
read_index++;
|
||||
|
||||
if(((readed_index % buffer_size) == 0)) {
|
||||
uint16_t writed_size = storage_file_write(file, buffer, buffer_size);
|
||||
if(((read_index % buffer_size) == 0)) {
|
||||
uint16_t written_size = storage_file_write(file, buffer, buffer_size);
|
||||
|
||||
if(writed_size != buffer_size) {
|
||||
if(written_size != buffer_size) {
|
||||
storage_cli_print_error(storage_file_get_error(file));
|
||||
break;
|
||||
}
|
||||
@ -239,11 +239,11 @@ static void storage_cli_read_chunks(Cli* cli, string_t path, string_t args) {
|
||||
printf("\r\nReady?\r\n");
|
||||
cli_getc(cli);
|
||||
|
||||
uint16_t readed_size = storage_file_read(file, data, buffer_size);
|
||||
for(uint16_t i = 0; i < readed_size; i++) {
|
||||
uint16_t read_size = storage_file_read(file, data, buffer_size);
|
||||
for(uint16_t i = 0; i < read_size; i++) {
|
||||
putchar(data[i]);
|
||||
}
|
||||
file_size -= readed_size;
|
||||
file_size -= read_size;
|
||||
}
|
||||
printf("\r\n");
|
||||
|
||||
@ -277,9 +277,9 @@ static void storage_cli_write_chunk(Cli* cli, string_t path, string_t args) {
|
||||
buffer[i] = cli_getc(cli);
|
||||
}
|
||||
|
||||
uint16_t writed_size = storage_file_write(file, buffer, buffer_size);
|
||||
uint16_t written_size = storage_file_write(file, buffer, buffer_size);
|
||||
|
||||
if(writed_size != buffer_size) {
|
||||
if(written_size != buffer_size) {
|
||||
storage_cli_print_error(storage_file_get_error(file));
|
||||
}
|
||||
|
||||
@ -400,17 +400,17 @@ static void storage_cli_md5(Cli* cli, string_t path) {
|
||||
File* file = storage_file_alloc(api);
|
||||
|
||||
if(storage_file_open(file, string_get_cstr(path), FSAM_READ, FSOM_OPEN_EXISTING)) {
|
||||
const uint16_t read_size = 512;
|
||||
const uint16_t size_to_read = 512;
|
||||
const uint8_t hash_size = 16;
|
||||
uint8_t* data = malloc(read_size);
|
||||
uint8_t* data = malloc(size_to_read);
|
||||
uint8_t* hash = malloc(sizeof(uint8_t) * hash_size);
|
||||
md5_context* md5_ctx = malloc(sizeof(md5_context));
|
||||
|
||||
md5_starts(md5_ctx);
|
||||
while(true) {
|
||||
uint16_t readed_size = storage_file_read(file, data, read_size);
|
||||
if(readed_size == 0) break;
|
||||
md5_update(md5_ctx, data, readed_size);
|
||||
uint16_t read_size = storage_file_read(file, data, size_to_read);
|
||||
if(read_size == 0) break;
|
||||
md5_update(md5_ctx, data, read_size);
|
||||
}
|
||||
md5_finish(md5_ctx, hash);
|
||||
free(md5_ctx);
|
||||
|
@ -340,10 +340,10 @@ static uint16_t
|
||||
storage_ext_file_read(void* ctx, File* file, void* buff, uint16_t const bytes_to_read) {
|
||||
StorageData* storage = ctx;
|
||||
SDFile* file_data = storage_get_storage_file_data(file, storage);
|
||||
uint16_t bytes_readed = 0;
|
||||
file->internal_error_id = f_read(file_data, buff, bytes_to_read, &bytes_readed);
|
||||
uint16_t bytes_read = 0;
|
||||
file->internal_error_id = f_read(file_data, buff, bytes_to_read, &bytes_read);
|
||||
file->error_id = storage_ext_parse_error(file->internal_error_id);
|
||||
return bytes_readed;
|
||||
return bytes_read;
|
||||
}
|
||||
|
||||
static uint16_t
|
||||
|
@ -349,7 +349,7 @@ static uint16_t
|
||||
lfs_t* lfs = lfs_get_from_storage(storage);
|
||||
LFSHandle* handle = storage_get_storage_file_data(file, storage);
|
||||
|
||||
uint16_t bytes_readed = 0;
|
||||
uint16_t bytes_read = 0;
|
||||
|
||||
if(lfs_handle_is_open(handle)) {
|
||||
file->internal_error_id =
|
||||
@ -361,10 +361,10 @@ static uint16_t
|
||||
file->error_id = storage_int_parse_error(file->internal_error_id);
|
||||
|
||||
if(file->error_id == FSE_OK) {
|
||||
bytes_readed = file->internal_error_id;
|
||||
bytes_read = file->internal_error_id;
|
||||
file->internal_error_id = 0;
|
||||
}
|
||||
return bytes_readed;
|
||||
return bytes_read;
|
||||
}
|
||||
|
||||
static uint16_t
|
||||
|
@ -56,12 +56,12 @@ uint16_t mf_ul_prepare_read(uint8_t* dest, uint8_t start_page) {
|
||||
|
||||
void mf_ul_parse_read_response(uint8_t* buff, uint16_t page_addr, MifareUlDevice* mf_ul_read) {
|
||||
uint8_t pages_read = 4;
|
||||
uint8_t page_read_count = mf_ul_read->pages_readed + pages_read;
|
||||
uint8_t page_read_count = mf_ul_read->pages_read + pages_read;
|
||||
if(page_read_count > mf_ul_read->pages_to_read) {
|
||||
pages_read -= page_read_count - mf_ul_read->pages_to_read;
|
||||
}
|
||||
mf_ul_read->pages_readed += pages_read;
|
||||
mf_ul_read->data.data_size = mf_ul_read->pages_readed * 4;
|
||||
mf_ul_read->pages_read += pages_read;
|
||||
mf_ul_read->data.data_size = mf_ul_read->pages_read * 4;
|
||||
memcpy(&mf_ul_read->data.data[page_addr * 4], buff, pages_read * 4);
|
||||
}
|
||||
|
||||
@ -77,8 +77,8 @@ void mf_ul_parse_fast_read_response(
|
||||
uint8_t start_page,
|
||||
uint8_t end_page,
|
||||
MifareUlDevice* mf_ul_read) {
|
||||
mf_ul_read->pages_readed = end_page - start_page + 1;
|
||||
mf_ul_read->data.data_size = mf_ul_read->pages_readed * 4;
|
||||
mf_ul_read->pages_read = end_page - start_page + 1;
|
||||
mf_ul_read->data.data_size = mf_ul_read->pages_read * 4;
|
||||
memcpy(mf_ul_read->data.data, buff, mf_ul_read->data.data_size);
|
||||
}
|
||||
|
||||
|
@ -74,7 +74,7 @@ typedef struct {
|
||||
|
||||
typedef struct {
|
||||
uint8_t pages_to_read;
|
||||
uint8_t pages_readed;
|
||||
uint8_t pages_read;
|
||||
bool support_fast_read;
|
||||
bool data_changed;
|
||||
MifareUlData data;
|
||||
|
@ -71,10 +71,10 @@ static bool writer_write_TM2004(iButtonWriter* writer, iButtonKey* key) {
|
||||
furi_hal_delay_us(600);
|
||||
writer_write_one_bit(writer, 1, 50000);
|
||||
|
||||
// read writed key byte
|
||||
// read written key byte
|
||||
answer = onewire_host_read(writer->host);
|
||||
|
||||
// check that writed and readed are same
|
||||
// check that written and read are same
|
||||
if(ibutton_key_get_data_p(key)[i] != answer) {
|
||||
result = false;
|
||||
break;
|
||||
|
@ -232,18 +232,18 @@ class FlipperStorage:
|
||||
self.read.until(self.CLI_PROMPT)
|
||||
return filedata
|
||||
size = int(answer.split(b": ")[1])
|
||||
readed_size = 0
|
||||
read_size = 0
|
||||
|
||||
while readed_size < size:
|
||||
while read_size < size:
|
||||
self.read.until("Ready?" + self.CLI_EOL)
|
||||
self.send("y")
|
||||
read_size = min(size - readed_size, buffer_size)
|
||||
read_size = min(size - read_size, buffer_size)
|
||||
filedata.extend(self.port.read(read_size))
|
||||
readed_size = readed_size + read_size
|
||||
read_size = read_size + read_size
|
||||
|
||||
percent = str(math.ceil(readed_size / size * 100))
|
||||
percent = str(math.ceil(read_size / size * 100))
|
||||
total_chunks = str(math.ceil(size / buffer_size))
|
||||
current_chunk = str(math.ceil(readed_size / buffer_size))
|
||||
current_chunk = str(math.ceil(read_size / buffer_size))
|
||||
sys.stdout.write(f"\r{percent}%, chunk {current_chunk} of {total_chunks}")
|
||||
sys.stdout.flush()
|
||||
print()
|
||||
|
Loading…
Reference in New Issue
Block a user