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:
SG
2021-06-29 00:42:30 +10:00
committed by GitHub
parent 5d746234e9
commit 22e1ecb642
141 changed files with 2504 additions and 1666 deletions

View File

@@ -0,0 +1,65 @@
#include "button-element.h"
#include <gui/elements.h>
ButtonElement::ButtonElement() {
}
ButtonElement::~ButtonElement() {
}
void ButtonElement::draw(Canvas* canvas) {
if(text != nullptr) {
canvas_set_font(canvas, FontSecondary);
switch(type) {
case Type::Left:
elements_button_left(canvas, text);
break;
case Type::Center:
elements_button_center(canvas, text);
break;
case Type::Right:
elements_button_right(canvas, text);
break;
}
}
}
bool ButtonElement::input(InputEvent* event) {
bool consumed = false;
if(event->type == InputTypeShort && callback != nullptr) {
switch(type) {
case Type::Left:
if(event->key == InputKeyLeft) {
callback(context);
consumed = true;
}
break;
case Type::Center:
if(event->key == InputKeyOk) {
callback(context);
consumed = true;
}
break;
case Type::Right:
if(event->key == InputKeyRight) {
callback(context);
consumed = true;
}
break;
}
}
return consumed;
}
void ButtonElement::set_type(Type _type, const char* _text) {
lock_model();
type = _type;
text = _text;
unlock_model(true);
}
void ButtonElement::set_callback(void* _context, ButtonElementCallback _callback) {
context = _context;
callback = _callback;
}

View File

@@ -0,0 +1,28 @@
#pragma once
#include "generic-element.h"
typedef void (*ButtonElementCallback)(void* context);
class ButtonElement : public GenericElement {
public:
ButtonElement();
~ButtonElement() final;
void draw(Canvas* canvas) final;
bool input(InputEvent* event) final;
enum class Type : uint8_t {
Left,
Center,
Right,
};
void set_type(Type type, const char* text);
void set_callback(void* context, ButtonElementCallback callback);
private:
Type type = Type::Left;
const char* text = nullptr;
void* context = nullptr;
ButtonElementCallback callback = nullptr;
};

View File

@@ -0,0 +1,15 @@
#include "generic-element.h"
void GenericElement::lock_model() {
furi_assert(view != nullptr);
view_get_model(view);
}
void GenericElement::unlock_model(bool need_redraw) {
furi_assert(view != nullptr);
view_commit_model(view, need_redraw);
}
void GenericElement::set_parent_view(View* _view) {
view = _view;
}

View File

@@ -0,0 +1,21 @@
#pragma once
#include <gui/gui.h>
#include <gui/view.h>
class GenericElement {
public:
GenericElement(){};
virtual ~GenericElement(){};
virtual void draw(Canvas* canvas) = 0;
virtual bool input(InputEvent* event) = 0;
// TODO that must be accessible only to ContainerVMData
void set_parent_view(View* view);
// TODO that must be accessible only to inheritors
void lock_model();
void unlock_model(bool need_redraw);
private:
View* view = nullptr;
};

View File

@@ -0,0 +1,25 @@
#include "icon-element.h"
IconElement::IconElement() {
}
IconElement::~IconElement() {
}
void IconElement::draw(Canvas* canvas) {
if(name != I_Empty_1x1) {
canvas_draw_icon_name(canvas, x, y, name);
}
}
bool IconElement::input(InputEvent* event) {
return false;
}
void IconElement::set_icon(uint8_t _x, uint8_t _y, IconName _name) {
lock_model();
name = _name;
x = _x;
y = _y;
unlock_model(true);
}

View File

@@ -0,0 +1,17 @@
#pragma once
#include "generic-element.h"
class IconElement : public GenericElement {
public:
IconElement();
~IconElement() final;
void draw(Canvas* canvas) final;
bool input(InputEvent* event) final;
void set_icon(uint8_t x = 0, uint8_t y = 0, IconName name = I_Empty_1x1);
private:
IconName name = I_Empty_1x1;
uint8_t x = 0;
uint8_t y = 0;
};

View File

@@ -0,0 +1,35 @@
#include "string-element.h"
StringElement::StringElement() {
}
StringElement::~StringElement() {
}
void StringElement::draw(Canvas* canvas) {
if(text) {
canvas_set_font(canvas, font);
canvas_draw_str_aligned(canvas, x, y, horizontal, vertical, text);
}
}
bool StringElement::input(InputEvent* event) {
return false;
}
void StringElement::set_text(
const char* _text,
uint8_t _x,
uint8_t _y,
Align _horizontal,
Align _vertical,
Font _font) {
lock_model();
text = _text;
x = _x;
y = _y;
horizontal = _horizontal;
vertical = _vertical;
font = _font;
unlock_model(true);
}

View File

@@ -0,0 +1,26 @@
#pragma once
#include "generic-element.h"
class StringElement : public GenericElement {
public:
StringElement();
~StringElement() final;
void draw(Canvas* canvas) final;
bool input(InputEvent* event) final;
void set_text(
const char* text = NULL,
uint8_t x = 0,
uint8_t y = 0,
Align horizontal = AlignLeft,
Align vertical = AlignTop,
Font font = FontPrimary);
private:
const char* text = NULL;
uint8_t x = 0;
uint8_t y = 0;
Align horizontal = AlignLeft;
Align vertical = AlignTop;
Font font = FontPrimary;
};