[FL-84] iButton app, dallas emulate + cyfral read, cyfral emulate (#253)

* maxim crc function
* one wire template device and ds1990 classes
* 3 fields for addr
* cyfral emulator lib
* add cyfral read mode, refract rendering and events
* add ADC1_IN14, add adc interrupt
* cyfral read mode
* rename and move api-hal includes folder
* build onewire libs only if we build app
* start in mode 0
This commit is contained in:
DrZlo13
2020-11-25 10:25:13 +03:00
committed by GitHub
parent 758e37e294
commit 1f761d7fbb
37 changed files with 1996 additions and 821 deletions

View File

@@ -1,11 +1,15 @@
#include "ibutton.h"
#include "ibutton_mode_dallas_read.h"
#include "ibutton_mode_dallas_emulate.h"
#include "ibutton_mode_cyfral_read.h"
#include "ibutton_mode_cyfral_emulate.h"
// start app
void AppiButton::run() {
mode[0] = new AppiButtonModeDallasRead(this);
mode[1] = new AppiButtonModeDallasEmulate(this);
mode[2] = new AppiButtonModeCyfralRead(this);
mode[3] = new AppiButtonModeCyfralEmulate(this);
switch_to_mode(0);
@@ -21,7 +25,7 @@ void AppiButton::run() {
AppiButtonEvent event;
while(1) {
if(get_event(&event, 100)) {
if(get_event(&event, 20)) {
if(event.type == AppiButtonEvent::EventTypeKey) {
// press events
if(event.value.input.state && event.value.input.input == InputBack) {
@@ -60,6 +64,46 @@ void AppiButton::render(CanvasApi* canvas) {
mode[state.mode_index]->render(canvas, &state);
}
void AppiButton::render_dallas_list(CanvasApi* canvas, AppiButtonState* state) {
const uint8_t buffer_size = 50;
char buf[buffer_size];
for(uint8_t i = 0; i < state->dallas_address_count; i++) {
snprintf(
buf,
buffer_size,
"%s[%u] %x:%x:%x:%x:%x:%x:%x:%x",
(i == state->dallas_address_index) ? "> " : "",
i + 1,
state->dallas_address[i][0],
state->dallas_address[i][1],
state->dallas_address[i][2],
state->dallas_address[i][3],
state->dallas_address[i][4],
state->dallas_address[i][5],
state->dallas_address[i][6],
state->dallas_address[i][7]);
canvas->draw_str(canvas, 2, 37 + i * 12, buf);
}
}
void AppiButton::render_cyfral_list(CanvasApi* canvas, AppiButtonState* state) {
const uint8_t buffer_size = 50;
char buf[buffer_size];
for(uint8_t i = 0; i < state->cyfral_address_count; i++) {
snprintf(
buf,
buffer_size,
"%s[%u] %x:%x:%x:%x",
(i == state->cyfral_address_index) ? "> " : "",
i + 1,
state->cyfral_address[i][0],
state->cyfral_address[i][1],
state->cyfral_address[i][2],
state->cyfral_address[i][3]);
canvas->draw_str(canvas, 2, 37 + i * 12, buf);
}
}
void AppiButton::blink_red() {
gpio_write(red_led_record, 0);
delay(10);
@@ -92,12 +136,34 @@ void AppiButton::decrease_mode() {
release_state();
}
void AppiButton::increase_dallas_address() {
if(state.dallas_address_index < (state.dallas_address_count - 1)) {
state.dallas_address_index++;
}
}
void AppiButton::decrease_dallas_address() {
if(state.dallas_address_index > 0) {
state.dallas_address_index--;
}
}
void AppiButton::increase_cyfral_address() {
if(state.cyfral_address_index < (state.cyfral_address_count - 1)) {
state.cyfral_address_index++;
}
}
void AppiButton::decrease_cyfral_address() {
if(state.cyfral_address_index > 0) {
state.cyfral_address_index--;
}
}
void AppiButton::switch_to_mode(uint8_t mode_index) {
acquire_state();
mode[state.mode_index]->release();
state.mode_index = mode_index;
mode[state.mode_index]->acquire();
release_state();
}
// app enter function