[FL-2393][FL-2381] iButton, OneWire: move to plain C (#1068)
* iButton: getting started on the worker concept * Hal delay: added global instructions_per_us variable * iButton: one wire slave * iButton: ibutton key setter * iButton: one wire host, use ibutton_hal * iButton\RFID: common pulse decoder concept * iButton: cyfral decoder * iButton: worker thread concept * iButton: metakom decoder * iButton: write key through worker * iButton: worker mode holder * iButton: worker improvements * iButton: Cyfral encoder * iButton: Metakom encoder * lib: pulse protocol helpers * iButton: Metakom decoder * iButton: Cyfral decoder * iButton worker: separate modes * iButton: libs documentation * HAL: iButton gpio modes * iButton worker: rename modes file * iButton worker, hal: move to LL * iButton CLI: worker for reading and emulation commands * iButton HAL: correct init and emulation sequence * iButton cli: moved to plain C * iButton: move to worker, small step to plain C * Libs, one wire: move to plain C * Libs: added forgotten files to compilation * iButton writer: get rid of manual disable/enable irq
This commit is contained in:
@@ -1,193 +0,0 @@
|
||||
#include "cyfral_decoder.h"
|
||||
#include <furi.h>
|
||||
|
||||
void CyfralDecoder::reset_state() {
|
||||
state = State::WAIT_START_NIBBLE;
|
||||
bit_state = BitState::WAIT_FRONT_LOW;
|
||||
|
||||
period_time = 0;
|
||||
bit_index = 0;
|
||||
ready = false;
|
||||
index = 0;
|
||||
|
||||
key_data = 0;
|
||||
readed_nibble = 0;
|
||||
data_valid = true;
|
||||
}
|
||||
|
||||
bool CyfralDecoder::nibble_valid(uint8_t data) {
|
||||
uint8_t data_value = data & 0x0F;
|
||||
|
||||
switch(data_value) {
|
||||
case 0b1110:
|
||||
case 0b1101:
|
||||
case 0b1011:
|
||||
case 0b0111:
|
||||
return true;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
CyfralDecoder::CyfralDecoder() {
|
||||
reset_state();
|
||||
max_period = 0;
|
||||
}
|
||||
|
||||
void CyfralDecoder::process_front(bool polarity, uint32_t time) {
|
||||
bool readed;
|
||||
bool value;
|
||||
|
||||
if(max_period == 0) {
|
||||
max_period = 230 * (SystemCoreClock / 1000000.0f);
|
||||
}
|
||||
|
||||
if(ready) return;
|
||||
|
||||
switch(state) {
|
||||
case State::WAIT_START_NIBBLE:
|
||||
// wait for start word
|
||||
if(process_bit(polarity, time, &readed, &value)) {
|
||||
if(readed) {
|
||||
readed_nibble = ((readed_nibble << 1) | value) & 0x0F;
|
||||
if(readed_nibble == 0b0001) {
|
||||
readed_nibble = 0;
|
||||
state = State::READ_NIBBLE;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
reset_state();
|
||||
}
|
||||
|
||||
break;
|
||||
case State::READ_NIBBLE:
|
||||
// read nibbles
|
||||
if(process_bit(polarity, time, &readed, &value)) {
|
||||
if(readed) {
|
||||
readed_nibble = (readed_nibble << 1) | value;
|
||||
|
||||
bit_index++;
|
||||
|
||||
//convert every nibble to 2-bit index
|
||||
if(bit_index == 4) {
|
||||
switch(readed_nibble) {
|
||||
case 0b1110:
|
||||
key_data = (key_data << 2) | 0b11;
|
||||
break;
|
||||
case 0b1101:
|
||||
key_data = (key_data << 2) | 0b10;
|
||||
break;
|
||||
case 0b1011:
|
||||
key_data = (key_data << 2) | 0b01;
|
||||
break;
|
||||
case 0b0111:
|
||||
key_data = (key_data << 2) | 0b00;
|
||||
break;
|
||||
default:
|
||||
data_valid = false;
|
||||
break;
|
||||
}
|
||||
|
||||
readed_nibble = 0;
|
||||
bit_index = 0;
|
||||
index++;
|
||||
}
|
||||
|
||||
// succefully read 8 nibbles
|
||||
if(index == 8) {
|
||||
state = State::READ_STOP_NIBBLE;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
reset_state();
|
||||
}
|
||||
break;
|
||||
case State::READ_STOP_NIBBLE:
|
||||
// read stop nibble
|
||||
if(process_bit(polarity, time, &readed, &value)) {
|
||||
if(readed) {
|
||||
readed_nibble = ((readed_nibble << 1) | value) & 0x0F;
|
||||
bit_index++;
|
||||
|
||||
switch(bit_index) {
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
break;
|
||||
case 4:
|
||||
if(readed_nibble == 0b0001) {
|
||||
// validate data
|
||||
if(data_valid) {
|
||||
ready = true;
|
||||
} else {
|
||||
reset_state();
|
||||
}
|
||||
} else {
|
||||
reset_state();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
reset_state();
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
reset_state();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool CyfralDecoder::process_bit(bool polarity, uint32_t time, bool* readed, bool* readed_value) {
|
||||
bool result = true;
|
||||
*readed = false;
|
||||
|
||||
// bit start from low
|
||||
switch(bit_state) {
|
||||
case BitState::WAIT_FRONT_LOW:
|
||||
if(polarity == true) {
|
||||
period_time += time;
|
||||
|
||||
*readed = true;
|
||||
if(period_time <= max_period) {
|
||||
if((period_time / 2) > time) {
|
||||
*readed_value = false;
|
||||
} else {
|
||||
*readed_value = true;
|
||||
}
|
||||
} else {
|
||||
result = false;
|
||||
}
|
||||
|
||||
bit_state = BitState::WAIT_FRONT_HIGH;
|
||||
} else {
|
||||
result = false;
|
||||
}
|
||||
break;
|
||||
case BitState::WAIT_FRONT_HIGH:
|
||||
if(polarity == false) {
|
||||
period_time = time;
|
||||
bit_state = BitState::WAIT_FRONT_LOW;
|
||||
} else {
|
||||
result = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool CyfralDecoder::read(uint8_t* _data, uint8_t data_size) {
|
||||
furi_check(data_size <= 2);
|
||||
bool result = false;
|
||||
|
||||
if(ready) {
|
||||
memcpy(_data, &key_data, data_size);
|
||||
reset_state();
|
||||
result = true;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include <atomic>
|
||||
|
||||
class CyfralDecoder {
|
||||
public:
|
||||
bool read(uint8_t* data, uint8_t data_size);
|
||||
void process_front(bool polarity, uint32_t time);
|
||||
|
||||
CyfralDecoder();
|
||||
|
||||
private:
|
||||
enum class BitState : uint8_t {
|
||||
WAIT_FRONT_HIGH,
|
||||
WAIT_FRONT_LOW,
|
||||
};
|
||||
|
||||
enum class State : uint8_t {
|
||||
WAIT_START_NIBBLE,
|
||||
READ_NIBBLE,
|
||||
READ_STOP_NIBBLE,
|
||||
};
|
||||
|
||||
State state;
|
||||
BitState bit_state;
|
||||
|
||||
bool process_bit(bool polarity, uint32_t time, bool* readed, bool* readed_value);
|
||||
void reset_state();
|
||||
bool nibble_valid(uint8_t data);
|
||||
|
||||
// high + low period time
|
||||
uint32_t period_time;
|
||||
|
||||
// ready flag, key is readed and valid
|
||||
std::atomic<bool> ready;
|
||||
|
||||
// key data storage
|
||||
uint16_t key_data;
|
||||
|
||||
// temporary nibble storage
|
||||
uint8_t readed_nibble;
|
||||
|
||||
// data valid flag
|
||||
// MUST be checked only in READ_STOP_NIBBLE state
|
||||
bool data_valid;
|
||||
|
||||
// nibble index, we expect 8 nibbles
|
||||
uint8_t index;
|
||||
|
||||
// bit index in nibble, 4 bit per nibble
|
||||
uint8_t bit_index;
|
||||
|
||||
// max period, 230us x clock per us
|
||||
uint32_t max_period;
|
||||
};
|
||||
@@ -1,39 +0,0 @@
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
|
||||
class RW1990_1 {
|
||||
public:
|
||||
constexpr static const uint8_t CMD_WRITE_RECORD_FLAG = 0xD1;
|
||||
constexpr static const uint8_t CMD_READ_RECORD_FLAG = 0xB5;
|
||||
constexpr static const uint8_t CMD_WRITE_ROM = 0xD5;
|
||||
};
|
||||
|
||||
class RW1990_2 {
|
||||
public:
|
||||
constexpr static const uint8_t CMD_WRITE_RECORD_FLAG = 0x1D;
|
||||
constexpr static const uint8_t CMD_READ_RECORD_FLAG = 0x1E;
|
||||
constexpr static const uint8_t CMD_WRITE_ROM = 0xD5;
|
||||
};
|
||||
|
||||
class TM2004 {
|
||||
public:
|
||||
constexpr static const uint8_t CMD_READ_STATUS = 0xAA;
|
||||
constexpr static const uint8_t CMD_READ_MEMORY = 0xF0;
|
||||
constexpr static const uint8_t CMD_WRITE_ROM = 0x3C;
|
||||
constexpr static const uint8_t CMD_FINALIZATION = 0x35;
|
||||
|
||||
constexpr static const uint8_t ANSWER_READ_MEMORY = 0xF5;
|
||||
};
|
||||
|
||||
class TM01 {
|
||||
public:
|
||||
constexpr static const uint8_t CMD_WRITE_RECORD_FLAG = 0xC1;
|
||||
constexpr static const uint8_t CMD_WRITE_ROM = 0xC5;
|
||||
constexpr static const uint8_t CMD_SWITCH_TO_CYFRAL = 0xCA;
|
||||
constexpr static const uint8_t CMD_SWITCH_TO_METAKOM = 0xCB;
|
||||
};
|
||||
|
||||
class DS1990 {
|
||||
public:
|
||||
constexpr static const uint8_t CMD_READ_ROM = 0x33;
|
||||
};
|
||||
@@ -1,208 +0,0 @@
|
||||
#include "key_emulator.h"
|
||||
#include <callback-connector.h>
|
||||
|
||||
KeyEmulator::~KeyEmulator() {
|
||||
stop();
|
||||
}
|
||||
|
||||
KeyEmulator::KeyEmulator(OneWireSlave* _onewire_slave)
|
||||
: dallas_key{0, 0, 0, 0, 0, 0, 0} {
|
||||
onewire_slave = _onewire_slave;
|
||||
|
||||
auto cb = cbc::obtain_connector(this, &KeyEmulator::result_callback);
|
||||
onewire_slave->set_result_callback(cb, this);
|
||||
}
|
||||
|
||||
void KeyEmulator::start(iButtonKey* key) {
|
||||
anything_emulated = false;
|
||||
stop();
|
||||
|
||||
// pulldown pull pin, to prevent low-pass filtering by the RFID part of the schematic
|
||||
furi_hal_rfid_pin_pull_pulldown();
|
||||
|
||||
switch(key->get_key_type()) {
|
||||
case iButtonKeyType::KeyDallas:
|
||||
start_dallas_emulate(key);
|
||||
break;
|
||||
case iButtonKeyType::KeyCyfral:
|
||||
start_cyfral_emulate(key);
|
||||
break;
|
||||
case iButtonKeyType::KeyMetakom:
|
||||
start_metakom_emulate(key);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool KeyEmulator::emulated() {
|
||||
bool result = false;
|
||||
|
||||
if(anything_emulated) {
|
||||
anything_emulated = false;
|
||||
result = true;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void KeyEmulator::stop() {
|
||||
onewire_slave->stop();
|
||||
pulser.stop();
|
||||
furi_hal_rfid_pins_reset();
|
||||
}
|
||||
|
||||
void KeyEmulator::start_cyfral_emulate(iButtonKey* key) {
|
||||
furi_assert(key->get_key_type() == iButtonKeyType::KeyCyfral);
|
||||
furi_assert(key->get_type_data_size() == 2);
|
||||
|
||||
const uint32_t cyfral_period_full = 8000;
|
||||
const uint32_t cyfral_period_one[2] = {
|
||||
uint32_t(cyfral_period_full * 0.33f), uint32_t(cyfral_period_full * 0.66f)};
|
||||
const uint32_t cyfral_period_zero[2] = {
|
||||
uint32_t(cyfral_period_full * 0.66f), uint32_t(cyfral_period_full * 0.33f)};
|
||||
uint8_t pd_index = 0;
|
||||
uint8_t* key_data = key->get_data();
|
||||
|
||||
// start nibble
|
||||
set_pulse_data_cyfral(pd_index, cyfral_period_zero);
|
||||
pd_index++;
|
||||
set_pulse_data_cyfral(pd_index, cyfral_period_zero);
|
||||
pd_index++;
|
||||
set_pulse_data_cyfral(pd_index, cyfral_period_zero);
|
||||
pd_index++;
|
||||
set_pulse_data_cyfral(pd_index, cyfral_period_one);
|
||||
pd_index++;
|
||||
|
||||
// data nibbles x 8
|
||||
for(int8_t i = key->get_type_data_size() - 1; i >= 0; i--) {
|
||||
for(int8_t j = 3; j >= 0; j--) {
|
||||
switch((key_data[i] >> (j * 2)) & 0b00000011) {
|
||||
case 0b11:
|
||||
set_pulse_data_cyfral(pd_index, cyfral_period_one);
|
||||
pd_index++;
|
||||
set_pulse_data_cyfral(pd_index, cyfral_period_one);
|
||||
pd_index++;
|
||||
set_pulse_data_cyfral(pd_index, cyfral_period_one);
|
||||
pd_index++;
|
||||
set_pulse_data_cyfral(pd_index, cyfral_period_zero);
|
||||
pd_index++;
|
||||
break;
|
||||
case 0b10:
|
||||
set_pulse_data_cyfral(pd_index, cyfral_period_one);
|
||||
pd_index++;
|
||||
set_pulse_data_cyfral(pd_index, cyfral_period_one);
|
||||
pd_index++;
|
||||
set_pulse_data_cyfral(pd_index, cyfral_period_zero);
|
||||
pd_index++;
|
||||
set_pulse_data_cyfral(pd_index, cyfral_period_one);
|
||||
pd_index++;
|
||||
break;
|
||||
case 0b01:
|
||||
set_pulse_data_cyfral(pd_index, cyfral_period_one);
|
||||
pd_index++;
|
||||
set_pulse_data_cyfral(pd_index, cyfral_period_zero);
|
||||
pd_index++;
|
||||
set_pulse_data_cyfral(pd_index, cyfral_period_one);
|
||||
pd_index++;
|
||||
set_pulse_data_cyfral(pd_index, cyfral_period_one);
|
||||
pd_index++;
|
||||
break;
|
||||
case 0b00:
|
||||
set_pulse_data_cyfral(pd_index, cyfral_period_zero);
|
||||
pd_index++;
|
||||
set_pulse_data_cyfral(pd_index, cyfral_period_one);
|
||||
pd_index++;
|
||||
set_pulse_data_cyfral(pd_index, cyfral_period_one);
|
||||
pd_index++;
|
||||
set_pulse_data_cyfral(pd_index, cyfral_period_one);
|
||||
pd_index++;
|
||||
break;
|
||||
default:
|
||||
// cannot be anyway
|
||||
furi_check(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 4 (nibbles) x (8 data + 1 start) = 4 x 9 = 36
|
||||
if(pd_index != 36) {
|
||||
// something is very wrong
|
||||
furi_check(false);
|
||||
}
|
||||
|
||||
pulser.set_periods(pulse_data, 72, false);
|
||||
pulser.start();
|
||||
}
|
||||
|
||||
void KeyEmulator::start_metakom_emulate(iButtonKey* key) {
|
||||
furi_assert(key->get_key_type() == iButtonKeyType::KeyMetakom);
|
||||
furi_assert(key->get_type_data_size() == 4);
|
||||
|
||||
const uint32_t metakom_period_full = 8000;
|
||||
const uint32_t metakom_period_zero[2] = {
|
||||
uint32_t(metakom_period_full * 0.33f), uint32_t(metakom_period_full * 0.66f)};
|
||||
const uint32_t metakom_period_one[2] = {
|
||||
uint32_t(metakom_period_full * 0.66f), uint32_t(metakom_period_full * 0.33f)};
|
||||
uint8_t pd_index = 0;
|
||||
|
||||
uint8_t* key_data = key->get_data();
|
||||
|
||||
// start pulse
|
||||
pulse_data[0] = metakom_period_full;
|
||||
|
||||
// start triplet
|
||||
set_pulse_data_metakom(pd_index, metakom_period_zero);
|
||||
pd_index++;
|
||||
set_pulse_data_metakom(pd_index, metakom_period_one);
|
||||
pd_index++;
|
||||
set_pulse_data_metakom(pd_index, metakom_period_zero);
|
||||
pd_index++;
|
||||
|
||||
for(int8_t i = key->get_type_data_size() - 1; i >= 0; i--) {
|
||||
for(int8_t j = 7; j >= 0; j--) {
|
||||
if(((key_data[i] >> j) & 0b00000001) == 1) {
|
||||
set_pulse_data_metakom(pd_index, metakom_period_one);
|
||||
pd_index++;
|
||||
} else {
|
||||
set_pulse_data_metakom(pd_index, metakom_period_zero);
|
||||
pd_index++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 4 byte x 8 bits + 3 start bits = 35
|
||||
if(pd_index != 35) {
|
||||
// something is very wrong
|
||||
furi_check(false);
|
||||
}
|
||||
|
||||
pulser.set_periods(pulse_data, 71, false);
|
||||
pulser.start();
|
||||
}
|
||||
|
||||
void KeyEmulator::start_dallas_emulate(iButtonKey* key) {
|
||||
furi_assert(key->get_key_type() == iButtonKeyType::KeyDallas);
|
||||
furi_assert(key->get_type_data_size() == 8);
|
||||
|
||||
onewire_slave->deattach();
|
||||
memcpy(dallas_key.id_storage, key->get_data(), key->get_type_data_size());
|
||||
onewire_slave->attach(&dallas_key);
|
||||
onewire_slave->start();
|
||||
}
|
||||
|
||||
void KeyEmulator::set_pulse_data_cyfral(uint8_t index, const uint32_t* data) {
|
||||
pulse_data[index * 2] = data[0];
|
||||
pulse_data[index * 2 + 1] = data[1];
|
||||
}
|
||||
|
||||
void KeyEmulator::set_pulse_data_metakom(uint8_t index, const uint32_t* data) {
|
||||
// damn start pulse
|
||||
pulse_data[(index * 2) + 1] = data[0];
|
||||
pulse_data[(index * 2) + 2] = data[1];
|
||||
}
|
||||
|
||||
void KeyEmulator::result_callback(bool success, void* ctx) {
|
||||
KeyEmulator* _this = static_cast<KeyEmulator*>(ctx);
|
||||
|
||||
_this->anything_emulated = true;
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
#pragma once
|
||||
#include "pulse_sequencer.h"
|
||||
#include "../ibutton_key.h"
|
||||
#include <one_wire_slave.h>
|
||||
#include <one_wire_device_ds_1990.h>
|
||||
#include <atomic>
|
||||
|
||||
class KeyEmulator {
|
||||
public:
|
||||
KeyEmulator(OneWireSlave* onewire_slave);
|
||||
~KeyEmulator();
|
||||
|
||||
void start(iButtonKey* key);
|
||||
bool emulated();
|
||||
void stop();
|
||||
|
||||
private:
|
||||
DS1990 dallas_key;
|
||||
OneWireSlave* onewire_slave;
|
||||
|
||||
PulseSequencer pulser;
|
||||
uint32_t pulse_data[72];
|
||||
|
||||
std::atomic<bool> anything_emulated;
|
||||
|
||||
void start_cyfral_emulate(iButtonKey* key);
|
||||
void start_metakom_emulate(iButtonKey* key);
|
||||
void start_dallas_emulate(iButtonKey* key);
|
||||
|
||||
void set_pulse_data_cyfral(uint8_t index, const uint32_t* data);
|
||||
void set_pulse_data_metakom(uint8_t index, const uint32_t* data);
|
||||
|
||||
void result_callback(bool success, void* ctx);
|
||||
};
|
||||
@@ -1,11 +0,0 @@
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
|
||||
static const uint8_t IBUTTON_KEY_DATA_SIZE = 8;
|
||||
static const uint8_t IBUTTON_KEY_NAME_SIZE = 22;
|
||||
|
||||
enum class iButtonKeyType : uint8_t {
|
||||
KeyDallas,
|
||||
KeyCyfral,
|
||||
KeyMetakom,
|
||||
};
|
||||
@@ -1,181 +0,0 @@
|
||||
#include "key_reader.h"
|
||||
#include "key_commands.h"
|
||||
#include <callback-connector.h>
|
||||
#include <maxim_crc.h>
|
||||
|
||||
KeyReader::Error KeyReader::read(iButtonKey* key) {
|
||||
uint8_t tmp_key_data[8] = {0, 0, 0, 0, 0, 0, 0, 0};
|
||||
iButtonKeyType key_type;
|
||||
|
||||
KeyReader::Error result = KeyReader::Error::EMPTY;
|
||||
|
||||
if(read_key(&key_type, tmp_key_data, 8)) {
|
||||
switch(key_type) {
|
||||
case iButtonKeyType::KeyDallas:
|
||||
if(verify_key(key_type, tmp_key_data, 8)) {
|
||||
if(maxim_crc8(tmp_key_data, 8) == 0) {
|
||||
if(tmp_key_data[0] == 0x01) {
|
||||
result = KeyReader::Error::OK;
|
||||
} else {
|
||||
result = KeyReader::Error::NOT_ARE_KEY;
|
||||
}
|
||||
} else {
|
||||
result = KeyReader::Error::CRC_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case iButtonKeyType::KeyCyfral:
|
||||
result = KeyReader::Error::OK;
|
||||
break;
|
||||
case iButtonKeyType::KeyMetakom:
|
||||
result = KeyReader::Error::OK;
|
||||
break;
|
||||
}
|
||||
|
||||
if(result != KeyReader::Error::EMPTY) {
|
||||
key->set_type(key_type);
|
||||
key->set_data(tmp_key_data, 8);
|
||||
}
|
||||
}
|
||||
|
||||
switch_mode_if_needed();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
KeyReader::KeyReader(OneWireMaster* _onewire_master) {
|
||||
onewire_master = _onewire_master;
|
||||
read_mode_switch_time = 0;
|
||||
read_mode = ReadMode::DALLAS;
|
||||
}
|
||||
|
||||
KeyReader::~KeyReader() {
|
||||
stop();
|
||||
}
|
||||
|
||||
bool KeyReader::read_key(iButtonKeyType* key_type, uint8_t* data, uint8_t data_size) {
|
||||
bool readed = false;
|
||||
|
||||
if(read_mode == ReadMode::DALLAS) {
|
||||
FURI_CRITICAL_ENTER();
|
||||
if(onewire_master->search(data)) {
|
||||
onewire_master->reset_search();
|
||||
readed = true;
|
||||
*key_type = iButtonKeyType::KeyDallas;
|
||||
} else {
|
||||
onewire_master->reset_search();
|
||||
}
|
||||
FURI_CRITICAL_EXIT();
|
||||
} else if(read_mode == ReadMode::CYFRAL_METAKOM) {
|
||||
if(cyfral_decoder.read(data, 2)) {
|
||||
readed = true;
|
||||
*key_type = iButtonKeyType::KeyCyfral;
|
||||
} else if(metakom_decoder.read(data, 4)) {
|
||||
readed = true;
|
||||
*key_type = iButtonKeyType::KeyMetakom;
|
||||
}
|
||||
}
|
||||
|
||||
return readed;
|
||||
}
|
||||
|
||||
bool KeyReader::verify_key(iButtonKeyType key_type, const uint8_t* const data, uint8_t data_size) {
|
||||
bool result = true;
|
||||
|
||||
if(key_type == iButtonKeyType::KeyDallas) {
|
||||
switch_to(ReadMode::DALLAS);
|
||||
|
||||
FURI_CRITICAL_ENTER();
|
||||
if(onewire_master->reset()) {
|
||||
onewire_master->write(DS1990::CMD_READ_ROM);
|
||||
for(uint8_t i = 0; i < data_size; i++) {
|
||||
if(onewire_master->read() != data[i]) {
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
result = false;
|
||||
}
|
||||
FURI_CRITICAL_EXIT();
|
||||
|
||||
} else {
|
||||
result = false;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void KeyReader::start_comaparator(void) {
|
||||
furi_hal_rfid_pins_reset();
|
||||
|
||||
// pulldown pull pin, we sense the signal through the analog part of the RFID schematic
|
||||
furi_hal_rfid_pin_pull_pulldown();
|
||||
|
||||
comparator_callback_pointer =
|
||||
cbc::obtain_connector(this, &KeyReader::comparator_trigger_callback);
|
||||
furi_hal_rfid_comp_set_callback(comparator_callback_pointer, this);
|
||||
last_dwt_value = DWT->CYCCNT;
|
||||
furi_hal_rfid_comp_start();
|
||||
}
|
||||
|
||||
void KeyReader::stop_comaparator(void) {
|
||||
furi_hal_rfid_pins_reset();
|
||||
|
||||
// rfid_pins_reset will disable ibutton pin
|
||||
furi_hal_ibutton_start();
|
||||
|
||||
furi_hal_rfid_comp_stop();
|
||||
furi_hal_rfid_comp_set_callback(NULL, NULL);
|
||||
}
|
||||
|
||||
void KeyReader::comparator_trigger_callback(bool level, void* comp_ctx) {
|
||||
KeyReader* _this = static_cast<KeyReader*>(comp_ctx);
|
||||
|
||||
uint32_t current_dwt_value = DWT->CYCCNT;
|
||||
|
||||
_this->cyfral_decoder.process_front(level, current_dwt_value - last_dwt_value);
|
||||
_this->metakom_decoder.process_front(level, current_dwt_value - last_dwt_value);
|
||||
|
||||
last_dwt_value = current_dwt_value;
|
||||
}
|
||||
|
||||
void KeyReader::switch_to(ReadMode mode) {
|
||||
switch(mode) {
|
||||
case ReadMode::DALLAS:
|
||||
onewire_master->start();
|
||||
stop_comaparator();
|
||||
break;
|
||||
case ReadMode::CYFRAL_METAKOM:
|
||||
onewire_master->stop();
|
||||
start_comaparator();
|
||||
break;
|
||||
}
|
||||
|
||||
read_mode = mode;
|
||||
}
|
||||
|
||||
void KeyReader::switch_mode_if_needed() {
|
||||
if(osKernelGetTickCount() - read_mode_switch_time > (osKernelGetTickFreq() / 5)) {
|
||||
read_mode_switch_time = osKernelGetTickCount();
|
||||
switch(read_mode) {
|
||||
case ReadMode::DALLAS:
|
||||
switch_to(ReadMode::CYFRAL_METAKOM);
|
||||
break;
|
||||
case ReadMode::CYFRAL_METAKOM:
|
||||
switch_to(ReadMode::DALLAS);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void KeyReader::start() {
|
||||
furi_hal_power_enable_otg();
|
||||
switch_to(ReadMode::CYFRAL_METAKOM);
|
||||
}
|
||||
|
||||
void KeyReader::stop() {
|
||||
furi_hal_power_disable_otg();
|
||||
onewire_master->stop();
|
||||
stop_comaparator();
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include <furi.h>
|
||||
#include "cyfral_decoder.h"
|
||||
#pragma once
|
||||
#include "metakom_decoder.h"
|
||||
#include "../ibutton_key.h"
|
||||
#include <one_wire_master.h>
|
||||
#include <one_wire_slave.h>
|
||||
|
||||
class KeyReader {
|
||||
public:
|
||||
enum class Error : uint8_t {
|
||||
EMPTY,
|
||||
CRC_ERROR,
|
||||
NOT_ARE_KEY,
|
||||
OK,
|
||||
};
|
||||
|
||||
void start();
|
||||
void stop();
|
||||
KeyReader::Error read(iButtonKey* key);
|
||||
KeyReader(OneWireMaster* onewire_master);
|
||||
~KeyReader();
|
||||
|
||||
private:
|
||||
bool read_key(iButtonKeyType* key_type, uint8_t* data, uint8_t data_size);
|
||||
bool verify_key(iButtonKeyType key_type, const uint8_t* const data, uint8_t data_size);
|
||||
|
||||
// cyfral and metakom readers data
|
||||
void comparator_trigger_callback(bool level, void* comp_ctx);
|
||||
void (*comparator_callback_pointer)(bool level, void* comp_ctx);
|
||||
|
||||
void start_comaparator(void);
|
||||
void stop_comaparator(void);
|
||||
uint32_t last_dwt_value;
|
||||
|
||||
CyfralDecoder cyfral_decoder;
|
||||
MetakomDecoder metakom_decoder;
|
||||
|
||||
// mode
|
||||
uint32_t read_mode_switch_time;
|
||||
enum class ReadMode : uint8_t {
|
||||
CYFRAL_METAKOM,
|
||||
DALLAS,
|
||||
};
|
||||
ReadMode read_mode;
|
||||
|
||||
// one wire
|
||||
OneWireMaster* onewire_master;
|
||||
|
||||
void switch_to(ReadMode mode);
|
||||
void switch_mode_if_needed();
|
||||
};
|
||||
@@ -1,52 +0,0 @@
|
||||
#include "key_worker.h"
|
||||
#include <callback-connector.h>
|
||||
#include <maxim_crc.h>
|
||||
|
||||
KeyReader::Error KeyWorker::read(iButtonKey* key) {
|
||||
KeyReader::Error result = key_reader.read(key);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void KeyWorker::start_read() {
|
||||
key_reader.start();
|
||||
}
|
||||
|
||||
void KeyWorker::stop_read() {
|
||||
key_reader.stop();
|
||||
}
|
||||
|
||||
bool KeyWorker::emulated() {
|
||||
return key_emulator.emulated();
|
||||
}
|
||||
|
||||
void KeyWorker::start_emulate(iButtonKey* key) {
|
||||
key_emulator.start(key);
|
||||
}
|
||||
|
||||
void KeyWorker::stop_emulate() {
|
||||
key_emulator.stop();
|
||||
}
|
||||
|
||||
KeyWriter::Error KeyWorker::write(iButtonKey* key) {
|
||||
return key_writer.write(key);
|
||||
}
|
||||
|
||||
void KeyWorker::start_write() {
|
||||
key_writer.start();
|
||||
}
|
||||
|
||||
void KeyWorker::stop_write() {
|
||||
key_writer.stop();
|
||||
}
|
||||
|
||||
KeyWorker::KeyWorker(const GpioPin* one_wire_gpio)
|
||||
: onewire_master{one_wire_gpio}
|
||||
, onewire_slave{one_wire_gpio}
|
||||
, key_reader{&onewire_master}
|
||||
, key_emulator{&onewire_slave}
|
||||
, key_writer{&onewire_master} {
|
||||
}
|
||||
|
||||
KeyWorker::~KeyWorker() {
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
#pragma once
|
||||
#include <furi.h>
|
||||
#include "key_info.h"
|
||||
#include "key_reader.h"
|
||||
#include "key_emulator.h"
|
||||
#include "key_writer.h"
|
||||
#include "../ibutton_key.h"
|
||||
#include <one_wire_master.h>
|
||||
#include <one_wire_slave.h>
|
||||
|
||||
class KeyWorker {
|
||||
public:
|
||||
KeyReader::Error read(iButtonKey* key);
|
||||
void start_read();
|
||||
void stop_read();
|
||||
|
||||
bool emulated();
|
||||
void start_emulate(iButtonKey* key);
|
||||
void stop_emulate();
|
||||
|
||||
KeyWriter::Error write(iButtonKey* key);
|
||||
void start_write();
|
||||
void stop_write();
|
||||
|
||||
KeyWorker(const GpioPin* one_wire_gpio);
|
||||
~KeyWorker();
|
||||
|
||||
private:
|
||||
// one wire
|
||||
OneWireMaster onewire_master;
|
||||
OneWireSlave onewire_slave;
|
||||
KeyReader key_reader;
|
||||
KeyEmulator key_emulator;
|
||||
KeyWriter key_writer;
|
||||
};
|
||||
@@ -1,278 +0,0 @@
|
||||
#include "key_writer.h"
|
||||
#include "key_commands.h"
|
||||
|
||||
KeyWriter::KeyWriter(OneWireMaster* _onewire_master) {
|
||||
onewire_master = _onewire_master;
|
||||
}
|
||||
|
||||
KeyWriter::~KeyWriter() {
|
||||
stop();
|
||||
}
|
||||
|
||||
KeyWriter::Error KeyWriter::write(iButtonKey* key) {
|
||||
return write_internal(key);
|
||||
}
|
||||
|
||||
void KeyWriter::start() {
|
||||
furi_hal_power_enable_otg();
|
||||
onewire_master->start();
|
||||
}
|
||||
|
||||
void KeyWriter::stop() {
|
||||
furi_hal_power_disable_otg();
|
||||
onewire_master->stop();
|
||||
}
|
||||
|
||||
KeyWriter::Error KeyWriter::write_internal(iButtonKey* key) {
|
||||
Error result = Error::NO_DETECT;
|
||||
bool same_key = false;
|
||||
|
||||
osKernelLock();
|
||||
bool presence = onewire_master->reset();
|
||||
osKernelUnlock();
|
||||
|
||||
if(presence) {
|
||||
switch(key->get_key_type()) {
|
||||
case iButtonKeyType::KeyDallas:
|
||||
same_key = compare_key_ds1990(key);
|
||||
|
||||
if(!same_key) {
|
||||
bool write_result = false;
|
||||
// currently we can write:
|
||||
// RW1990, TM08v2, TM08vi-2 by write_1990_1()
|
||||
// RW2004, RW2004 with EEPROM by write_TM2004();
|
||||
|
||||
if(!write_result) {
|
||||
write_result = write_1990_1(key);
|
||||
}
|
||||
if(!write_result) {
|
||||
write_result = write_1990_2(key);
|
||||
}
|
||||
if(!write_result) {
|
||||
write_result = write_TM2004(key);
|
||||
}
|
||||
|
||||
if(write_result) {
|
||||
result = Error::OK;
|
||||
} else {
|
||||
result = Error::CANNOT_WRITE;
|
||||
}
|
||||
} else {
|
||||
result = Error::SAME_KEY;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool KeyWriter::compare_key_ds1990(iButtonKey* key) {
|
||||
bool result = false;
|
||||
|
||||
if(key->get_key_type() == iButtonKeyType::KeyDallas) {
|
||||
FURI_CRITICAL_ENTER();
|
||||
bool presence = onewire_master->reset();
|
||||
|
||||
if(presence) {
|
||||
onewire_master->write(DS1990::CMD_READ_ROM);
|
||||
|
||||
result = true;
|
||||
for(uint8_t i = 0; i < key->get_type_data_size(); i++) {
|
||||
if(key->get_data()[i] != onewire_master->read()) {
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FURI_CRITICAL_EXIT();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool KeyWriter::write_1990_1(iButtonKey* key) {
|
||||
bool result = false;
|
||||
|
||||
if(key->get_key_type() == iButtonKeyType::KeyDallas) {
|
||||
FURI_CRITICAL_ENTER();
|
||||
|
||||
// unlock
|
||||
onewire_master->reset();
|
||||
onewire_master->write(RW1990_1::CMD_WRITE_RECORD_FLAG);
|
||||
delay_us(10);
|
||||
onewire_write_one_bit(0, 5000);
|
||||
|
||||
// write key
|
||||
onewire_master->reset();
|
||||
onewire_master->write(RW1990_1::CMD_WRITE_ROM);
|
||||
for(uint8_t i = 0; i < key->get_type_data_size(); i++) {
|
||||
// inverted key for RW1990.1
|
||||
write_byte_ds1990(~key->get_data()[i]);
|
||||
delay_us(30000);
|
||||
}
|
||||
|
||||
// lock
|
||||
onewire_master->write(RW1990_1::CMD_WRITE_RECORD_FLAG);
|
||||
onewire_write_one_bit(1);
|
||||
|
||||
FURI_CRITICAL_EXIT();
|
||||
|
||||
if(compare_key_ds1990(key)) {
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool KeyWriter::write_1990_2(iButtonKey* key) {
|
||||
bool result = false;
|
||||
|
||||
if(key->get_key_type() == iButtonKeyType::KeyDallas) {
|
||||
FURI_CRITICAL_ENTER();
|
||||
|
||||
// unlock
|
||||
onewire_master->reset();
|
||||
onewire_master->write(RW1990_2::CMD_WRITE_RECORD_FLAG);
|
||||
delay_us(10);
|
||||
onewire_write_one_bit(1, 5000);
|
||||
|
||||
// write key
|
||||
onewire_master->reset();
|
||||
onewire_master->write(RW1990_2::CMD_WRITE_ROM);
|
||||
for(uint8_t i = 0; i < key->get_type_data_size(); i++) {
|
||||
write_byte_ds1990(key->get_data()[i]);
|
||||
delay_us(30000);
|
||||
}
|
||||
|
||||
// lock
|
||||
onewire_master->write(RW1990_2::CMD_WRITE_RECORD_FLAG);
|
||||
onewire_write_one_bit(0);
|
||||
|
||||
FURI_CRITICAL_EXIT();
|
||||
|
||||
if(compare_key_ds1990(key)) {
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool KeyWriter::write_TM2004(iButtonKey* key) {
|
||||
uint8_t answer;
|
||||
bool result = true;
|
||||
|
||||
if(key->get_key_type() == iButtonKeyType::KeyDallas) {
|
||||
FURI_CRITICAL_ENTER();
|
||||
|
||||
// write rom, addr is 0x0000
|
||||
onewire_master->reset();
|
||||
onewire_master->write(TM2004::CMD_WRITE_ROM);
|
||||
onewire_master->write(0x00);
|
||||
onewire_master->write(0x00);
|
||||
|
||||
// write key
|
||||
for(uint8_t i = 0; i < key->get_type_data_size(); i++) {
|
||||
// write key byte
|
||||
onewire_master->write(key->get_data()[i]);
|
||||
answer = onewire_master->read();
|
||||
// TODO: check answer CRC
|
||||
|
||||
// pulse indicating that data is correct
|
||||
delay_us(600);
|
||||
onewire_write_one_bit(1, 50000);
|
||||
|
||||
// read writed key byte
|
||||
answer = onewire_master->read();
|
||||
|
||||
// check that writed and readed are same
|
||||
if(key->get_data()[i] != answer) {
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!compare_key_ds1990(key)) {
|
||||
result = false;
|
||||
}
|
||||
|
||||
onewire_master->reset();
|
||||
|
||||
FURI_CRITICAL_EXIT();
|
||||
} else {
|
||||
result = false;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool KeyWriter::write_TM01(iButtonKey* key) {
|
||||
/*bool result = true;
|
||||
|
||||
// TODO test and encoding
|
||||
FURI_CRITICAL_ENTER();
|
||||
|
||||
// unlock
|
||||
onewire_master->reset();
|
||||
onewire_master->write(TM01::CMD_WRITE_RECORD_FLAG);
|
||||
onewire_write_one_bit(1, 10000);
|
||||
|
||||
// write key
|
||||
onewire_master->reset();
|
||||
onewire_master->write(TM01::CMD_WRITE_ROM);
|
||||
|
||||
// TODO: key types
|
||||
//if(type == KEY_METAKOM || type == KEY_CYFRAL) {
|
||||
//} else {
|
||||
for(uint8_t i = 0; i < key->get_type_data_size(); i++) {
|
||||
write_byte_ds1990(key->get_data()[i]);
|
||||
delay_us(10000);
|
||||
}
|
||||
//}
|
||||
|
||||
// lock
|
||||
onewire_master->write(TM01::CMD_WRITE_RECORD_FLAG);
|
||||
onewire_write_one_bit(0, 10000);
|
||||
|
||||
FURI_CRITICAL_EXIT();
|
||||
|
||||
if(!compare_key_ds1990(key)) {
|
||||
result = false;
|
||||
}
|
||||
|
||||
FURI_CRITICAL_ENTER();
|
||||
|
||||
if(key->get_key_type() == iButtonKeyType::KeyMetakom ||
|
||||
key->get_key_type() == iButtonKeyType::KeyCyfral) {
|
||||
onewire_master->reset();
|
||||
if(key->get_key_type() == iButtonKeyType::KeyCyfral)
|
||||
onewire_master->write(TM01::CMD_SWITCH_TO_CYFRAL);
|
||||
else
|
||||
onewire_master->write(TM01::CMD_SWITCH_TO_METAKOM);
|
||||
onewire_write_one_bit(1);
|
||||
}
|
||||
|
||||
FURI_CRITICAL_EXIT();
|
||||
|
||||
return result;*/
|
||||
return false;
|
||||
}
|
||||
|
||||
void KeyWriter::onewire_write_one_bit(bool value, uint32_t delay) {
|
||||
onewire_master->write_bit(value);
|
||||
delay_us(delay);
|
||||
}
|
||||
|
||||
void KeyWriter::write_byte_ds1990(uint8_t data) {
|
||||
for(uint8_t n_bit = 0; n_bit < 8; n_bit++) {
|
||||
onewire_master->write_bit(data & 1);
|
||||
delay_us(5000);
|
||||
data = data >> 1;
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
#pragma once
|
||||
#include "../ibutton_key.h"
|
||||
#include <one_wire_master.h>
|
||||
|
||||
class KeyWriter {
|
||||
public:
|
||||
enum class Error : uint8_t {
|
||||
OK,
|
||||
SAME_KEY,
|
||||
NO_DETECT,
|
||||
CANNOT_WRITE,
|
||||
};
|
||||
|
||||
KeyWriter(OneWireMaster* onewire_master);
|
||||
~KeyWriter();
|
||||
|
||||
KeyWriter::Error write(iButtonKey* key);
|
||||
void start();
|
||||
void stop();
|
||||
|
||||
private:
|
||||
OneWireMaster* onewire_master;
|
||||
|
||||
KeyWriter::Error write_internal(iButtonKey* key);
|
||||
bool compare_key_ds1990(iButtonKey* key);
|
||||
|
||||
// write strategy
|
||||
bool write_1990_1(iButtonKey* key);
|
||||
bool write_1990_2(iButtonKey* key);
|
||||
bool write_TM2004(iButtonKey* key);
|
||||
bool write_TM01(iButtonKey* key);
|
||||
|
||||
void onewire_write_one_bit(bool value, uint32_t delay = 10000);
|
||||
void write_byte_ds1990(uint8_t data);
|
||||
};
|
||||
@@ -1,191 +0,0 @@
|
||||
#include "metakom_decoder.h"
|
||||
#include <furi.h>
|
||||
|
||||
bool MetakomDecoder::read(uint8_t* _data, uint8_t data_size) {
|
||||
bool result = false;
|
||||
|
||||
if(ready) {
|
||||
memcpy(_data, &key_data, 4);
|
||||
reset_state();
|
||||
result = true;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void MetakomDecoder::process_front(bool polarity, uint32_t time) {
|
||||
if(max_period == 0) {
|
||||
max_period = 230 * (SystemCoreClock / 1000000.0f);
|
||||
}
|
||||
|
||||
if(ready) return;
|
||||
|
||||
uint32_t high_time = 0;
|
||||
uint32_t low_time = 0;
|
||||
|
||||
switch(state) {
|
||||
case State::WAIT_PERIOD_SYNC:
|
||||
if(process_bit(polarity, time, &high_time, &low_time)) {
|
||||
period_sample_data[period_sample_index] = high_time + low_time;
|
||||
period_sample_index++;
|
||||
|
||||
if(period_sample_index == period_sample_count) {
|
||||
for(uint8_t i = 0; i < period_sample_count; i++) {
|
||||
period_time += period_sample_data[i];
|
||||
};
|
||||
period_time /= period_sample_count;
|
||||
|
||||
state = State::WAIT_START_BIT;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case State::WAIT_START_BIT:
|
||||
if(process_bit(polarity, time, &high_time, &low_time)) {
|
||||
tmp_counter++;
|
||||
if(high_time > period_time) {
|
||||
tmp_counter = 0;
|
||||
state = State::WAIT_START_WORD;
|
||||
}
|
||||
|
||||
if(tmp_counter > 40) {
|
||||
reset_state();
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case State::WAIT_START_WORD:
|
||||
if(process_bit(polarity, time, &high_time, &low_time)) {
|
||||
if(low_time < (period_time / 2)) {
|
||||
tmp_data = (tmp_data << 1) | 0b0;
|
||||
} else {
|
||||
tmp_data = (tmp_data << 1) | 0b1;
|
||||
}
|
||||
tmp_counter++;
|
||||
|
||||
if(tmp_counter == 3) {
|
||||
if(tmp_data == 0b010) {
|
||||
tmp_counter = 0;
|
||||
tmp_data = 0;
|
||||
state = State::READ_WORD;
|
||||
} else {
|
||||
reset_state();
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case State::READ_WORD:
|
||||
if(process_bit(polarity, time, &high_time, &low_time)) {
|
||||
if(low_time < (period_time / 2)) {
|
||||
tmp_data = (tmp_data << 1) | 0b0;
|
||||
} else {
|
||||
tmp_data = (tmp_data << 1) | 0b1;
|
||||
}
|
||||
tmp_counter++;
|
||||
|
||||
if(tmp_counter == 8) {
|
||||
if(parity_check(tmp_data)) {
|
||||
key_data = (key_data << 8) | tmp_data;
|
||||
key_data_index++;
|
||||
tmp_data = 0;
|
||||
tmp_counter = 0;
|
||||
|
||||
if(key_data_index == 4) {
|
||||
// check for stop bit
|
||||
if(high_time > period_time) {
|
||||
state = State::READ_STOP_WORD;
|
||||
} else {
|
||||
reset_state();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
reset_state();
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case State::READ_STOP_WORD:
|
||||
if(process_bit(polarity, time, &high_time, &low_time)) {
|
||||
if(low_time < (period_time / 2)) {
|
||||
tmp_data = (tmp_data << 1) | 0b0;
|
||||
} else {
|
||||
tmp_data = (tmp_data << 1) | 0b1;
|
||||
}
|
||||
tmp_counter++;
|
||||
|
||||
if(tmp_counter == 3) {
|
||||
if(tmp_data == 0b010) {
|
||||
ready = true;
|
||||
} else {
|
||||
reset_state();
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
MetakomDecoder::MetakomDecoder() {
|
||||
reset_state();
|
||||
}
|
||||
|
||||
void MetakomDecoder::reset_state() {
|
||||
ready = false;
|
||||
period_sample_index = 0;
|
||||
period_time = 0;
|
||||
|
||||
tmp_counter = 0;
|
||||
tmp_data = 0;
|
||||
|
||||
for(uint8_t i = 0; i < period_sample_count; i++) {
|
||||
period_sample_data[i] = 0;
|
||||
};
|
||||
|
||||
state = State::WAIT_PERIOD_SYNC;
|
||||
bit_state = BitState::WAIT_FRONT_LOW;
|
||||
|
||||
key_data = 0;
|
||||
key_data_index = 0;
|
||||
}
|
||||
|
||||
bool MetakomDecoder::parity_check(uint8_t data) {
|
||||
uint8_t ones_count = 0;
|
||||
bool result;
|
||||
|
||||
for(uint8_t i = 0; i < 8; i++) {
|
||||
if((data >> i) & 0b00000001) {
|
||||
ones_count++;
|
||||
}
|
||||
}
|
||||
|
||||
result = (ones_count % 2 == 0);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool MetakomDecoder::process_bit(
|
||||
bool polarity,
|
||||
uint32_t time,
|
||||
uint32_t* high_time,
|
||||
uint32_t* low_time) {
|
||||
bool result = false;
|
||||
|
||||
switch(bit_state) {
|
||||
case BitState::WAIT_FRONT_LOW:
|
||||
if(polarity == false) {
|
||||
*low_time = low_time_storage;
|
||||
*high_time = time;
|
||||
result = true;
|
||||
bit_state = BitState::WAIT_FRONT_HIGH;
|
||||
}
|
||||
break;
|
||||
case BitState::WAIT_FRONT_HIGH:
|
||||
if(polarity == true) {
|
||||
low_time_storage = time;
|
||||
bit_state = BitState::WAIT_FRONT_LOW;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include <atomic>
|
||||
|
||||
class MetakomDecoder {
|
||||
public:
|
||||
bool read(uint8_t* data, uint8_t data_size);
|
||||
void process_front(bool polarity, uint32_t time);
|
||||
|
||||
MetakomDecoder();
|
||||
|
||||
private:
|
||||
enum class BitState : uint8_t {
|
||||
WAIT_FRONT_HIGH,
|
||||
WAIT_FRONT_LOW,
|
||||
};
|
||||
|
||||
BitState bit_state;
|
||||
|
||||
enum class State : uint8_t {
|
||||
WAIT_PERIOD_SYNC,
|
||||
WAIT_START_BIT,
|
||||
WAIT_START_WORD,
|
||||
READ_WORD,
|
||||
READ_STOP_WORD,
|
||||
};
|
||||
|
||||
State state;
|
||||
|
||||
// high + low period time
|
||||
uint32_t period_time;
|
||||
uint32_t low_time_storage;
|
||||
|
||||
static const uint8_t period_sample_count = 10;
|
||||
uint8_t period_sample_index;
|
||||
uint32_t period_sample_data[period_sample_count];
|
||||
|
||||
// ready flag, key is readed and valid
|
||||
std::atomic<bool> ready;
|
||||
|
||||
// max period, 230us x clock per us
|
||||
uint32_t max_period;
|
||||
|
||||
uint8_t tmp_data;
|
||||
uint8_t tmp_counter;
|
||||
|
||||
uint32_t key_data;
|
||||
uint8_t key_data_index;
|
||||
|
||||
void reset_state();
|
||||
bool parity_check(uint8_t data);
|
||||
|
||||
bool process_bit(bool polarity, uint32_t time, uint32_t* high_time, uint32_t* low_time);
|
||||
};
|
||||
@@ -1,52 +0,0 @@
|
||||
#include "pulse_sequencer.h"
|
||||
|
||||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
|
||||
void PulseSequencer::set_periods(
|
||||
uint32_t* _periods,
|
||||
uint16_t _periods_count,
|
||||
bool _pin_start_state) {
|
||||
periods = _periods;
|
||||
periods_count = _periods_count;
|
||||
pin_start_state = _pin_start_state;
|
||||
}
|
||||
|
||||
void PulseSequencer::start() {
|
||||
period_index = 1;
|
||||
pin_state = pin_start_state;
|
||||
hal_gpio_write(&ibutton_gpio, pin_state);
|
||||
pin_state = !pin_state;
|
||||
|
||||
hal_gpio_init(&ibutton_gpio, GpioModeOutputOpenDrain, GpioPullNo, GpioSpeedVeryHigh);
|
||||
furi_hal_ibutton_emulate_start(
|
||||
periods[period_index], PulseSequencer::timer_elapsed_callback, this);
|
||||
}
|
||||
|
||||
void PulseSequencer::stop() {
|
||||
furi_hal_ibutton_emulate_stop();
|
||||
}
|
||||
|
||||
PulseSequencer::~PulseSequencer() {
|
||||
stop();
|
||||
}
|
||||
|
||||
void PulseSequencer::timer_elapsed_callback(void* context) {
|
||||
PulseSequencer* self = static_cast<PulseSequencer*>(context);
|
||||
|
||||
furi_hal_ibutton_emulate_set_next(self->periods[self->period_index]);
|
||||
|
||||
if(self->period_index == 0) {
|
||||
self->pin_state = self->pin_start_state;
|
||||
} else {
|
||||
self->pin_state = !self->pin_state;
|
||||
}
|
||||
|
||||
hal_gpio_write(&ibutton_gpio, self->pin_state);
|
||||
|
||||
self->period_index++;
|
||||
|
||||
if(self->period_index == self->periods_count) {
|
||||
self->period_index = 0;
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
|
||||
class PulseSequencer {
|
||||
public:
|
||||
void set_periods(uint32_t* periods, uint16_t periods_count, bool pin_start_state);
|
||||
void start();
|
||||
void stop();
|
||||
|
||||
~PulseSequencer();
|
||||
|
||||
private:
|
||||
uint16_t period_index;
|
||||
uint16_t periods_count;
|
||||
uint32_t* periods;
|
||||
bool pin_start_state;
|
||||
bool pin_state;
|
||||
|
||||
void init_timer(uint32_t period);
|
||||
|
||||
void reset_period_index(PulseSequencer* _this);
|
||||
|
||||
void (*callback_pointer)(void*, void*);
|
||||
|
||||
static void timer_elapsed_callback(void* comp_ctx);
|
||||
};
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "ibutton_app.h"
|
||||
#include <stdarg.h>
|
||||
#include <callback-connector.h>
|
||||
#include <furi_hal.h>
|
||||
#include <m-string.h>
|
||||
#include <toolbox/path.h>
|
||||
#include <flipper_format/flipper_format.h>
|
||||
@@ -42,7 +42,9 @@ iButtonApp::iButtonApp()
|
||||
, storage{"storage"}
|
||||
, dialogs{"dialogs"} {
|
||||
furi_hal_power_insomnia_enter();
|
||||
key_worker = new KeyWorker(&ibutton_gpio);
|
||||
key = ibutton_key_alloc();
|
||||
key_worker = ibutton_worker_alloc();
|
||||
ibutton_worker_start_thread(key_worker);
|
||||
}
|
||||
|
||||
iButtonApp::~iButtonApp() {
|
||||
@@ -50,7 +52,10 @@ iButtonApp::~iButtonApp() {
|
||||
delete it->second;
|
||||
}
|
||||
scenes.clear();
|
||||
delete key_worker;
|
||||
|
||||
ibutton_worker_stop_thread(key_worker);
|
||||
ibutton_worker_free(key_worker);
|
||||
ibutton_key_free(key);
|
||||
|
||||
furi_hal_power_insomnia_exit();
|
||||
}
|
||||
@@ -112,17 +117,12 @@ iButtonApp::Scene iButtonApp::get_previous_scene() {
|
||||
return scene;
|
||||
}
|
||||
|
||||
const GpioPin* iButtonApp::get_ibutton_pin() {
|
||||
// TODO open record
|
||||
return &ibutton_gpio;
|
||||
}
|
||||
|
||||
KeyWorker* iButtonApp::get_key_worker() {
|
||||
iButtonWorker* iButtonApp::get_key_worker() {
|
||||
return key_worker;
|
||||
}
|
||||
|
||||
iButtonKey* iButtonApp::get_key() {
|
||||
return &key;
|
||||
return key;
|
||||
}
|
||||
|
||||
char* iButtonApp::get_file_name() {
|
||||
@@ -201,10 +201,11 @@ bool iButtonApp::save_key(const char* key_name) {
|
||||
if(!delete_key()) break;
|
||||
|
||||
// Save the key
|
||||
key.set_name(key_name);
|
||||
ibutton_key_set_name(key, key_name);
|
||||
|
||||
// Set full file name, for new key
|
||||
string_printf(key_file_name, "%s/%s%s", app_folder, key.get_name(), app_extension);
|
||||
string_printf(
|
||||
key_file_name, "%s/%s%s", app_folder, ibutton_key_get_name_p(key), app_extension);
|
||||
|
||||
// Open file for write
|
||||
if(!flipper_format_file_open_always(file, string_get_cstr(key_file_name))) break;
|
||||
@@ -215,7 +216,7 @@ bool iButtonApp::save_key(const char* key_name) {
|
||||
// Write key type
|
||||
if(!flipper_format_write_comment_cstr(file, "Key type can be Cyfral, Dallas or Metakom"))
|
||||
break;
|
||||
const char* key_type = key.get_key_type_string_by_type(key.get_key_type());
|
||||
const char* key_type = ibutton_key_get_string_by_type(ibutton_key_get_type(key));
|
||||
if(!flipper_format_write_string_cstr(file, "Key type", key_type)) break;
|
||||
|
||||
// Write data
|
||||
@@ -223,7 +224,8 @@ bool iButtonApp::save_key(const char* key_name) {
|
||||
file, "Data size for Cyfral is 2, for Metakom is 4, for Dallas is 8"))
|
||||
break;
|
||||
|
||||
if(!flipper_format_write_hex(file, "Data", key.get_data(), key.get_type_data_size()))
|
||||
if(!flipper_format_write_hex(
|
||||
file, "Data", ibutton_key_get_data_p(key), ibutton_key_get_data_size(key)))
|
||||
break;
|
||||
result = true;
|
||||
|
||||
@@ -258,15 +260,15 @@ bool iButtonApp::load_key_data(string_t key_path) {
|
||||
// key type
|
||||
iButtonKeyType type;
|
||||
if(!flipper_format_read_string(file, "Key type", data)) break;
|
||||
if(!key.get_key_type_by_type_string(string_get_cstr(data), &type)) break;
|
||||
if(!ibutton_key_get_type_by_string(string_get_cstr(data), &type)) break;
|
||||
|
||||
// key data
|
||||
uint8_t key_data[IBUTTON_KEY_DATA_SIZE] = {0};
|
||||
if(!flipper_format_read_hex(file, "Data", key_data, key.get_type_data_size_by_type(type)))
|
||||
if(!flipper_format_read_hex(file, "Data", key_data, ibutton_key_get_size_by_type(type)))
|
||||
break;
|
||||
|
||||
key.set_type(type);
|
||||
key.set_data(key_data, IBUTTON_KEY_DATA_SIZE);
|
||||
ibutton_key_set_type(key, type);
|
||||
ibutton_key_set_data(key, key_data, IBUTTON_KEY_DATA_SIZE);
|
||||
|
||||
result = true;
|
||||
} while(false);
|
||||
@@ -290,7 +292,7 @@ bool iButtonApp::load_key(const char* key_name) {
|
||||
result = load_key_data(key_path);
|
||||
if(result) {
|
||||
path_extract_filename_no_ext(key_name, key_path);
|
||||
get_key()->set_name(string_get_cstr(key_path));
|
||||
ibutton_key_set_name(key, string_get_cstr(key_path));
|
||||
}
|
||||
string_clear(key_path);
|
||||
return result;
|
||||
@@ -306,7 +308,7 @@ bool iButtonApp::load_key() {
|
||||
app_extension,
|
||||
get_file_name(),
|
||||
get_file_name_size(),
|
||||
get_key()->get_name());
|
||||
ibutton_key_get_name_p(key));
|
||||
|
||||
if(res) {
|
||||
string_t key_str;
|
||||
@@ -316,7 +318,7 @@ bool iButtonApp::load_key() {
|
||||
|
||||
result = load_key_data(key_str);
|
||||
if(result) {
|
||||
get_key()->set_name(get_file_name());
|
||||
ibutton_key_set_name(key, get_file_name());
|
||||
}
|
||||
string_clear(key_str);
|
||||
}
|
||||
@@ -328,7 +330,8 @@ bool iButtonApp::delete_key() {
|
||||
string_t file_name;
|
||||
bool result = false;
|
||||
|
||||
string_init_printf(file_name, "%s/%s%s", app_folder, get_key()->get_name(), app_extension);
|
||||
string_init_printf(
|
||||
file_name, "%s/%s%s", app_folder, ibutton_key_get_name_p(key), app_extension);
|
||||
result = storage_simply_remove(storage, string_get_cstr(file_name));
|
||||
string_clear(file_name);
|
||||
|
||||
|
||||
@@ -22,17 +22,10 @@
|
||||
#include "scene/ibutton_scene_select_key.h"
|
||||
#include "scene/ibutton_scene_add_type.h"
|
||||
#include "scene/ibutton_scene_add_value.h"
|
||||
|
||||
#include "helpers/key_worker.h"
|
||||
|
||||
#include "one_wire_master.h"
|
||||
#include "maxim_crc.h"
|
||||
#include "ibutton_key.h"
|
||||
|
||||
#include <one_wire/ibutton/ibutton_worker.h>
|
||||
#include <notification/notification_messages.h>
|
||||
#include <storage/storage.h>
|
||||
#include <dialogs/dialogs.h>
|
||||
|
||||
#include <record_controller.hpp>
|
||||
|
||||
class iButtonApp {
|
||||
@@ -75,7 +68,7 @@ public:
|
||||
Scene get_previous_scene();
|
||||
|
||||
const GpioPin* get_ibutton_pin();
|
||||
KeyWorker* get_key_worker();
|
||||
iButtonWorker* get_key_worker();
|
||||
iButtonKey* get_key();
|
||||
|
||||
void notify_green_blink();
|
||||
@@ -127,9 +120,8 @@ private:
|
||||
{Scene::SceneAddValue, new iButtonSceneAddValue()},
|
||||
};
|
||||
|
||||
KeyWorker* key_worker;
|
||||
|
||||
iButtonKey key;
|
||||
iButtonWorker* key_worker;
|
||||
iButtonKey* key;
|
||||
|
||||
RecordController<NotificationApp> notification;
|
||||
RecordController<Storage> storage;
|
||||
|
||||
308
applications/ibutton/ibutton_cli.c
Normal file
308
applications/ibutton/ibutton_cli.c
Normal file
@@ -0,0 +1,308 @@
|
||||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
#include <stdarg.h>
|
||||
#include <cli/cli.h>
|
||||
#include <lib/toolbox/args.h>
|
||||
#include <one_wire/ibutton/ibutton_worker.h>
|
||||
#include <one_wire/one_wire_host.h>
|
||||
|
||||
void ibutton_cli(Cli* cli, string_t args, void* context);
|
||||
void onewire_cli(Cli* cli, string_t args, void* context);
|
||||
|
||||
// app cli function
|
||||
void ibutton_on_system_start() {
|
||||
#ifdef SRV_CLI
|
||||
Cli* cli = furi_record_open("cli");
|
||||
cli_add_command(cli, "ikey", CliCommandFlagDefault, ibutton_cli, cli);
|
||||
cli_add_command(cli, "onewire", CliCommandFlagDefault, onewire_cli, cli);
|
||||
furi_record_close("cli");
|
||||
#endif
|
||||
}
|
||||
|
||||
void ibutton_cli_print_usage() {
|
||||
printf("Usage:\r\n");
|
||||
printf("ikey read\r\n");
|
||||
printf("ikey emulate <key_type> <key_data>\r\n");
|
||||
printf("ikey write Dallas <key_data>\r\n");
|
||||
printf("\t<key_type> choose from:\r\n");
|
||||
printf("\tDallas (8 bytes key_data)\r\n");
|
||||
printf("\tCyfral (2 bytes key_data)\r\n");
|
||||
printf("\tMetakom (4 bytes key_data)\r\n");
|
||||
printf("\t<key_data> are hex-formatted\r\n");
|
||||
};
|
||||
|
||||
bool ibutton_cli_get_key_type(string_t data, iButtonKeyType* type) {
|
||||
bool result = false;
|
||||
|
||||
if(string_cmp_str(data, "Dallas") == 0 || string_cmp_str(data, "dallas") == 0) {
|
||||
result = true;
|
||||
*type = iButtonKeyDS1990;
|
||||
} else if(string_cmp_str(data, "Cyfral") == 0 || string_cmp_str(data, "cyfral") == 0) {
|
||||
result = true;
|
||||
*type = iButtonKeyCyfral;
|
||||
} else if(string_cmp_str(data, "Metakom") == 0 || string_cmp_str(data, "metakom") == 0) {
|
||||
result = true;
|
||||
*type = iButtonKeyMetakom;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void ibutton_cli_print_key_data(iButtonKey* key) {
|
||||
const uint8_t* key_data = ibutton_key_get_data_p(key);
|
||||
iButtonKeyType type = ibutton_key_get_type(key);
|
||||
|
||||
printf("%s ", ibutton_key_get_string_by_type(type));
|
||||
for(size_t i = 0; i < ibutton_key_get_size_by_type(type); i++) {
|
||||
printf("%02X", key_data[i]);
|
||||
}
|
||||
|
||||
printf("\r\n");
|
||||
}
|
||||
|
||||
#define EVENT_FLAG_IBUTTON_COMPLETE (1 << 0)
|
||||
|
||||
static void ibutton_cli_worker_read_cb(void* context) {
|
||||
osEventFlagsId_t event = context;
|
||||
osEventFlagsSet(event, EVENT_FLAG_IBUTTON_COMPLETE);
|
||||
}
|
||||
|
||||
void ibutton_cli_read(Cli* cli) {
|
||||
iButtonKey* key = ibutton_key_alloc();
|
||||
iButtonWorker* worker = ibutton_worker_alloc();
|
||||
osEventFlagsId_t event = osEventFlagsNew(NULL);
|
||||
|
||||
ibutton_worker_start_thread(worker);
|
||||
ibutton_worker_read_set_callback(worker, ibutton_cli_worker_read_cb, event);
|
||||
|
||||
ibutton_worker_read_start(worker, key);
|
||||
while(true) {
|
||||
uint32_t flags = osEventFlagsWait(event, EVENT_FLAG_IBUTTON_COMPLETE, osFlagsWaitAny, 100);
|
||||
|
||||
if(flags & EVENT_FLAG_IBUTTON_COMPLETE) {
|
||||
ibutton_cli_print_key_data(key);
|
||||
|
||||
if(ibutton_key_get_type(key) == iButtonKeyDS1990) {
|
||||
if(!ibutton_key_dallas_crc_is_valid(key)) {
|
||||
printf("Warning: invalid CRC\r\n");
|
||||
}
|
||||
|
||||
if(!ibutton_key_dallas_is_1990_key(key)) {
|
||||
printf("Warning: not a key\r\n");
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if(cli_cmd_interrupt_received(cli)) break;
|
||||
}
|
||||
ibutton_worker_stop(worker);
|
||||
|
||||
ibutton_worker_stop_thread(worker);
|
||||
ibutton_worker_free(worker);
|
||||
ibutton_key_free(key);
|
||||
|
||||
osEventFlagsDelete(event);
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
osEventFlagsId_t event;
|
||||
iButtonWorkerWriteResult result;
|
||||
} iButtonWriteContext;
|
||||
|
||||
static void ibutton_cli_worker_write_cb(void* context, iButtonWorkerWriteResult result) {
|
||||
iButtonWriteContext* write_context = (iButtonWriteContext*)context;
|
||||
write_context->result = result;
|
||||
osEventFlagsSet(write_context->event, EVENT_FLAG_IBUTTON_COMPLETE);
|
||||
}
|
||||
|
||||
void ibutton_cli_write(Cli* cli, string_t args) {
|
||||
iButtonKey* key = ibutton_key_alloc();
|
||||
iButtonWorker* worker = ibutton_worker_alloc();
|
||||
iButtonKeyType type;
|
||||
iButtonWriteContext write_context;
|
||||
uint8_t key_data[IBUTTON_KEY_DATA_SIZE];
|
||||
string_t data;
|
||||
|
||||
write_context.event = osEventFlagsNew(NULL);
|
||||
|
||||
string_init(data);
|
||||
ibutton_worker_start_thread(worker);
|
||||
ibutton_worker_write_set_callback(worker, ibutton_cli_worker_write_cb, &write_context);
|
||||
|
||||
do {
|
||||
if(!args_read_string_and_trim(args, data)) {
|
||||
ibutton_cli_print_usage();
|
||||
break;
|
||||
}
|
||||
|
||||
if(!ibutton_cli_get_key_type(data, &type)) {
|
||||
ibutton_cli_print_usage();
|
||||
break;
|
||||
}
|
||||
|
||||
if(type != iButtonKeyDS1990) {
|
||||
ibutton_cli_print_usage();
|
||||
break;
|
||||
}
|
||||
|
||||
if(!args_read_hex_bytes(args, key_data, ibutton_key_get_size_by_type(type))) {
|
||||
ibutton_cli_print_usage();
|
||||
break;
|
||||
}
|
||||
|
||||
ibutton_key_set_type(key, type);
|
||||
ibutton_key_set_data(key, key_data, ibutton_key_get_size_by_type(type));
|
||||
|
||||
printf("Writing key ");
|
||||
ibutton_cli_print_key_data(key);
|
||||
printf("Press Ctrl+C to abort\r\n");
|
||||
|
||||
ibutton_worker_write_start(worker, key);
|
||||
while(true) {
|
||||
uint32_t flags = osEventFlagsWait(
|
||||
write_context.event, EVENT_FLAG_IBUTTON_COMPLETE, osFlagsWaitAny, 100);
|
||||
|
||||
if(flags & EVENT_FLAG_IBUTTON_COMPLETE) {
|
||||
if(write_context.result == iButtonWorkerWriteSameKey ||
|
||||
write_context.result == iButtonWorkerWriteOK) {
|
||||
printf("Write success\r\n");
|
||||
break;
|
||||
} else if(write_context.result == iButtonWorkerWriteCannotWrite) {
|
||||
printf("Write fail\r\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(cli_cmd_interrupt_received(cli)) break;
|
||||
}
|
||||
ibutton_worker_stop(worker);
|
||||
} while(false);
|
||||
|
||||
string_clear(data);
|
||||
ibutton_worker_stop_thread(worker);
|
||||
ibutton_worker_free(worker);
|
||||
ibutton_key_free(key);
|
||||
|
||||
osEventFlagsDelete(write_context.event);
|
||||
};
|
||||
|
||||
void ibutton_cli_emulate(Cli* cli, string_t args) {
|
||||
iButtonKey* key = ibutton_key_alloc();
|
||||
iButtonWorker* worker = ibutton_worker_alloc();
|
||||
iButtonKeyType type;
|
||||
uint8_t key_data[IBUTTON_KEY_DATA_SIZE];
|
||||
string_t data;
|
||||
|
||||
string_init(data);
|
||||
ibutton_worker_start_thread(worker);
|
||||
|
||||
do {
|
||||
if(!args_read_string_and_trim(args, data)) {
|
||||
ibutton_cli_print_usage();
|
||||
break;
|
||||
}
|
||||
|
||||
if(!ibutton_cli_get_key_type(data, &type)) {
|
||||
ibutton_cli_print_usage();
|
||||
break;
|
||||
}
|
||||
|
||||
if(!args_read_hex_bytes(args, key_data, ibutton_key_get_size_by_type(type))) {
|
||||
ibutton_cli_print_usage();
|
||||
break;
|
||||
}
|
||||
|
||||
ibutton_key_set_type(key, type);
|
||||
ibutton_key_set_data(key, key_data, ibutton_key_get_size_by_type(type));
|
||||
|
||||
printf("Emulating key ");
|
||||
ibutton_cli_print_key_data(key);
|
||||
printf("Press Ctrl+C to abort\r\n");
|
||||
|
||||
ibutton_worker_emulate_start(worker, key);
|
||||
while(!cli_cmd_interrupt_received(cli)) {
|
||||
delay(100);
|
||||
};
|
||||
ibutton_worker_stop(worker);
|
||||
} while(false);
|
||||
|
||||
string_clear(data);
|
||||
ibutton_worker_stop_thread(worker);
|
||||
ibutton_worker_free(worker);
|
||||
ibutton_key_free(key);
|
||||
};
|
||||
|
||||
void ibutton_cli(Cli* cli, string_t args, void* context) {
|
||||
string_t cmd;
|
||||
string_init(cmd);
|
||||
|
||||
if(!args_read_string_and_trim(args, cmd)) {
|
||||
string_clear(cmd);
|
||||
ibutton_cli_print_usage();
|
||||
return;
|
||||
}
|
||||
|
||||
if(string_cmp_str(cmd, "read") == 0) {
|
||||
ibutton_cli_read(cli);
|
||||
} else if(string_cmp_str(cmd, "write") == 0) {
|
||||
ibutton_cli_write(cli, args);
|
||||
} else if(string_cmp_str(cmd, "emulate") == 0) {
|
||||
ibutton_cli_emulate(cli, args);
|
||||
} else {
|
||||
ibutton_cli_print_usage();
|
||||
}
|
||||
|
||||
string_clear(cmd);
|
||||
}
|
||||
|
||||
void onewire_cli_print_usage() {
|
||||
printf("Usage:\r\n");
|
||||
printf("onewire search\r\n");
|
||||
};
|
||||
|
||||
void onewire_cli_search(Cli* cli) {
|
||||
OneWireHost* onewire = onewire_host_alloc();
|
||||
uint8_t address[8];
|
||||
bool done = false;
|
||||
|
||||
printf("Search started\r\n");
|
||||
|
||||
onewire_host_start(onewire);
|
||||
furi_hal_power_enable_otg();
|
||||
|
||||
while(!done) {
|
||||
if(onewire_host_search(onewire, address, NORMAL_SEARCH) != 1) {
|
||||
printf("Search finished\r\n");
|
||||
onewire_host_reset_search(onewire);
|
||||
done = true;
|
||||
} else {
|
||||
printf("Found: ");
|
||||
for(uint8_t i = 0; i < 8; i++) {
|
||||
printf("%02X", address[i]);
|
||||
}
|
||||
printf("\r\n");
|
||||
}
|
||||
delay(100);
|
||||
}
|
||||
|
||||
furi_hal_power_disable_otg();
|
||||
onewire_host_free(onewire);
|
||||
}
|
||||
|
||||
void onewire_cli(Cli* cli, string_t args, void* context) {
|
||||
string_t cmd;
|
||||
string_init(cmd);
|
||||
|
||||
if(!args_read_string_and_trim(args, cmd)) {
|
||||
string_clear(cmd);
|
||||
onewire_cli_print_usage();
|
||||
return;
|
||||
}
|
||||
|
||||
if(string_cmp_str(cmd, "search") == 0) {
|
||||
onewire_cli_search(cli);
|
||||
}
|
||||
|
||||
string_clear(cmd);
|
||||
}
|
||||
@@ -1,292 +0,0 @@
|
||||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
#include <stdarg.h>
|
||||
#include <cli/cli.h>
|
||||
#include <lib/toolbox/args.h>
|
||||
|
||||
#include "helpers/key_info.h"
|
||||
#include "helpers/key_worker.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
void ibutton_cli(Cli* cli, string_t args, void* context);
|
||||
void onewire_cli(Cli* cli, string_t args, void* context);
|
||||
|
||||
// app cli function
|
||||
extern "C" void ibutton_on_system_start() {
|
||||
#ifdef SRV_CLI
|
||||
Cli* cli = static_cast<Cli*>(furi_record_open("cli"));
|
||||
cli_add_command(cli, "ikey", CliCommandFlagDefault, ibutton_cli, cli);
|
||||
cli_add_command(cli, "onewire", CliCommandFlagDefault, onewire_cli, cli);
|
||||
furi_record_close("cli");
|
||||
#endif
|
||||
}
|
||||
|
||||
void ibutton_cli_print_usage() {
|
||||
printf("Usage:\r\n");
|
||||
printf("ikey read\r\n");
|
||||
printf("ikey <write | emulate> <key_type> <key_data>\r\n");
|
||||
printf("\t<key_type> choose from:\r\n");
|
||||
printf("\tDallas (8 bytes key_data)\r\n");
|
||||
printf("\tCyfral (2 bytes key_data)\r\n");
|
||||
printf("\tMetakom (4 bytes key_data)\r\n");
|
||||
printf("\t<key_data> are hex-formatted\r\n");
|
||||
};
|
||||
|
||||
bool ibutton_cli_get_key_type(string_t data, iButtonKeyType* type) {
|
||||
bool result = false;
|
||||
|
||||
if(string_cmp_str(data, "Dallas") == 0 || string_cmp_str(data, "dallas") == 0) {
|
||||
result = true;
|
||||
*type = iButtonKeyType::KeyDallas;
|
||||
} else if(string_cmp_str(data, "Cyfral") == 0 || string_cmp_str(data, "cyfral") == 0) {
|
||||
result = true;
|
||||
*type = iButtonKeyType::KeyCyfral;
|
||||
} else if(string_cmp_str(data, "Metakom") == 0 || string_cmp_str(data, "metakom") == 0) {
|
||||
result = true;
|
||||
*type = iButtonKeyType::KeyMetakom;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void ibutton_cli_print_key_data(iButtonKey* key) {
|
||||
uint8_t* key_data = key->get_data();
|
||||
switch(key->get_key_type()) {
|
||||
case iButtonKeyType::KeyDallas:
|
||||
printf(
|
||||
"Dallas %02X%02X%02X%02X%02X%02X%02X%02X\r\n",
|
||||
key_data[0],
|
||||
key_data[1],
|
||||
key_data[2],
|
||||
key_data[3],
|
||||
key_data[4],
|
||||
key_data[5],
|
||||
key_data[6],
|
||||
key_data[7]);
|
||||
break;
|
||||
case iButtonKeyType::KeyCyfral:
|
||||
printf("Cyfral %02X%02X\r\n", key_data[0], key_data[1]);
|
||||
break;
|
||||
case iButtonKeyType::KeyMetakom:
|
||||
printf("Metakom %02X%02X%02X%02X\r\n", key_data[0], key_data[1], key_data[2], key_data[3]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void ibutton_cli_read(Cli* cli) {
|
||||
iButtonKey key;
|
||||
std::unique_ptr<KeyWorker> worker(new KeyWorker(&ibutton_gpio));
|
||||
|
||||
bool exit = false;
|
||||
|
||||
worker->start_read();
|
||||
printf("Reading iButton...\r\nPress Ctrl+C to abort\r\n");
|
||||
|
||||
while(!exit) {
|
||||
exit = cli_cmd_interrupt_received(cli);
|
||||
|
||||
switch(worker->read(&key)) {
|
||||
case KeyReader::Error::EMPTY:
|
||||
break;
|
||||
case KeyReader::Error::CRC_ERROR:
|
||||
ibutton_cli_print_key_data(&key);
|
||||
printf("Warning: invalid CRC\r\n");
|
||||
exit = true;
|
||||
break;
|
||||
case KeyReader::Error::OK:
|
||||
ibutton_cli_print_key_data(&key);
|
||||
exit = true;
|
||||
break;
|
||||
case KeyReader::Error::NOT_ARE_KEY:
|
||||
ibutton_cli_print_key_data(&key);
|
||||
printf("Warning: not a key\r\n");
|
||||
exit = true;
|
||||
break;
|
||||
}
|
||||
|
||||
delay(100);
|
||||
}
|
||||
|
||||
worker->stop_read();
|
||||
};
|
||||
|
||||
void ibutton_cli_write(Cli* cli, string_t args) {
|
||||
iButtonKey key;
|
||||
iButtonKeyType type;
|
||||
std::unique_ptr<KeyWorker> worker(new KeyWorker(&ibutton_gpio));
|
||||
|
||||
bool exit = false;
|
||||
string_t data;
|
||||
string_init(data);
|
||||
|
||||
if(!args_read_string_and_trim(args, data)) {
|
||||
ibutton_cli_print_usage();
|
||||
string_clear(data);
|
||||
return;
|
||||
}
|
||||
|
||||
if(!ibutton_cli_get_key_type(data, &type)) {
|
||||
ibutton_cli_print_usage();
|
||||
string_clear(data);
|
||||
return;
|
||||
}
|
||||
|
||||
key.set_type(type);
|
||||
|
||||
if(!args_read_hex_bytes(args, key.get_data(), key.get_type_data_size())) {
|
||||
ibutton_cli_print_usage();
|
||||
string_clear(data);
|
||||
return;
|
||||
}
|
||||
|
||||
printf("Writing key ");
|
||||
ibutton_cli_print_key_data(&key);
|
||||
printf("Press Ctrl+C to abort\r\n");
|
||||
|
||||
worker->start_write();
|
||||
|
||||
while(!exit) {
|
||||
exit = cli_cmd_interrupt_received(cli);
|
||||
|
||||
KeyWriter::Error result = worker->write(&key);
|
||||
|
||||
switch(result) {
|
||||
case KeyWriter::Error::SAME_KEY:
|
||||
case KeyWriter::Error::OK:
|
||||
printf("Write success\r\n");
|
||||
exit = true;
|
||||
break;
|
||||
case KeyWriter::Error::NO_DETECT:
|
||||
break;
|
||||
case KeyWriter::Error::CANNOT_WRITE:
|
||||
printf("Write fail\r\n");
|
||||
exit = true;
|
||||
break;
|
||||
}
|
||||
|
||||
delay(100);
|
||||
};
|
||||
|
||||
worker->stop_write();
|
||||
|
||||
string_clear(data);
|
||||
};
|
||||
|
||||
void ibutton_cli_emulate(Cli* cli, string_t args) {
|
||||
iButtonKey key;
|
||||
iButtonKeyType type;
|
||||
std::unique_ptr<KeyWorker> worker(new KeyWorker(&ibutton_gpio));
|
||||
bool exit = false;
|
||||
string_t data;
|
||||
string_init(data);
|
||||
|
||||
if(!args_read_string_and_trim(args, data)) {
|
||||
ibutton_cli_print_usage();
|
||||
string_clear(data);
|
||||
return;
|
||||
}
|
||||
|
||||
if(!ibutton_cli_get_key_type(data, &type)) {
|
||||
ibutton_cli_print_usage();
|
||||
string_clear(data);
|
||||
return;
|
||||
}
|
||||
|
||||
key.set_type(type);
|
||||
|
||||
if(!args_read_hex_bytes(args, key.get_data(), key.get_type_data_size())) {
|
||||
ibutton_cli_print_usage();
|
||||
string_clear(data);
|
||||
return;
|
||||
}
|
||||
|
||||
printf("Emulating key ");
|
||||
ibutton_cli_print_key_data(&key);
|
||||
printf("Press Ctrl+C to abort\r\n");
|
||||
|
||||
worker->start_emulate(&key);
|
||||
|
||||
while(!exit) {
|
||||
exit = cli_cmd_interrupt_received(cli);
|
||||
delay(100);
|
||||
};
|
||||
|
||||
worker->stop_emulate();
|
||||
|
||||
string_clear(data);
|
||||
};
|
||||
|
||||
void ibutton_cli(Cli* cli, string_t args, void* context) {
|
||||
string_t cmd;
|
||||
string_init(cmd);
|
||||
|
||||
if(!args_read_string_and_trim(args, cmd)) {
|
||||
string_clear(cmd);
|
||||
ibutton_cli_print_usage();
|
||||
return;
|
||||
}
|
||||
|
||||
if(string_cmp_str(cmd, "read") == 0) {
|
||||
ibutton_cli_read(cli);
|
||||
} else if(string_cmp_str(cmd, "write") == 0) {
|
||||
ibutton_cli_write(cli, args);
|
||||
} else if(string_cmp_str(cmd, "emulate") == 0) {
|
||||
ibutton_cli_emulate(cli, args);
|
||||
} else {
|
||||
ibutton_cli_print_usage();
|
||||
}
|
||||
|
||||
string_clear(cmd);
|
||||
}
|
||||
|
||||
void onewire_cli_print_usage() {
|
||||
printf("Usage:\r\n");
|
||||
printf("onewire search\r\n");
|
||||
};
|
||||
|
||||
void onewire_cli_search(Cli* cli) {
|
||||
OneWireMaster onewire(&ibutton_gpio);
|
||||
uint8_t address[8];
|
||||
bool done = false;
|
||||
|
||||
printf("Search started\r\n");
|
||||
|
||||
onewire.start();
|
||||
furi_hal_power_enable_otg();
|
||||
|
||||
while(!done) {
|
||||
if(onewire.search(address, true) != 1) {
|
||||
printf("Search finished\r\n");
|
||||
onewire.reset_search();
|
||||
done = true;
|
||||
} else {
|
||||
printf("Found: ");
|
||||
for(uint8_t i = 0; i < 8; i++) {
|
||||
printf("%02X", address[i]);
|
||||
}
|
||||
printf("\r\n");
|
||||
}
|
||||
delay(100);
|
||||
}
|
||||
|
||||
furi_hal_power_disable_otg();
|
||||
onewire.stop();
|
||||
}
|
||||
|
||||
void onewire_cli(Cli* cli, string_t args, void* context) {
|
||||
string_t cmd;
|
||||
string_init(cmd);
|
||||
|
||||
if(!args_read_string_and_trim(args, cmd)) {
|
||||
string_clear(cmd);
|
||||
onewire_cli_print_usage();
|
||||
return;
|
||||
}
|
||||
|
||||
if(string_cmp_str(cmd, "search") == 0) {
|
||||
onewire_cli_search(cli);
|
||||
}
|
||||
|
||||
string_clear(cmd);
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <stdint.h>
|
||||
#include <gui/modules/dialog_ex.h>
|
||||
#include <gui/modules/widget.h>
|
||||
#include <one_wire/ibutton/ibutton_worker.h>
|
||||
|
||||
class iButtonApp;
|
||||
|
||||
@@ -16,6 +17,9 @@ public:
|
||||
EventTypeTextEditResult,
|
||||
EventTypeByteEditResult,
|
||||
EventTypeWidgetButtonResult,
|
||||
EventTypeWorkerEmulated,
|
||||
EventTypeWorkerRead,
|
||||
EventTypeWorkerWrite,
|
||||
};
|
||||
|
||||
// payload
|
||||
@@ -23,6 +27,7 @@ public:
|
||||
uint32_t menu_index;
|
||||
DialogExResult dialog_result;
|
||||
GuiButtonType widget_button_result;
|
||||
iButtonWorkerWriteResult worker_write_result;
|
||||
} payload;
|
||||
|
||||
// event type
|
||||
|
||||
@@ -1,95 +0,0 @@
|
||||
#include "ibutton_key.h"
|
||||
#include <furi.h>
|
||||
|
||||
uint8_t iButtonKey::get_size() {
|
||||
return IBUTTON_KEY_DATA_SIZE;
|
||||
}
|
||||
|
||||
void iButtonKey::set_data(uint8_t* _data, uint8_t _data_count) {
|
||||
furi_check(_data_count > 0);
|
||||
furi_check(_data_count <= get_size());
|
||||
|
||||
memset(data, 0, get_size());
|
||||
memcpy(data, _data, _data_count);
|
||||
}
|
||||
|
||||
void iButtonKey::clear_data() {
|
||||
memset(data, 0, get_size());
|
||||
}
|
||||
|
||||
uint8_t* iButtonKey::get_data() {
|
||||
return data;
|
||||
}
|
||||
|
||||
uint8_t iButtonKey::get_type_data_size() {
|
||||
return get_type_data_size_by_type(type);
|
||||
}
|
||||
|
||||
void iButtonKey::set_name(const char* _name) {
|
||||
strlcpy(name, _name, IBUTTON_KEY_NAME_SIZE);
|
||||
}
|
||||
|
||||
char* iButtonKey::get_name() {
|
||||
return name;
|
||||
}
|
||||
|
||||
void iButtonKey::set_type(iButtonKeyType _key_type) {
|
||||
type = _key_type;
|
||||
}
|
||||
|
||||
iButtonKeyType iButtonKey::get_key_type() {
|
||||
return type;
|
||||
}
|
||||
|
||||
const char* iButtonKey::get_key_type_string_by_type(iButtonKeyType key_type) {
|
||||
switch(key_type) {
|
||||
case iButtonKeyType::KeyCyfral:
|
||||
return "Cyfral";
|
||||
break;
|
||||
case iButtonKeyType::KeyMetakom:
|
||||
return "Metakom";
|
||||
break;
|
||||
case iButtonKeyType::KeyDallas:
|
||||
return "Dallas";
|
||||
break;
|
||||
default:
|
||||
furi_crash("Invalid iButton type");
|
||||
return "";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool iButtonKey::get_key_type_by_type_string(const char* type_string, iButtonKeyType* key_type) {
|
||||
if(strcmp(type_string, get_key_type_string_by_type(iButtonKeyType::KeyCyfral)) == 0) {
|
||||
*key_type = iButtonKeyType::KeyCyfral;
|
||||
} else if(strcmp(type_string, get_key_type_string_by_type(iButtonKeyType::KeyMetakom)) == 0) {
|
||||
*key_type = iButtonKeyType::KeyMetakom;
|
||||
} else if(strcmp(type_string, get_key_type_string_by_type(iButtonKeyType::KeyDallas)) == 0) {
|
||||
*key_type = iButtonKeyType::KeyDallas;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
uint8_t iButtonKey::get_type_data_size_by_type(iButtonKeyType key_type) {
|
||||
uint8_t size = 0;
|
||||
|
||||
switch(key_type) {
|
||||
case iButtonKeyType::KeyCyfral:
|
||||
size = 2;
|
||||
break;
|
||||
case iButtonKeyType::KeyMetakom:
|
||||
size = 4;
|
||||
break;
|
||||
case iButtonKeyType::KeyDallas:
|
||||
size = 8;
|
||||
break;
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
iButtonKey::iButtonKey() {
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include "helpers/key_info.h"
|
||||
|
||||
class iButtonKey {
|
||||
public:
|
||||
uint8_t get_size();
|
||||
|
||||
void set_data(uint8_t* data, uint8_t data_count);
|
||||
void clear_data();
|
||||
uint8_t* get_data();
|
||||
uint8_t get_type_data_size();
|
||||
|
||||
void set_name(const char* name);
|
||||
char* get_name();
|
||||
|
||||
void set_type(iButtonKeyType key_type);
|
||||
iButtonKeyType get_key_type();
|
||||
|
||||
const char* get_key_type_string_by_type(iButtonKeyType key_type);
|
||||
bool get_key_type_by_type_string(const char* type_string, iButtonKeyType* key_type);
|
||||
uint8_t get_type_data_size_by_type(iButtonKeyType key_type);
|
||||
|
||||
iButtonKey();
|
||||
|
||||
private:
|
||||
uint8_t data[IBUTTON_KEY_DATA_SIZE] = {0, 0, 0, 0, 0, 0, 0, 0};
|
||||
char name[IBUTTON_KEY_NAME_SIZE] = {0};
|
||||
|
||||
iButtonKeyType type = iButtonKeyType::KeyDallas;
|
||||
};
|
||||
@@ -1,7 +1,5 @@
|
||||
#include "ibutton_scene_add_type.h"
|
||||
#include "../ibutton_app.h"
|
||||
#include "../ibutton_view_manager.h"
|
||||
#include "../ibutton_event.h"
|
||||
#include <callback-connector.h>
|
||||
|
||||
typedef enum {
|
||||
@@ -10,14 +8,23 @@ typedef enum {
|
||||
SubmenuIndexMetakom,
|
||||
} SubmenuIndex;
|
||||
|
||||
static void submenu_callback(void* context, uint32_t index) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
|
||||
event.type = iButtonEvent::Type::EventTypeMenuSelected;
|
||||
event.payload.menu_index = index;
|
||||
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
||||
|
||||
void iButtonSceneAddType::on_enter(iButtonApp* app) {
|
||||
iButtonAppViewManager* view_manager = app->get_view_manager();
|
||||
Submenu* submenu = view_manager->get_submenu();
|
||||
auto callback = cbc::obtain_connector(this, &iButtonSceneAddType::submenu_callback);
|
||||
|
||||
submenu_add_item(submenu, "Cyfral", SubmenuIndexCyfral, callback, app);
|
||||
submenu_add_item(submenu, "Dallas", SubmenuIndexDallas, callback, app);
|
||||
submenu_add_item(submenu, "Metakom", SubmenuIndexMetakom, callback, app);
|
||||
submenu_add_item(submenu, "Cyfral", SubmenuIndexCyfral, submenu_callback, app);
|
||||
submenu_add_item(submenu, "Dallas", SubmenuIndexDallas, submenu_callback, app);
|
||||
submenu_add_item(submenu, "Metakom", SubmenuIndexMetakom, submenu_callback, app);
|
||||
submenu_set_selected_item(submenu, submenu_item_selected);
|
||||
|
||||
view_manager->switch_to(iButtonAppViewManager::Type::iButtonAppViewSubmenu);
|
||||
@@ -28,19 +35,21 @@ bool iButtonSceneAddType::on_event(iButtonApp* app, iButtonEvent* event) {
|
||||
|
||||
if(event->type == iButtonEvent::Type::EventTypeMenuSelected) {
|
||||
submenu_item_selected = event->payload.menu_index;
|
||||
iButtonKey* key = app->get_key();
|
||||
|
||||
switch(event->payload.menu_index) {
|
||||
case SubmenuIndexCyfral:
|
||||
app->get_key()->set_type(iButtonKeyType::KeyCyfral);
|
||||
ibutton_key_set_type(key, iButtonKeyCyfral);
|
||||
break;
|
||||
case SubmenuIndexDallas:
|
||||
app->get_key()->set_type(iButtonKeyType::KeyDallas);
|
||||
ibutton_key_set_type(key, iButtonKeyDS1990);
|
||||
break;
|
||||
case SubmenuIndexMetakom:
|
||||
app->get_key()->set_type(iButtonKeyType::KeyMetakom);
|
||||
ibutton_key_set_type(key, iButtonKeyMetakom);
|
||||
break;
|
||||
}
|
||||
app->get_key()->set_name("");
|
||||
app->get_key()->clear_data();
|
||||
ibutton_key_set_name(key, "");
|
||||
ibutton_key_clear_data(key);
|
||||
app->switch_to_next_scene(iButtonApp::Scene::SceneAddValue);
|
||||
consumed = true;
|
||||
}
|
||||
@@ -54,13 +63,3 @@ void iButtonSceneAddType::on_exit(iButtonApp* app) {
|
||||
|
||||
submenu_reset(submenu);
|
||||
}
|
||||
|
||||
void iButtonSceneAddType::submenu_callback(void* context, uint32_t index) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
|
||||
event.type = iButtonEvent::Type::EventTypeMenuSelected;
|
||||
event.payload.menu_index = index;
|
||||
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
||||
|
||||
@@ -8,6 +8,5 @@ public:
|
||||
void on_exit(iButtonApp* app) final;
|
||||
|
||||
private:
|
||||
void submenu_callback(void* context, uint32_t index);
|
||||
uint32_t submenu_item_selected = 0;
|
||||
};
|
||||
@@ -1,17 +1,30 @@
|
||||
#include "ibutton_scene_add_value.h"
|
||||
#include "../ibutton_app.h"
|
||||
#include "../ibutton_view_manager.h"
|
||||
#include "../ibutton_event.h"
|
||||
#include <callback-connector.h>
|
||||
#include <dolphin/dolphin.h>
|
||||
|
||||
static void byte_input_callback(void* context) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
|
||||
event.type = iButtonEvent::Type::EventTypeByteEditResult;
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
||||
|
||||
void iButtonSceneAddValue::on_enter(iButtonApp* app) {
|
||||
iButtonAppViewManager* view_manager = app->get_view_manager();
|
||||
ByteInput* byte_input = view_manager->get_byte_input();
|
||||
auto callback = cbc::obtain_connector(this, &iButtonSceneAddValue::byte_input_callback);
|
||||
memcpy(this->new_key_data, app->get_key()->get_data(), app->get_key()->get_type_data_size());
|
||||
iButtonKey* key = app->get_key();
|
||||
|
||||
memcpy(this->new_key_data, ibutton_key_get_data_p(key), ibutton_key_get_data_size(key));
|
||||
|
||||
byte_input_set_result_callback(
|
||||
byte_input, callback, NULL, app, this->new_key_data, app->get_key()->get_type_data_size());
|
||||
byte_input,
|
||||
byte_input_callback,
|
||||
NULL,
|
||||
app,
|
||||
this->new_key_data,
|
||||
ibutton_key_get_data_size(key));
|
||||
|
||||
byte_input_set_header_text(byte_input, "Enter the key");
|
||||
|
||||
view_manager->switch_to(iButtonAppViewManager::Type::iButtonAppViewByteInput);
|
||||
@@ -21,6 +34,7 @@ bool iButtonSceneAddValue::on_event(iButtonApp* app, iButtonEvent* event) {
|
||||
bool consumed = false;
|
||||
|
||||
if(event->type == iButtonEvent::Type::EventTypeByteEditResult) {
|
||||
ibutton_key_set_data(app->get_key(), this->new_key_data, IBUTTON_KEY_DATA_SIZE);
|
||||
DOLPHIN_DEED(DolphinDeedIbuttonAdd);
|
||||
app->switch_to_next_scene(iButtonApp::Scene::SceneSaveName);
|
||||
consumed = true;
|
||||
@@ -35,13 +49,4 @@ void iButtonSceneAddValue::on_exit(iButtonApp* app) {
|
||||
|
||||
byte_input_set_result_callback(byte_input, NULL, NULL, NULL, NULL, 0);
|
||||
byte_input_set_header_text(byte_input, {0});
|
||||
}
|
||||
|
||||
void iButtonSceneAddValue::byte_input_callback(void* context) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
|
||||
event.type = iButtonEvent::Type::EventTypeByteEditResult;
|
||||
memcpy(app->get_key()->get_data(), this->new_key_data, app->get_key()->get_type_data_size());
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
#include "ibutton_scene_generic.h"
|
||||
#include "../ibutton_key.h"
|
||||
#include <one_wire/ibutton/ibutton_key.h>
|
||||
|
||||
class iButtonSceneAddValue : public iButtonScene {
|
||||
public:
|
||||
@@ -9,6 +9,5 @@ public:
|
||||
void on_exit(iButtonApp* app) final;
|
||||
|
||||
private:
|
||||
void byte_input_callback(void* context);
|
||||
uint8_t new_key_data[IBUTTON_KEY_DATA_SIZE] = {};
|
||||
};
|
||||
@@ -1,25 +1,31 @@
|
||||
#include "ibutton_scene_delete_confirm.h"
|
||||
#include "../ibutton_app.h"
|
||||
#include "../ibutton_view_manager.h"
|
||||
#include "../ibutton_event.h"
|
||||
#include <callback-connector.h>
|
||||
|
||||
static void widget_callback(GuiButtonType result, InputType type, void* context) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
|
||||
if(type == InputTypeShort) {
|
||||
event.type = iButtonEvent::Type::EventTypeWidgetButtonResult;
|
||||
event.payload.widget_button_result = result;
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
||||
}
|
||||
|
||||
void iButtonSceneDeleteConfirm::on_enter(iButtonApp* app) {
|
||||
iButtonAppViewManager* view_manager = app->get_view_manager();
|
||||
Widget* widget = view_manager->get_widget();
|
||||
auto callback = cbc::obtain_connector(this, &iButtonSceneDeleteConfirm::widget_callback);
|
||||
|
||||
iButtonKey* key = app->get_key();
|
||||
uint8_t* key_data = key->get_data();
|
||||
const uint8_t* key_data = ibutton_key_get_data_p(key);
|
||||
|
||||
app->set_text_store("\e#Delete %s?\e#", key->get_name());
|
||||
app->set_text_store("\e#Delete %s?\e#", ibutton_key_get_name_p(key));
|
||||
widget_add_text_box_element(
|
||||
widget, 0, 0, 128, 27, AlignCenter, AlignCenter, app->get_text_store());
|
||||
widget_add_button_element(widget, GuiButtonTypeLeft, "Back", callback, app);
|
||||
widget_add_button_element(widget, GuiButtonTypeRight, "Delete", callback, app);
|
||||
widget_add_button_element(widget, GuiButtonTypeLeft, "Back", widget_callback, app);
|
||||
widget_add_button_element(widget, GuiButtonTypeRight, "Delete", widget_callback, app);
|
||||
|
||||
switch(key->get_key_type()) {
|
||||
case iButtonKeyType::KeyDallas:
|
||||
switch(ibutton_key_get_type(key)) {
|
||||
case iButtonKeyDS1990:
|
||||
app->set_text_store(
|
||||
"%02X %02X %02X %02X %02X %02X %02X %02X",
|
||||
key_data[0],
|
||||
@@ -33,12 +39,12 @@ void iButtonSceneDeleteConfirm::on_enter(iButtonApp* app) {
|
||||
widget_add_string_element(
|
||||
widget, 64, 45, AlignCenter, AlignBottom, FontSecondary, "Dallas");
|
||||
break;
|
||||
case iButtonKeyType::KeyCyfral:
|
||||
case iButtonKeyCyfral:
|
||||
app->set_text_store("%02X %02X", key_data[0], key_data[1]);
|
||||
widget_add_string_element(
|
||||
widget, 64, 45, AlignCenter, AlignBottom, FontSecondary, "Cyfral");
|
||||
break;
|
||||
case iButtonKeyType::KeyMetakom:
|
||||
case iButtonKeyMetakom:
|
||||
app->set_text_store(
|
||||
"%02X %02X %02X %02X", key_data[0], key_data[1], key_data[2], key_data[3]);
|
||||
widget_add_string_element(
|
||||
@@ -77,18 +83,3 @@ void iButtonSceneDeleteConfirm::on_exit(iButtonApp* app) {
|
||||
|
||||
widget_reset(widget);
|
||||
}
|
||||
|
||||
void iButtonSceneDeleteConfirm::widget_callback(
|
||||
GuiButtonType result,
|
||||
InputType type,
|
||||
void* context) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
|
||||
if(type == InputTypeShort) {
|
||||
event.type = iButtonEvent::Type::EventTypeWidgetButtonResult;
|
||||
event.payload.widget_button_result = result;
|
||||
}
|
||||
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,4 @@ public:
|
||||
void on_enter(iButtonApp* app) final;
|
||||
bool on_event(iButtonApp* app, iButtonEvent* event) final;
|
||||
void on_exit(iButtonApp* app) final;
|
||||
|
||||
private:
|
||||
void widget_callback(GuiButtonType result, InputType type, void* context);
|
||||
};
|
||||
@@ -1,19 +1,21 @@
|
||||
#include "ibutton_scene_delete_success.h"
|
||||
#include "../ibutton_app.h"
|
||||
#include "../ibutton_view_manager.h"
|
||||
#include "../ibutton_event.h"
|
||||
#include "../ibutton_key.h"
|
||||
#include <callback-connector.h>
|
||||
|
||||
static void popup_callback(void* context) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
event.type = iButtonEvent::Type::EventTypeBack;
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
||||
|
||||
void iButtonSceneDeleteSuccess::on_enter(iButtonApp* app) {
|
||||
iButtonAppViewManager* view_manager = app->get_view_manager();
|
||||
Popup* popup = view_manager->get_popup();
|
||||
auto callback = cbc::obtain_connector(this, &iButtonSceneDeleteSuccess::popup_callback);
|
||||
|
||||
popup_set_icon(popup, 0, 2, &I_DolphinMafia_115x62);
|
||||
popup_set_text(popup, "Deleted", 83, 19, AlignLeft, AlignBottom);
|
||||
|
||||
popup_set_callback(popup, callback);
|
||||
popup_set_callback(popup, popup_callback);
|
||||
popup_set_context(popup, app);
|
||||
popup_set_timeout(popup, 1500);
|
||||
popup_enable_timeout(popup);
|
||||
@@ -41,11 +43,4 @@ void iButtonSceneDeleteSuccess::on_exit(iButtonApp* app) {
|
||||
popup_disable_timeout(popup);
|
||||
popup_set_context(popup, NULL);
|
||||
popup_set_callback(popup, NULL);
|
||||
}
|
||||
|
||||
void iButtonSceneDeleteSuccess::popup_callback(void* context) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
event.type = iButtonEvent::Type::EventTypeBack;
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
||||
@@ -6,7 +6,4 @@ public:
|
||||
void on_enter(iButtonApp* app) final;
|
||||
bool on_event(iButtonApp* app, iButtonEvent* event) final;
|
||||
void on_exit(iButtonApp* app) final;
|
||||
|
||||
private:
|
||||
void popup_callback(void* context);
|
||||
};
|
||||
@@ -1,17 +1,21 @@
|
||||
#include "ibutton_scene_emulate.h"
|
||||
#include "../ibutton_app.h"
|
||||
#include "../ibutton_view_manager.h"
|
||||
#include "../ibutton_event.h"
|
||||
#include "../ibutton_key.h"
|
||||
#include <dolphin/dolphin.h>
|
||||
#include <callback-connector.h>
|
||||
|
||||
static void emulate_callback(void* context, bool emulated) {
|
||||
if(emulated) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event = {.type = iButtonEvent::Type::EventTypeWorkerEmulated};
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
||||
}
|
||||
|
||||
void iButtonSceneEmulate::on_enter(iButtonApp* app) {
|
||||
iButtonAppViewManager* view_manager = app->get_view_manager();
|
||||
Popup* popup = view_manager->get_popup();
|
||||
iButtonKey* key = app->get_key();
|
||||
uint8_t* key_data = key->get_data();
|
||||
const char* key_name = key->get_name();
|
||||
const uint8_t* key_data = ibutton_key_get_data_p(key);
|
||||
const char* key_name = ibutton_key_get_name_p(key);
|
||||
uint8_t line_count = 2;
|
||||
DOLPHIN_DEED(DolphinDeedIbuttonEmulate);
|
||||
|
||||
@@ -21,8 +25,8 @@ void iButtonSceneEmulate::on_enter(iButtonApp* app) {
|
||||
line_count = 2;
|
||||
} else {
|
||||
// if not, show key data
|
||||
switch(key->get_key_type()) {
|
||||
case iButtonKeyType::KeyDallas:
|
||||
switch(ibutton_key_get_type(key)) {
|
||||
case iButtonKeyDS1990:
|
||||
app->set_text_store(
|
||||
"emulating\n%02X %02X %02X %02X\n%02X %02X %02X %02X",
|
||||
key_data[0],
|
||||
@@ -35,11 +39,11 @@ void iButtonSceneEmulate::on_enter(iButtonApp* app) {
|
||||
key_data[7]);
|
||||
line_count = 3;
|
||||
break;
|
||||
case iButtonKeyType::KeyCyfral:
|
||||
case iButtonKeyCyfral:
|
||||
app->set_text_store("emulating\n%02X %02X", key_data[0], key_data[1]);
|
||||
line_count = 2;
|
||||
break;
|
||||
case iButtonKeyType::KeyMetakom:
|
||||
case iButtonKeyMetakom:
|
||||
app->set_text_store(
|
||||
"emulating\n%02X %02X %02X %02X",
|
||||
key_data[0],
|
||||
@@ -66,29 +70,28 @@ void iButtonSceneEmulate::on_enter(iButtonApp* app) {
|
||||
popup_set_icon(popup, 2, 10, &I_iButtonKey_49x44);
|
||||
|
||||
view_manager->switch_to(iButtonAppViewManager::Type::iButtonAppViewPopup);
|
||||
app->get_key_worker()->start_emulate(app->get_key());
|
||||
|
||||
ibutton_worker_emulate_set_callback(app->get_key_worker(), emulate_callback, app);
|
||||
ibutton_worker_emulate_start(app->get_key_worker(), key);
|
||||
}
|
||||
|
||||
bool iButtonSceneEmulate::on_event(iButtonApp* app, iButtonEvent* event) {
|
||||
bool consumed = false;
|
||||
|
||||
if(event->type == iButtonEvent::Type::EventTypeTick) {
|
||||
if(event->type == iButtonEvent::Type::EventTypeWorkerEmulated) {
|
||||
app->notify_yellow_blink();
|
||||
consumed = true;
|
||||
} else if(event->type == iButtonEvent::Type::EventTypeTick) {
|
||||
app->notify_red_blink();
|
||||
consumed = true;
|
||||
if(app->get_key_worker()->emulated()) {
|
||||
app->notify_yellow_blink();
|
||||
} else {
|
||||
app->notify_red_blink();
|
||||
}
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void iButtonSceneEmulate::on_exit(iButtonApp* app) {
|
||||
app->get_key_worker()->stop_emulate();
|
||||
|
||||
Popup* popup = app->get_view_manager()->get_popup();
|
||||
|
||||
ibutton_worker_stop(app->get_key_worker());
|
||||
popup_set_header(popup, NULL, 0, 0, AlignCenter, AlignBottom);
|
||||
popup_set_text(popup, NULL, 0, 0, AlignCenter, AlignTop);
|
||||
popup_set_icon(popup, 0, 0, NULL);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#pragma once
|
||||
#include "ibutton_scene_generic.h"
|
||||
#include "../helpers/key_emulator.h"
|
||||
|
||||
class iButtonSceneEmulate : public iButtonScene {
|
||||
public:
|
||||
|
||||
@@ -1,24 +1,30 @@
|
||||
#include "ibutton_scene_info.h"
|
||||
#include "../ibutton_app.h"
|
||||
#include "../ibutton_view_manager.h"
|
||||
#include "../ibutton_event.h"
|
||||
#include <callback-connector.h>
|
||||
|
||||
static void widget_callback(GuiButtonType result, InputType type, void* context) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
|
||||
if(type == InputTypeShort) {
|
||||
event.type = iButtonEvent::Type::EventTypeWidgetButtonResult;
|
||||
event.payload.widget_button_result = result;
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
||||
}
|
||||
|
||||
void iButtonSceneInfo::on_enter(iButtonApp* app) {
|
||||
iButtonAppViewManager* view_manager = app->get_view_manager();
|
||||
Widget* widget = view_manager->get_widget();
|
||||
auto callback = cbc::obtain_connector(this, &iButtonSceneInfo::widget_callback);
|
||||
|
||||
iButtonKey* key = app->get_key();
|
||||
uint8_t* key_data = key->get_data();
|
||||
const uint8_t* key_data = ibutton_key_get_data_p(key);
|
||||
|
||||
app->set_text_store("%s", key->get_name());
|
||||
app->set_text_store("%s", ibutton_key_get_name_p(key));
|
||||
widget_add_text_box_element(
|
||||
widget, 0, 0, 128, 27, AlignCenter, AlignCenter, app->get_text_store());
|
||||
widget_add_button_element(widget, GuiButtonTypeLeft, "Back", callback, app);
|
||||
widget_add_button_element(widget, GuiButtonTypeLeft, "Back", widget_callback, app);
|
||||
|
||||
switch(key->get_key_type()) {
|
||||
case iButtonKeyType::KeyDallas:
|
||||
switch(ibutton_key_get_type(key)) {
|
||||
case iButtonKeyDS1990:
|
||||
app->set_text_store(
|
||||
"%02X %02X %02X %02X %02X %02X %02X %02X",
|
||||
key_data[0],
|
||||
@@ -32,13 +38,13 @@ void iButtonSceneInfo::on_enter(iButtonApp* app) {
|
||||
widget_add_string_element(
|
||||
widget, 64, 45, AlignCenter, AlignBottom, FontSecondary, "Dallas");
|
||||
break;
|
||||
case iButtonKeyType::KeyMetakom:
|
||||
case iButtonKeyMetakom:
|
||||
app->set_text_store(
|
||||
"%02X %02X %02X %02X", key_data[0], key_data[1], key_data[2], key_data[3]);
|
||||
widget_add_string_element(
|
||||
widget, 64, 45, AlignCenter, AlignBottom, FontSecondary, "Metakom");
|
||||
break;
|
||||
case iButtonKeyType::KeyCyfral:
|
||||
case iButtonKeyCyfral:
|
||||
app->set_text_store("%02X %02X", key_data[0], key_data[1]);
|
||||
widget_add_string_element(
|
||||
widget, 64, 45, AlignCenter, AlignBottom, FontSecondary, "Cyfral");
|
||||
@@ -71,15 +77,3 @@ void iButtonSceneInfo::on_exit(iButtonApp* app) {
|
||||
|
||||
widget_reset(widget);
|
||||
}
|
||||
|
||||
void iButtonSceneInfo::widget_callback(GuiButtonType result, InputType type, void* context) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
|
||||
if(type == InputTypeShort) {
|
||||
event.type = iButtonEvent::Type::EventTypeWidgetButtonResult;
|
||||
event.payload.widget_button_result = result;
|
||||
}
|
||||
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,4 @@ public:
|
||||
void on_enter(iButtonApp* app) final;
|
||||
bool on_event(iButtonApp* app, iButtonEvent* event) final;
|
||||
void on_exit(iButtonApp* app) final;
|
||||
|
||||
private:
|
||||
void widget_callback(GuiButtonType result, InputType type, void* context);
|
||||
};
|
||||
@@ -1,12 +1,18 @@
|
||||
#include "ibutton_scene_read.h"
|
||||
#include "../ibutton_app.h"
|
||||
#include "../ibutton_view_manager.h"
|
||||
#include "../ibutton_event.h"
|
||||
#include <dolphin/dolphin.h>
|
||||
|
||||
static void read_callback(void* context) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event = {.type = iButtonEvent::Type::EventTypeWorkerRead};
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
||||
|
||||
void iButtonSceneRead::on_enter(iButtonApp* app) {
|
||||
iButtonAppViewManager* view_manager = app->get_view_manager();
|
||||
Popup* popup = view_manager->get_popup();
|
||||
iButtonKey* key = app->get_key();
|
||||
iButtonWorker* worker = app->get_key_worker();
|
||||
DOLPHIN_DEED(DolphinDeedIbuttonRead);
|
||||
|
||||
popup_set_header(popup, "iButton", 95, 26, AlignCenter, AlignBottom);
|
||||
@@ -14,41 +20,41 @@ void iButtonSceneRead::on_enter(iButtonApp* app) {
|
||||
popup_set_icon(popup, 0, 5, &I_DolphinWait_61x59);
|
||||
|
||||
view_manager->switch_to(iButtonAppViewManager::Type::iButtonAppViewPopup);
|
||||
app->get_key()->set_name("");
|
||||
ibutton_key_set_name(key, "");
|
||||
|
||||
app->get_key_worker()->start_read();
|
||||
ibutton_worker_read_set_callback(worker, read_callback, app);
|
||||
ibutton_worker_read_start(worker, key);
|
||||
}
|
||||
|
||||
bool iButtonSceneRead::on_event(iButtonApp* app, iButtonEvent* event) {
|
||||
bool consumed = false;
|
||||
|
||||
if(event->type == iButtonEvent::Type::EventTypeTick) {
|
||||
if(event->type == iButtonEvent::Type::EventTypeWorkerRead) {
|
||||
consumed = true;
|
||||
|
||||
iButtonKey* key = app->get_key();
|
||||
if(ibutton_key_get_type(key) == iButtonKeyDS1990) {
|
||||
if(!ibutton_key_dallas_crc_is_valid(key)) {
|
||||
app->switch_to_next_scene(iButtonApp::Scene::SceneReadCRCError);
|
||||
} else if(!ibutton_key_dallas_is_1990_key(key)) {
|
||||
app->switch_to_next_scene(iButtonApp::Scene::SceneReadNotKeyError);
|
||||
} else {
|
||||
app->switch_to_next_scene(iButtonApp::Scene::SceneReadSuccess);
|
||||
}
|
||||
} else {
|
||||
app->switch_to_next_scene(iButtonApp::Scene::SceneReadSuccess);
|
||||
}
|
||||
} else if(event->type == iButtonEvent::Type::EventTypeTick) {
|
||||
consumed = true;
|
||||
app->notify_red_blink();
|
||||
|
||||
switch(app->get_key_worker()->read(app->get_key())) {
|
||||
case KeyReader::Error::EMPTY:
|
||||
break;
|
||||
case KeyReader::Error::OK:
|
||||
app->switch_to_next_scene(iButtonApp::Scene::SceneReadSuccess);
|
||||
break;
|
||||
case KeyReader::Error::CRC_ERROR:
|
||||
app->switch_to_next_scene(iButtonApp::Scene::SceneReadCRCError);
|
||||
break;
|
||||
case KeyReader::Error::NOT_ARE_KEY:
|
||||
app->switch_to_next_scene(iButtonApp::Scene::SceneReadNotKeyError);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void iButtonSceneRead::on_exit(iButtonApp* app) {
|
||||
app->get_key_worker()->stop_read();
|
||||
|
||||
Popup* popup = app->get_view_manager()->get_popup();
|
||||
|
||||
ibutton_worker_stop(app->get_key_worker());
|
||||
popup_set_header(popup, NULL, 0, 0, AlignCenter, AlignBottom);
|
||||
popup_set_text(popup, NULL, 0, 0, AlignCenter, AlignTop);
|
||||
popup_set_icon(popup, 0, 0, NULL);
|
||||
|
||||
@@ -6,6 +6,4 @@ public:
|
||||
void on_enter(iButtonApp* app) final;
|
||||
bool on_event(iButtonApp* app, iButtonEvent* event) final;
|
||||
void on_exit(iButtonApp* app) final;
|
||||
|
||||
private:
|
||||
};
|
||||
@@ -1,16 +1,21 @@
|
||||
#include "ibutton_scene_read_crc_error.h"
|
||||
#include "../ibutton_app.h"
|
||||
#include "../ibutton_view_manager.h"
|
||||
#include "../ibutton_event.h"
|
||||
#include <callback-connector.h>
|
||||
#include <one_wire/maxim_crc.h>
|
||||
|
||||
static void dialog_ex_callback(DialogExResult result, void* context) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
|
||||
event.type = iButtonEvent::Type::EventTypeDialogResult;
|
||||
event.payload.dialog_result = result;
|
||||
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
||||
|
||||
void iButtonSceneReadCRCError::on_enter(iButtonApp* app) {
|
||||
iButtonAppViewManager* view_manager = app->get_view_manager();
|
||||
DialogEx* dialog_ex = view_manager->get_dialog_ex();
|
||||
auto callback = cbc::obtain_connector(this, &iButtonSceneReadCRCError::dialog_ex_callback);
|
||||
|
||||
iButtonKey* key = app->get_key();
|
||||
uint8_t* key_data = key->get_data();
|
||||
const uint8_t* key_data = ibutton_key_get_data_p(app->get_key());
|
||||
|
||||
app->set_text_store(
|
||||
"%02X %02X %02X %02X %02X %02X %02X %02X\nExpected CRC: %X",
|
||||
@@ -22,13 +27,13 @@ void iButtonSceneReadCRCError::on_enter(iButtonApp* app) {
|
||||
key_data[5],
|
||||
key_data[6],
|
||||
key_data[7],
|
||||
maxim_crc8(key_data, 7));
|
||||
maxim_crc8(key_data, 7, MAXIM_CRC8_INIT));
|
||||
|
||||
dialog_ex_set_header(dialog_ex, "CRC ERROR", 64, 10, AlignCenter, AlignCenter);
|
||||
dialog_ex_set_text(dialog_ex, app->get_text_store(), 64, 19, AlignCenter, AlignTop);
|
||||
dialog_ex_set_left_button_text(dialog_ex, "Retry");
|
||||
dialog_ex_set_right_button_text(dialog_ex, "More");
|
||||
dialog_ex_set_result_callback(dialog_ex, callback);
|
||||
dialog_ex_set_result_callback(dialog_ex, dialog_ex_callback);
|
||||
dialog_ex_set_context(dialog_ex, app);
|
||||
|
||||
view_manager->switch_to(iButtonAppViewManager::Type::iButtonAppViewDialogEx);
|
||||
@@ -65,14 +70,4 @@ void iButtonSceneReadCRCError::on_exit(iButtonApp* app) {
|
||||
dialog_ex_set_context(dialog_ex, NULL);
|
||||
|
||||
app->notify_red_off();
|
||||
}
|
||||
|
||||
void iButtonSceneReadCRCError::dialog_ex_callback(DialogExResult result, void* context) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
|
||||
event.type = iButtonEvent::Type::EventTypeDialogResult;
|
||||
event.payload.dialog_result = result;
|
||||
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
||||
@@ -1,13 +1,9 @@
|
||||
#pragma once
|
||||
#include "ibutton_scene_generic.h"
|
||||
#include <gui/modules/dialog_ex.h>
|
||||
|
||||
class iButtonSceneReadCRCError : public iButtonScene {
|
||||
public:
|
||||
void on_enter(iButtonApp* app) final;
|
||||
bool on_event(iButtonApp* app, iButtonEvent* event) final;
|
||||
void on_exit(iButtonApp* app) final;
|
||||
|
||||
private:
|
||||
void dialog_ex_callback(DialogExResult result, void* context);
|
||||
};
|
||||
@@ -1,16 +1,21 @@
|
||||
#include "ibutton_scene_read_not_key_error.h"
|
||||
#include "../ibutton_app.h"
|
||||
#include "../ibutton_view_manager.h"
|
||||
#include "../ibutton_event.h"
|
||||
#include <callback-connector.h>
|
||||
#include <one_wire/maxim_crc.h>
|
||||
|
||||
static void dialog_ex_callback(DialogExResult result, void* context) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
|
||||
event.type = iButtonEvent::Type::EventTypeDialogResult;
|
||||
event.payload.dialog_result = result;
|
||||
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
||||
|
||||
void iButtonSceneReadNotKeyError::on_enter(iButtonApp* app) {
|
||||
iButtonAppViewManager* view_manager = app->get_view_manager();
|
||||
DialogEx* dialog_ex = view_manager->get_dialog_ex();
|
||||
auto callback = cbc::obtain_connector(this, &iButtonSceneReadNotKeyError::dialog_ex_callback);
|
||||
|
||||
iButtonKey* key = app->get_key();
|
||||
uint8_t* key_data = key->get_data();
|
||||
const uint8_t* key_data = ibutton_key_get_data_p(app->get_key());
|
||||
|
||||
app->set_text_store(
|
||||
"THIS IS NOT A KEY\n%02X %02X %02X %02X %02X %02X %02X %02X",
|
||||
@@ -22,13 +27,13 @@ void iButtonSceneReadNotKeyError::on_enter(iButtonApp* app) {
|
||||
key_data[5],
|
||||
key_data[6],
|
||||
key_data[7],
|
||||
maxim_crc8(key_data, 7));
|
||||
maxim_crc8(key_data, 7, MAXIM_CRC8_INIT));
|
||||
|
||||
dialog_ex_set_header(dialog_ex, "ERROR:", 64, 10, AlignCenter, AlignCenter);
|
||||
dialog_ex_set_text(dialog_ex, app->get_text_store(), 64, 19, AlignCenter, AlignTop);
|
||||
dialog_ex_set_left_button_text(dialog_ex, "Retry");
|
||||
dialog_ex_set_right_button_text(dialog_ex, "More");
|
||||
dialog_ex_set_result_callback(dialog_ex, callback);
|
||||
dialog_ex_set_result_callback(dialog_ex, dialog_ex_callback);
|
||||
dialog_ex_set_context(dialog_ex, app);
|
||||
|
||||
view_manager->switch_to(iButtonAppViewManager::Type::iButtonAppViewDialogEx);
|
||||
@@ -65,14 +70,4 @@ void iButtonSceneReadNotKeyError::on_exit(iButtonApp* app) {
|
||||
dialog_ex_set_context(dialog_ex, NULL);
|
||||
|
||||
app->notify_red_off();
|
||||
}
|
||||
|
||||
void iButtonSceneReadNotKeyError::dialog_ex_callback(DialogExResult result, void* context) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
|
||||
event.type = iButtonEvent::Type::EventTypeDialogResult;
|
||||
event.payload.dialog_result = result;
|
||||
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
||||
@@ -1,13 +1,9 @@
|
||||
#pragma once
|
||||
#include "ibutton_scene_generic.h"
|
||||
#include <gui/modules/dialog_ex.h>
|
||||
|
||||
class iButtonSceneReadNotKeyError : public iButtonScene {
|
||||
public:
|
||||
void on_enter(iButtonApp* app) final;
|
||||
bool on_event(iButtonApp* app, iButtonEvent* event) final;
|
||||
void on_exit(iButtonApp* app) final;
|
||||
|
||||
private:
|
||||
void dialog_ex_callback(DialogExResult result, void* context);
|
||||
};
|
||||
@@ -1,21 +1,26 @@
|
||||
#include "ibutton_scene_read_success.h"
|
||||
#include "../ibutton_app.h"
|
||||
#include "../ibutton_view_manager.h"
|
||||
#include "../ibutton_event.h"
|
||||
#include <dolphin/dolphin.h>
|
||||
#include <callback-connector.h>
|
||||
|
||||
static void dialog_ex_callback(DialogExResult result, void* context) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
|
||||
event.type = iButtonEvent::Type::EventTypeDialogResult;
|
||||
event.payload.dialog_result = result;
|
||||
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
||||
|
||||
void iButtonSceneReadSuccess::on_enter(iButtonApp* app) {
|
||||
iButtonAppViewManager* view_manager = app->get_view_manager();
|
||||
DialogEx* dialog_ex = view_manager->get_dialog_ex();
|
||||
auto callback = cbc::obtain_connector(this, &iButtonSceneReadSuccess::dialog_ex_callback);
|
||||
iButtonKey* key = app->get_key();
|
||||
const uint8_t* key_data = ibutton_key_get_data_p(key);
|
||||
DOLPHIN_DEED(DolphinDeedIbuttonReadSuccess);
|
||||
|
||||
iButtonKey* key = app->get_key();
|
||||
uint8_t* key_data = key->get_data();
|
||||
|
||||
switch(key->get_key_type()) {
|
||||
case iButtonKeyType::KeyDallas:
|
||||
switch(ibutton_key_get_type(key)) {
|
||||
case iButtonKeyDS1990:
|
||||
app->set_text_store(
|
||||
"Dallas\n%02X %02X %02X %02X\n%02X %02X %02X %02X",
|
||||
key_data[0],
|
||||
@@ -27,10 +32,10 @@ void iButtonSceneReadSuccess::on_enter(iButtonApp* app) {
|
||||
key_data[6],
|
||||
key_data[7]);
|
||||
break;
|
||||
case iButtonKeyType::KeyCyfral:
|
||||
case iButtonKeyCyfral:
|
||||
app->set_text_store("Cyfral\n%02X %02X", key_data[0], key_data[1]);
|
||||
break;
|
||||
case iButtonKeyType::KeyMetakom:
|
||||
case iButtonKeyMetakom:
|
||||
app->set_text_store(
|
||||
"Metakom\n%02X %02X %02X %02X", key_data[0], key_data[1], key_data[2], key_data[3]);
|
||||
break;
|
||||
@@ -40,7 +45,7 @@ void iButtonSceneReadSuccess::on_enter(iButtonApp* app) {
|
||||
dialog_ex_set_left_button_text(dialog_ex, "Retry");
|
||||
dialog_ex_set_right_button_text(dialog_ex, "More");
|
||||
dialog_ex_set_icon(dialog_ex, 0, 1, &I_DolphinExcited_64x63);
|
||||
dialog_ex_set_result_callback(dialog_ex, callback);
|
||||
dialog_ex_set_result_callback(dialog_ex, dialog_ex_callback);
|
||||
dialog_ex_set_context(dialog_ex, app);
|
||||
|
||||
view_manager->switch_to(iButtonAppViewManager::Type::iButtonAppViewDialogEx);
|
||||
@@ -80,13 +85,3 @@ void iButtonSceneReadSuccess::on_exit(iButtonApp* app) {
|
||||
|
||||
app->notify_green_off();
|
||||
}
|
||||
|
||||
void iButtonSceneReadSuccess::dialog_ex_callback(DialogExResult result, void* context) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
|
||||
event.type = iButtonEvent::Type::EventTypeDialogResult;
|
||||
event.payload.dialog_result = result;
|
||||
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
#pragma once
|
||||
#include "ibutton_scene_generic.h"
|
||||
#include <gui/modules/dialog_ex.h>
|
||||
|
||||
class iButtonSceneReadSuccess : public iButtonScene {
|
||||
public:
|
||||
void on_enter(iButtonApp* app) final;
|
||||
bool on_event(iButtonApp* app, iButtonEvent* event) final;
|
||||
void on_exit(iButtonApp* app) final;
|
||||
|
||||
private:
|
||||
void dialog_ex_callback(DialogExResult result, void* context);
|
||||
};
|
||||
@@ -1,8 +1,5 @@
|
||||
#include "ibutton_scene_readed_key_menu.h"
|
||||
#include "../ibutton_app.h"
|
||||
#include "../ibutton_view_manager.h"
|
||||
#include "../ibutton_event.h"
|
||||
#include <callback-connector.h>
|
||||
|
||||
typedef enum {
|
||||
SubmenuIndexWrite,
|
||||
@@ -11,17 +8,26 @@ typedef enum {
|
||||
SubmenuIndexReadNewKey,
|
||||
} SubmenuIndex;
|
||||
|
||||
static void submenu_callback(void* context, uint32_t index) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
|
||||
event.type = iButtonEvent::Type::EventTypeMenuSelected;
|
||||
event.payload.menu_index = index;
|
||||
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
||||
|
||||
void iButtonSceneReadedKeyMenu::on_enter(iButtonApp* app) {
|
||||
iButtonAppViewManager* view_manager = app->get_view_manager();
|
||||
Submenu* submenu = view_manager->get_submenu();
|
||||
auto callback = cbc::obtain_connector(this, &iButtonSceneReadedKeyMenu::submenu_callback);
|
||||
|
||||
if(app->get_key()->get_key_type() == iButtonKeyType::KeyDallas) {
|
||||
submenu_add_item(submenu, "Write", SubmenuIndexWrite, callback, app);
|
||||
if(ibutton_key_get_type(app->get_key()) == iButtonKeyDS1990) {
|
||||
submenu_add_item(submenu, "Write", SubmenuIndexWrite, submenu_callback, app);
|
||||
}
|
||||
submenu_add_item(submenu, "Name and save", SubmenuIndexNameAndSave, callback, app);
|
||||
submenu_add_item(submenu, "Emulate", SubmenuIndexEmulate, callback, app);
|
||||
submenu_add_item(submenu, "Read new key", SubmenuIndexReadNewKey, callback, app);
|
||||
submenu_add_item(submenu, "Name and save", SubmenuIndexNameAndSave, submenu_callback, app);
|
||||
submenu_add_item(submenu, "Emulate", SubmenuIndexEmulate, submenu_callback, app);
|
||||
submenu_add_item(submenu, "Read new key", SubmenuIndexReadNewKey, submenu_callback, app);
|
||||
submenu_set_selected_item(submenu, submenu_item_selected);
|
||||
|
||||
view_manager->switch_to(iButtonAppViewManager::Type::iButtonAppViewSubmenu);
|
||||
@@ -60,14 +66,4 @@ void iButtonSceneReadedKeyMenu::on_exit(iButtonApp* app) {
|
||||
Submenu* submenu = view->get_submenu();
|
||||
|
||||
submenu_reset(submenu);
|
||||
}
|
||||
|
||||
void iButtonSceneReadedKeyMenu::submenu_callback(void* context, uint32_t index) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
|
||||
event.type = iButtonEvent::Type::EventTypeMenuSelected;
|
||||
event.payload.menu_index = index;
|
||||
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,5 @@ public:
|
||||
void on_exit(iButtonApp* app) final;
|
||||
|
||||
private:
|
||||
void submenu_callback(void* context, uint32_t index);
|
||||
uint32_t submenu_item_selected = 0;
|
||||
};
|
||||
@@ -1,18 +1,21 @@
|
||||
#include "ibutton_scene_save_name.h"
|
||||
#include "../ibutton_app.h"
|
||||
#include "../ibutton_view_manager.h"
|
||||
#include "../ibutton_event.h"
|
||||
#include "../ibutton_key.h"
|
||||
#include <callback-connector.h>
|
||||
#include <lib/toolbox/random_name.h>
|
||||
|
||||
static void text_input_callback(void* context) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
|
||||
event.type = iButtonEvent::Type::EventTypeTextEditResult;
|
||||
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
||||
|
||||
void iButtonSceneSaveName::on_enter(iButtonApp* app) {
|
||||
iButtonAppViewManager* view_manager = app->get_view_manager();
|
||||
TextInput* text_input = view_manager->get_text_input();
|
||||
auto callback = cbc::obtain_connector(this, &iButtonSceneSaveName::text_input_callback);
|
||||
|
||||
iButtonKey* key = app->get_key();
|
||||
const char* key_name = key->get_name();
|
||||
const char* key_name = ibutton_key_get_name_p(app->get_key());
|
||||
bool key_name_empty = !strcmp(key_name, "");
|
||||
|
||||
if(key_name_empty) {
|
||||
@@ -23,7 +26,12 @@ void iButtonSceneSaveName::on_enter(iButtonApp* app) {
|
||||
|
||||
text_input_set_header_text(text_input, "Name the key");
|
||||
text_input_set_result_callback(
|
||||
text_input, callback, app, app->get_text_store(), IBUTTON_KEY_NAME_SIZE, key_name_empty);
|
||||
text_input,
|
||||
text_input_callback,
|
||||
app,
|
||||
app->get_text_store(),
|
||||
IBUTTON_KEY_NAME_SIZE,
|
||||
key_name_empty);
|
||||
|
||||
ValidatorIsFile* validator_is_file =
|
||||
validator_is_file_alloc_init(app->app_folder, app->app_extension);
|
||||
@@ -59,12 +67,3 @@ void iButtonSceneSaveName::on_exit(iButtonApp* app) {
|
||||
|
||||
text_input_reset(text_input);
|
||||
}
|
||||
|
||||
void iButtonSceneSaveName::text_input_callback(void* context) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
|
||||
event.type = iButtonEvent::Type::EventTypeTextEditResult;
|
||||
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,4 @@ public:
|
||||
void on_enter(iButtonApp* app) final;
|
||||
bool on_event(iButtonApp* app, iButtonEvent* event) final;
|
||||
void on_exit(iButtonApp* app) final;
|
||||
|
||||
private:
|
||||
void text_input_callback(void* context);
|
||||
};
|
||||
@@ -1,21 +1,23 @@
|
||||
#include "ibutton_scene_save_success.h"
|
||||
#include "../ibutton_app.h"
|
||||
#include "../ibutton_view_manager.h"
|
||||
#include "../ibutton_event.h"
|
||||
#include "../ibutton_key.h"
|
||||
#include <dolphin/dolphin.h>
|
||||
#include <callback-connector.h>
|
||||
|
||||
static void popup_callback(void* context) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
event.type = iButtonEvent::Type::EventTypeBack;
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
||||
|
||||
void iButtonSceneSaveSuccess::on_enter(iButtonApp* app) {
|
||||
iButtonAppViewManager* view_manager = app->get_view_manager();
|
||||
Popup* popup = view_manager->get_popup();
|
||||
auto callback = cbc::obtain_connector(this, &iButtonSceneSaveSuccess::popup_callback);
|
||||
DOLPHIN_DEED(DolphinDeedIbuttonSave);
|
||||
|
||||
popup_set_icon(popup, 32, 5, &I_DolphinNice_96x59);
|
||||
popup_set_text(popup, "Saved!", 13, 22, AlignLeft, AlignBottom);
|
||||
|
||||
popup_set_callback(popup, callback);
|
||||
popup_set_callback(popup, popup_callback);
|
||||
popup_set_context(popup, app);
|
||||
popup_set_timeout(popup, 1500);
|
||||
popup_enable_timeout(popup);
|
||||
@@ -46,11 +48,4 @@ void iButtonSceneSaveSuccess::on_exit(iButtonApp* app) {
|
||||
popup_disable_timeout(popup);
|
||||
popup_set_context(popup, NULL);
|
||||
popup_set_callback(popup, NULL);
|
||||
}
|
||||
|
||||
void iButtonSceneSaveSuccess::popup_callback(void* context) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
event.type = iButtonEvent::Type::EventTypeBack;
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,4 @@ public:
|
||||
void on_enter(iButtonApp* app) final;
|
||||
bool on_event(iButtonApp* app, iButtonEvent* event) final;
|
||||
void on_exit(iButtonApp* app) final;
|
||||
|
||||
private:
|
||||
void popup_callback(void* context);
|
||||
};
|
||||
@@ -1,7 +1,5 @@
|
||||
#include "ibutton_scene_saved_key_menu.h"
|
||||
#include "../ibutton_app.h"
|
||||
#include "../ibutton_view_manager.h"
|
||||
#include "../ibutton_event.h"
|
||||
#include <callback-connector.h>
|
||||
|
||||
typedef enum {
|
||||
@@ -12,18 +10,27 @@ typedef enum {
|
||||
SubmenuIndexInfo,
|
||||
} SubmenuIndex;
|
||||
|
||||
static void submenu_callback(void* context, uint32_t index) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
|
||||
event.type = iButtonEvent::Type::EventTypeMenuSelected;
|
||||
event.payload.menu_index = index;
|
||||
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
||||
|
||||
void iButtonSceneSavedKeyMenu::on_enter(iButtonApp* app) {
|
||||
iButtonAppViewManager* view_manager = app->get_view_manager();
|
||||
Submenu* submenu = view_manager->get_submenu();
|
||||
auto callback = cbc::obtain_connector(this, &iButtonSceneSavedKeyMenu::submenu_callback);
|
||||
|
||||
submenu_add_item(submenu, "Emulate", SubmenuIndexEmulate, callback, app);
|
||||
if(app->get_key()->get_key_type() == iButtonKeyType::KeyDallas) {
|
||||
submenu_add_item(submenu, "Write", SubmenuIndexWrite, callback, app);
|
||||
submenu_add_item(submenu, "Emulate", SubmenuIndexEmulate, submenu_callback, app);
|
||||
if(ibutton_key_get_type(app->get_key()) == iButtonKeyDS1990) {
|
||||
submenu_add_item(submenu, "Write", SubmenuIndexWrite, submenu_callback, app);
|
||||
}
|
||||
submenu_add_item(submenu, "Edit", SubmenuIndexEdit, callback, app);
|
||||
submenu_add_item(submenu, "Delete", SubmenuIndexDelete, callback, app);
|
||||
submenu_add_item(submenu, "Info", SubmenuIndexInfo, callback, app);
|
||||
submenu_add_item(submenu, "Edit", SubmenuIndexEdit, submenu_callback, app);
|
||||
submenu_add_item(submenu, "Delete", SubmenuIndexDelete, submenu_callback, app);
|
||||
submenu_add_item(submenu, "Info", SubmenuIndexInfo, submenu_callback, app);
|
||||
submenu_set_selected_item(submenu, submenu_item_selected);
|
||||
|
||||
view_manager->switch_to(iButtonAppViewManager::Type::iButtonAppViewSubmenu);
|
||||
@@ -63,13 +70,3 @@ void iButtonSceneSavedKeyMenu::on_exit(iButtonApp* app) {
|
||||
|
||||
submenu_reset(submenu);
|
||||
}
|
||||
|
||||
void iButtonSceneSavedKeyMenu::submenu_callback(void* context, uint32_t index) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
|
||||
event.type = iButtonEvent::Type::EventTypeMenuSelected;
|
||||
event.payload.menu_index = index;
|
||||
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
||||
|
||||
@@ -8,6 +8,5 @@ public:
|
||||
void on_exit(iButtonApp* app) final;
|
||||
|
||||
private:
|
||||
void submenu_callback(void* context, uint32_t index);
|
||||
uint32_t submenu_item_selected = 0;
|
||||
};
|
||||
@@ -1,7 +1,5 @@
|
||||
#include "ibutton_scene_select_key.h"
|
||||
#include "../ibutton_app.h"
|
||||
#include "../ibutton_event.h"
|
||||
#include "../ibutton_key.h"
|
||||
|
||||
void iButtonSceneSelectKey::on_enter(iButtonApp* app) {
|
||||
// Process file_select return
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
#include "ibutton_scene_start.h"
|
||||
#include "../ibutton_app.h"
|
||||
#include "../ibutton_view_manager.h"
|
||||
#include "../ibutton_event.h"
|
||||
#include <callback-connector.h>
|
||||
|
||||
typedef enum {
|
||||
SubmenuIndexRead,
|
||||
@@ -10,14 +7,23 @@ typedef enum {
|
||||
SubmenuIndexAdd,
|
||||
} SubmenuIndex;
|
||||
|
||||
static void submenu_callback(void* context, uint32_t index) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
|
||||
event.type = iButtonEvent::Type::EventTypeMenuSelected;
|
||||
event.payload.menu_index = index;
|
||||
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
||||
|
||||
void iButtonSceneStart::on_enter(iButtonApp* app) {
|
||||
iButtonAppViewManager* view_manager = app->get_view_manager();
|
||||
Submenu* submenu = view_manager->get_submenu();
|
||||
auto callback = cbc::obtain_connector(this, &iButtonSceneStart::submenu_callback);
|
||||
|
||||
submenu_add_item(submenu, "Read", SubmenuIndexRead, callback, app);
|
||||
submenu_add_item(submenu, "Saved", SubmenuIndexSaved, callback, app);
|
||||
submenu_add_item(submenu, "Add manually", SubmenuIndexAdd, callback, app);
|
||||
submenu_add_item(submenu, "Read", SubmenuIndexRead, submenu_callback, app);
|
||||
submenu_add_item(submenu, "Saved", SubmenuIndexSaved, submenu_callback, app);
|
||||
submenu_add_item(submenu, "Add manually", SubmenuIndexAdd, submenu_callback, app);
|
||||
submenu_set_selected_item(submenu, submenu_item_selected);
|
||||
|
||||
view_manager->switch_to(iButtonAppViewManager::Type::iButtonAppViewSubmenu);
|
||||
@@ -51,13 +57,3 @@ void iButtonSceneStart::on_exit(iButtonApp* app) {
|
||||
|
||||
submenu_reset(submenu);
|
||||
}
|
||||
|
||||
void iButtonSceneStart::submenu_callback(void* context, uint32_t index) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
|
||||
event.type = iButtonEvent::Type::EventTypeMenuSelected;
|
||||
event.payload.menu_index = index;
|
||||
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
||||
|
||||
@@ -8,6 +8,5 @@ public:
|
||||
void on_exit(iButtonApp* app) final;
|
||||
|
||||
private:
|
||||
void submenu_callback(void* context, uint32_t index);
|
||||
uint32_t submenu_item_selected = 0;
|
||||
};
|
||||
@@ -1,15 +1,22 @@
|
||||
#include "ibutton_scene_write.h"
|
||||
#include "../ibutton_app.h"
|
||||
#include "../ibutton_view_manager.h"
|
||||
#include "../ibutton_event.h"
|
||||
#include "../ibutton_key.h"
|
||||
|
||||
static void ibutton_worker_write_cb(void* context, iButtonWorkerWriteResult result) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
event.type = iButtonEvent::Type::EventTypeWorkerWrite;
|
||||
event.payload.worker_write_result = result;
|
||||
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
||||
|
||||
void iButtonSceneWrite::on_enter(iButtonApp* app) {
|
||||
iButtonAppViewManager* view_manager = app->get_view_manager();
|
||||
Popup* popup = view_manager->get_popup();
|
||||
iButtonKey* key = app->get_key();
|
||||
uint8_t* key_data = key->get_data();
|
||||
const char* key_name = key->get_name();
|
||||
iButtonWorker* worker = app->get_key_worker();
|
||||
const uint8_t* key_data = ibutton_key_get_data_p(key);
|
||||
const char* key_name = ibutton_key_get_name_p(key);
|
||||
uint8_t line_count = 2;
|
||||
|
||||
// check that stored key has name
|
||||
@@ -18,8 +25,8 @@ void iButtonSceneWrite::on_enter(iButtonApp* app) {
|
||||
line_count = 2;
|
||||
} else {
|
||||
// if not, show key data
|
||||
switch(key->get_key_type()) {
|
||||
case iButtonKeyType::KeyDallas:
|
||||
switch(ibutton_key_get_type(key)) {
|
||||
case iButtonKeyDS1990:
|
||||
app->set_text_store(
|
||||
"writing\n%02X %02X %02X %02X\n%02X %02X %02X %02X",
|
||||
key_data[0],
|
||||
@@ -32,11 +39,11 @@ void iButtonSceneWrite::on_enter(iButtonApp* app) {
|
||||
key_data[7]);
|
||||
line_count = 3;
|
||||
break;
|
||||
case iButtonKeyType::KeyCyfral:
|
||||
case iButtonKeyCyfral:
|
||||
app->set_text_store("writing\n%02X %02X", key_data[0], key_data[1]);
|
||||
line_count = 2;
|
||||
break;
|
||||
case iButtonKeyType::KeyMetakom:
|
||||
case iButtonKeyMetakom:
|
||||
app->set_text_store(
|
||||
"writing\n%02X %02X %02X %02X", key_data[0], key_data[1], key_data[2], key_data[3]);
|
||||
line_count = 2;
|
||||
@@ -60,27 +67,34 @@ void iButtonSceneWrite::on_enter(iButtonApp* app) {
|
||||
|
||||
view_manager->switch_to(iButtonAppViewManager::Type::iButtonAppViewPopup);
|
||||
|
||||
app->get_key_worker()->start_write();
|
||||
blink_yellow = false;
|
||||
ibutton_worker_write_set_callback(worker, ibutton_worker_write_cb, app);
|
||||
ibutton_worker_write_start(worker, key);
|
||||
}
|
||||
|
||||
bool iButtonSceneWrite::on_event(iButtonApp* app, iButtonEvent* event) {
|
||||
bool consumed = false;
|
||||
|
||||
if(event->type == iButtonEvent::Type::EventTypeTick) {
|
||||
if(event->type == iButtonEvent::Type::EventTypeWorkerWrite) {
|
||||
consumed = true;
|
||||
KeyWriter::Error result = app->get_key_worker()->write(app->get_key());
|
||||
|
||||
switch(result) {
|
||||
case KeyWriter::Error::SAME_KEY:
|
||||
case KeyWriter::Error::OK:
|
||||
switch(event->payload.worker_write_result) {
|
||||
case iButtonWorkerWriteOK:
|
||||
case iButtonWorkerWriteSameKey:
|
||||
app->switch_to_next_scene(iButtonApp::Scene::SceneWriteSuccess);
|
||||
break;
|
||||
case KeyWriter::Error::NO_DETECT:
|
||||
app->notify_red_blink();
|
||||
case iButtonWorkerWriteNoDetect:
|
||||
blink_yellow = false;
|
||||
break;
|
||||
case KeyWriter::Error::CANNOT_WRITE:
|
||||
case iButtonWorkerWriteCannotWrite:
|
||||
blink_yellow = true;
|
||||
break;
|
||||
}
|
||||
} else if(event->type == iButtonEvent::Type::EventTypeTick) {
|
||||
if(blink_yellow) {
|
||||
app->notify_yellow_blink();
|
||||
break;
|
||||
} else {
|
||||
app->notify_red_blink();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,10 +103,8 @@ bool iButtonSceneWrite::on_event(iButtonApp* app, iButtonEvent* event) {
|
||||
|
||||
void iButtonSceneWrite::on_exit(iButtonApp* app) {
|
||||
Popup* popup = app->get_view_manager()->get_popup();
|
||||
|
||||
ibutton_worker_stop(app->get_key_worker());
|
||||
popup_set_header(popup, NULL, 0, 0, AlignCenter, AlignBottom);
|
||||
popup_set_text(popup, NULL, 0, 0, AlignCenter, AlignTop);
|
||||
popup_set_icon(popup, 0, 0, NULL);
|
||||
|
||||
app->get_key_worker()->stop_write();
|
||||
}
|
||||
@@ -8,4 +8,5 @@ public:
|
||||
void on_exit(iButtonApp* app) final;
|
||||
|
||||
private:
|
||||
bool blink_yellow;
|
||||
};
|
||||
@@ -1,19 +1,22 @@
|
||||
#include "ibutton_scene_write_success.h"
|
||||
#include "../ibutton_app.h"
|
||||
#include "../ibutton_view_manager.h"
|
||||
#include "../ibutton_event.h"
|
||||
#include "../ibutton_key.h"
|
||||
#include <callback-connector.h>
|
||||
|
||||
static void popup_callback(void* context) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
event.type = iButtonEvent::Type::EventTypeBack;
|
||||
app->get_view_manager()->send_event(&event);
|
||||
app->notify_green_off();
|
||||
}
|
||||
|
||||
void iButtonSceneWriteSuccess::on_enter(iButtonApp* app) {
|
||||
iButtonAppViewManager* view_manager = app->get_view_manager();
|
||||
Popup* popup = view_manager->get_popup();
|
||||
auto callback = cbc::obtain_connector(this, &iButtonSceneWriteSuccess::popup_callback);
|
||||
|
||||
popup_set_icon(popup, 0, 12, &I_iButtonDolphinVerySuccess_108x52);
|
||||
popup_set_text(popup, "Successfully written!", 40, 12, AlignLeft, AlignBottom);
|
||||
|
||||
popup_set_callback(popup, callback);
|
||||
popup_set_callback(popup, popup_callback);
|
||||
popup_set_context(popup, app);
|
||||
popup_set_timeout(popup, 1500);
|
||||
popup_enable_timeout(popup);
|
||||
@@ -45,12 +48,4 @@ void iButtonSceneWriteSuccess::on_exit(iButtonApp* app) {
|
||||
popup_disable_timeout(popup);
|
||||
popup_set_context(popup, NULL);
|
||||
popup_set_callback(popup, NULL);
|
||||
}
|
||||
|
||||
void iButtonSceneWriteSuccess::popup_callback(void* context) {
|
||||
iButtonApp* app = static_cast<iButtonApp*>(context);
|
||||
iButtonEvent event;
|
||||
event.type = iButtonEvent::Type::EventTypeBack;
|
||||
app->get_view_manager()->send_event(&event);
|
||||
app->notify_green_off();
|
||||
}
|
||||
@@ -6,7 +6,4 @@ public:
|
||||
void on_enter(iButtonApp* app) final;
|
||||
bool on_event(iButtonApp* app, iButtonEvent* event) final;
|
||||
void on_exit(iButtonApp* app) final;
|
||||
|
||||
private:
|
||||
void popup_callback(void* context);
|
||||
};
|
||||
Reference in New Issue
Block a user