From 799eefd754a31c7c7d4685e3d17a4adad501d4bf Mon Sep 17 00:00:00 2001 From: DrZlo13 Date: Tue, 17 Nov 2020 07:10:58 +1000 Subject: [PATCH] ibutton app, only read mode --- applications/applications.mk | 12 ++++++++++++ applications/ibutton/ibutton.cpp | 12 ++++++++++++ applications/ibutton/ibutton.h | 4 +++- applications/ibutton/ibutton_mode_dallas_emulate.h | 8 ++++---- applications/ibutton/one_wire_slave_gpio.h | 6 ++---- 5 files changed, 33 insertions(+), 9 deletions(-) diff --git a/applications/applications.mk b/applications/applications.mk index ba21c5197..e675e87a1 100644 --- a/applications/applications.mk +++ b/applications/applications.mk @@ -24,6 +24,7 @@ BUILD_VIBRO_DEMO = 1 BUILD_SD_TEST = 1 BUILD_GPIO_DEMO = 1 BUILD_MUSIC_PLAYER = 1 +BUILD_IBUTTON = 1 endif APP_NFC ?= 0 @@ -258,6 +259,17 @@ CFLAGS += -DBUILD_MUSIC_PLAYER C_SOURCES += $(wildcard $(APP_DIR)/music-player/*.c) endif +APP_IBUTTON ?= 0 +ifeq ($(APP_IBUTTON), 1) +CFLAGS += -DAPP_IBUTTON +BUILD_IBUTTON = 1 +endif +BUILD_IBUTTON ?= 0 +ifeq ($(BUILD_IBUTTON), 1) +CFLAGS += -DBUILD_IBUTTON +CPP_SOURCES += $(wildcard $(APP_DIR)/ibutton/ibutton.cpp) +endif + # device drivers APP_GUI ?= 0 diff --git a/applications/ibutton/ibutton.cpp b/applications/ibutton/ibutton.cpp index ea7cdd415..0278b77bf 100644 --- a/applications/ibutton/ibutton.cpp +++ b/applications/ibutton/ibutton.cpp @@ -4,8 +4,12 @@ // start app void AppiButton::run() { + acquire_state(); mode[0] = new AppiButtonModeDallasRead(this); mode[1] = new AppiButtonModeDallasEmulate(this); + release_state(); + + switch_to_mode(0); // create pin GpioPin red_led = led_gpio[0]; @@ -94,6 +98,14 @@ void AppiButton::decrease_mode() { release_state(); } +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 extern "C" void app_ibutton(void* p) { AppiButton* app = new AppiButton(); diff --git a/applications/ibutton/ibutton.h b/applications/ibutton/ibutton.h index e33009876..9c9c26d64 100644 --- a/applications/ibutton/ibutton.h +++ b/applications/ibutton/ibutton.h @@ -8,7 +8,8 @@ typedef uint8_t event_t; class AppiButtonState { public: // state data - uint8_t dallas_address[8] = {0x01, 0xFD, 0x0E, 0x84, 0x01, 0x00, 0x00, 0xDB}; + // test key = {0x01, 0xFD, 0x0E, 0x84, 0x01, 0x00, 0x00, 0xDB}; + uint8_t dallas_address[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; uint8_t mode_index; // state initializer @@ -51,4 +52,5 @@ public: void increase_mode(); void decrease_mode(); + void switch_to_mode(uint8_t mode_index); }; \ No newline at end of file diff --git a/applications/ibutton/ibutton_mode_dallas_emulate.h b/applications/ibutton/ibutton_mode_dallas_emulate.h index 2d1fd9edb..871a00fb7 100644 --- a/applications/ibutton/ibutton_mode_dallas_emulate.h +++ b/applications/ibutton/ibutton_mode_dallas_emulate.h @@ -25,19 +25,19 @@ public: void AppiButtonModeDallasEmulate::event(AppiButtonEvent* event, AppiButtonState* state) { if(event->type == AppiButtonEvent::EventTypeTick) { - acquire(); - if(onewire_slave->emulate(state->dallas_address, 8)) { + app->blink_red(); + /*if(onewire_slave->emulate(state->dallas_address, 8)) { app->blink_green(); } else { - } + }*/ } } void AppiButtonModeDallasEmulate::render(CanvasApi* canvas, AppiButtonState* state) { canvas->set_font(canvas, FontSecondary); canvas->draw_str(canvas, 2, 25, "< dallas emulate"); - canvas->draw_str(canvas, 2, 37, "give me domophone"); + canvas->draw_str(canvas, 2, 37, "unimplemented"); { char buf[24]; sprintf( diff --git a/applications/ibutton/one_wire_slave_gpio.h b/applications/ibutton/one_wire_slave_gpio.h index 20ff2ca04..cf6cbdd96 100644 --- a/applications/ibutton/one_wire_slave_gpio.h +++ b/applications/ibutton/one_wire_slave_gpio.h @@ -129,8 +129,7 @@ bool OneWireGpioSlave::receiveBit(void) { // wait while bus is HIGH OneWiteTimeType time = OneWireEmulateTiming::SLOT_MAX[overdrive_mode]; time = wait_while_gpio(time, true); - if (time == 0) - { + if(time == 0) { printf("RESET_IN_PROGRESS\n"); return false; } @@ -144,8 +143,7 @@ bool OneWireGpioSlave::receiveBit(void) { // wait while bus is LOW time = OneWireEmulateTiming::MSG_HIGH_TIMEOUT; time = wait_while_gpio(time, false); - if (time == 0) - { + if(time == 0) { printf("TIMEOUT_HIGH\n"); return false; }