New LF-RFID app (#534)
* Hal lfrfid: add read timer pulse and period config fns * New debug application for lfrfid subsystem * New lfrfid: app, fix naming * App lfrfid: assets * Container view module * App ibutton: remove unused header * App lfrfid scenes * App notification, add yield to blocking operations, add speaker volume control * App lfrfid: reading key scene * Assets: placeholder icon * App lfrfid: reworked container view module * App lfrfid: new scenes * App lfrfid: write scene * App lfrfid: write hid * App lfrfid: emulate scene * App lfrfid: save name scene * App lfrfid: add missing file
This commit is contained in:
60
lib/app-scened-template/file-worker.cpp
Normal file
60
lib/app-scened-template/file-worker.cpp
Normal file
@@ -0,0 +1,60 @@
|
||||
#include "file-worker.h"
|
||||
|
||||
FileWorker::FileWorker()
|
||||
: fs_api{"sdcard"}
|
||||
, sd_ex_api{"sdcard-ex"} {
|
||||
string_init(error_string);
|
||||
}
|
||||
|
||||
FileWorker::~FileWorker() {
|
||||
string_clear(error_string);
|
||||
}
|
||||
|
||||
bool FileWorker::open(const char* filename, FS_AccessMode access_mode, FS_OpenMode open_mode) {
|
||||
bool result = fs_api.get()->file.open(&file, filename, access_mode, open_mode);
|
||||
|
||||
if(!result) {
|
||||
show_error_message("Cannot open\nfile");
|
||||
close();
|
||||
return false;
|
||||
}
|
||||
|
||||
return check_common_errors();
|
||||
}
|
||||
|
||||
bool FileWorker::close() {
|
||||
fs_api.get()->file.close(&file);
|
||||
|
||||
return check_common_errors();
|
||||
}
|
||||
|
||||
bool FileWorker::mkdir(const char* dirname) {
|
||||
FS_Error fs_result = fs_api.get()->common.mkdir(dirname);
|
||||
|
||||
if(fs_result != FSE_OK && fs_result != FSE_EXIST) {
|
||||
show_error_message("Cannot create\nfolder");
|
||||
return false;
|
||||
};
|
||||
|
||||
return check_common_errors();
|
||||
}
|
||||
|
||||
bool FileWorker::remove(const char* filename) {
|
||||
FS_Error fs_result = fs_api.get()->common.remove(filename);
|
||||
if(fs_result != FSE_OK && fs_result != FSE_NOT_EXIST) {
|
||||
show_error_message("Cannot remove\nold file");
|
||||
return false;
|
||||
};
|
||||
|
||||
return check_common_errors();
|
||||
}
|
||||
|
||||
bool FileWorker::check_common_errors() {
|
||||
sd_ex_api.get()->check_error(sd_ex_api.get()->context);
|
||||
return true;
|
||||
}
|
||||
|
||||
void FileWorker::show_error_message(const char* error_text) {
|
||||
string_set_str(error_string, error_text);
|
||||
sd_ex_api.get()->show_error(sd_ex_api.get()->context, string_get_cstr(error_string));
|
||||
}
|
27
lib/app-scened-template/file-worker.h
Normal file
27
lib/app-scened-template/file-worker.h
Normal file
@@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
#include "record-controller.hpp"
|
||||
#include <sd-card-api.h>
|
||||
#include <filesystem-api.h>
|
||||
#include <m-string.h>
|
||||
|
||||
class FileWorker {
|
||||
public:
|
||||
FileWorker();
|
||||
~FileWorker();
|
||||
|
||||
RecordController<FS_Api> fs_api;
|
||||
RecordController<SdCard_Api> sd_ex_api;
|
||||
|
||||
bool open(const char* filename, FS_AccessMode access_mode, FS_OpenMode open_mode);
|
||||
bool close();
|
||||
|
||||
bool mkdir(const char* dirname);
|
||||
bool remove(const char* filename);
|
||||
|
||||
private:
|
||||
File file;
|
||||
|
||||
bool check_common_errors();
|
||||
void show_error_message(const char* error_text);
|
||||
string_t error_string;
|
||||
};
|
@@ -10,7 +10,7 @@ TextStore::~TextStore() {
|
||||
free(text);
|
||||
}
|
||||
|
||||
void TextStore::set_text_store(const char* _text...) {
|
||||
void TextStore::set(const char* _text...) {
|
||||
va_list args;
|
||||
va_start(args, _text);
|
||||
vsnprintf(text, text_size, _text, args);
|
||||
|
@@ -6,7 +6,7 @@ public:
|
||||
TextStore(uint8_t text_size);
|
||||
~TextStore();
|
||||
|
||||
void set_text_store(const char* text...);
|
||||
void set(const char* text...);
|
||||
const uint8_t text_size;
|
||||
char* text;
|
||||
};
|
@@ -17,7 +17,7 @@ void DialogExVM::clean() {
|
||||
set_context(NULL);
|
||||
set_header(NULL, 0, 0, AlignLeft, AlignBottom);
|
||||
set_text(NULL, 0, 0, AlignLeft, AlignBottom);
|
||||
set_icon(-1, -1, I_ButtonCenter_7x7);
|
||||
set_icon(0, 0, I_Empty_1x1);
|
||||
set_left_button_text(NULL);
|
||||
set_center_button_text(NULL);
|
||||
set_right_button_text(NULL);
|
||||
@@ -44,7 +44,7 @@ void DialogExVM::set_text(const char* text, uint8_t x, uint8_t y, Align horizont
|
||||
dialog_ex_set_text(dialog_ex, text, x, y, horizontal, vertical);
|
||||
}
|
||||
|
||||
void DialogExVM::set_icon(int8_t x, int8_t y, IconName name) {
|
||||
void DialogExVM::set_icon(uint8_t x, uint8_t y, IconName name) {
|
||||
dialog_ex_set_icon(dialog_ex, x, y, name);
|
||||
}
|
||||
|
||||
|
@@ -45,7 +45,7 @@ public:
|
||||
* @param x, y - icon position
|
||||
* @param name - icon to be shown
|
||||
*/
|
||||
void set_icon(int8_t x, int8_t y, IconName name);
|
||||
void set_icon(uint8_t x, uint8_t y, IconName name);
|
||||
|
||||
/**
|
||||
* Set left button text
|
||||
|
@@ -16,7 +16,7 @@ void PopupVM::clean() {
|
||||
set_context(NULL);
|
||||
set_header(NULL, 0, 0, AlignLeft, AlignBottom);
|
||||
set_text(NULL, 0, 0, AlignLeft, AlignBottom);
|
||||
set_icon(-1, -1, I_ButtonCenter_7x7);
|
||||
set_icon(0, 0, I_Empty_1x1);
|
||||
disable_timeout();
|
||||
set_timeout(1000);
|
||||
}
|
||||
|
Reference in New Issue
Block a user