unleashed-firmware/applications/ibutton/ibutton_mode_dallas_read.h
DrZlo13 cf1c8fb223
[FL-85][FL-446][FL-720] Dallas key blanks and OneWire lib rework (#313)
* sepate one wire class
* TM2004 writer
* app mode write ds1990
* test another blanks protocol
* new ibutton slave
* one wire states
* tim1 capture compare and update interrupts
* interrupt mgr, new timers IRQ
* discard HAL_TIM_PeriodElapsedCallback from main
* add exti_14 line
* add external interrupt callback
* use int mgr in input
* better interrupt managment
* add interrupt callback enable and disable fns
* properly init app
* changed timings
* rename one wire classes
* use new owb classes
* properly remove interrupts
* new blanks writer
* remove unused tests
* new core includes
* extern c guard
* fix api_interrupt_remove usage
* remove debug info, new way to detect blanks writing
* remove copy constructor
* change keys template
* fix app sources recipe
2021-01-28 15:30:31 +03:00

71 lines
No EOL
2 KiB
C++

#pragma once
#include "ibutton.h"
#include "one_wire_master.h"
#include "maxim_crc.h"
class AppiButtonModeDallasRead : public AppTemplateMode<AppiButtonState, AppiButtonEvent> {
public:
const char* name = "dallas read";
AppiButton* app;
OneWireMaster* onewire;
void event(AppiButtonEvent* event, AppiButtonState* state);
void render(Canvas* canvas, AppiButtonState* state);
void acquire();
void release();
AppiButtonModeDallasRead(AppiButton* parent_app) {
app = parent_app;
// TODO open record
const GpioPin* one_wire_pin_record = &ibutton_gpio;
onewire = new OneWireMaster(one_wire_pin_record);
};
};
void AppiButtonModeDallasRead::event(AppiButtonEvent* event, AppiButtonState* state) {
if(event->type == AppiButtonEvent::EventTypeTick) {
bool result = 0;
uint8_t address[8];
osKernelLock();
result = onewire->reset();
osKernelUnlock();
if(result) {
osKernelLock();
__disable_irq();
onewire->write(0x33);
onewire->read_bytes(address, 8);
__enable_irq();
osKernelUnlock();
if(maxim_crc8(address, 8) == 0) {
memcpy(app->state.dallas_address[app->state.dallas_address_index], address, 8);
app->blink_green();
}
}
} else if(event->type == AppiButtonEvent::EventTypeKey) {
if(event->value.input.state && event->value.input.input == InputUp) {
app->decrease_dallas_address();
}
if(event->value.input.state && event->value.input.input == InputDown) {
app->increase_dallas_address();
}
}
}
void AppiButtonModeDallasRead::render(Canvas* canvas, AppiButtonState* state) {
canvas_set_font(canvas, FontSecondary);
canvas_draw_str(canvas, 2, 25, "Dallas read >");
app->render_dallas_list(canvas, state);
}
void AppiButtonModeDallasRead::acquire() {
onewire->start();
}
void AppiButtonModeDallasRead::release() {
onewire->stop();
}