Fix off-by-one bug. Stop clicking when all found.

This commit is contained in:
Derek Jamison 2023-10-20 16:43:38 -05:00
parent 87df63a3e9
commit 32b40d268a
5 changed files with 30 additions and 17 deletions

View File

@ -5,7 +5,7 @@ App(
entry_point="genie_record_app",
requires=["gui", "subghz"],
stack_size=4 * 1024,
fap_version=(2, 4),
fap_version=(2, 5),
fap_icon="genie.png",
fap_category="Sub-GHz",
fap_icon_assets="assets",

View File

@ -42,7 +42,7 @@ typedef struct {
bool pressed;
uint32_t click_counter;
uint32_t rx_counter;
uint16_t genie_save_counter;
uint32_t genie_save_counter;
FuriString* key;
} GenieApp;
@ -116,8 +116,8 @@ static void genie_view_draw_callback(Canvas* canvas, void* model) {
"Got %ld",
app->genie_save_counter > 0 ? app->genie_save_counter : app->rx_counter);
canvas_draw_str(canvas, 75, 45, buffer);
if(app->genie_save_counter != 0xFFFF) {
snprintf(buffer, COUNT_OF(buffer), "Remaining codes %d", 65536 - app->genie_save_counter);
if(app->genie_save_counter < 0x10000) {
snprintf(buffer, COUNT_OF(buffer), "Remaining codes %ld", 65536 - app->genie_save_counter);
canvas_draw_str(canvas, 1, 32, buffer);
} else {
canvas_draw_str(canvas, 1, 30, "Found all codes!");
@ -136,7 +136,7 @@ static uint32_t last_count() {
return count;
}
static uint16_t save_count(uint32_t count, FuriString* key, bool is_genie) {
static uint32_t save_count(uint32_t count, FuriString* key, bool is_genie) {
FURI_LOG_D(TAG, "%ld,%s", count, furi_string_get_cstr(key));
genie_save(count, key);
if(is_genie) {
@ -169,7 +169,7 @@ static void genie_packet(FuriString* buffer, void* context) {
GenieApp* app = (GenieApp*)context;
app->processing = true;
/*
/*
if(furi_string_search_str(buffer, "KeeLoq 64bit") < furi_string_size(buffer)) {
release_button(app);
FURI_LOG_D(TAG, "KeeLoq 64bit packet");
@ -180,7 +180,7 @@ static void genie_packet(FuriString* buffer, void* context) {
save_count(app->click_counter, app->key, false);
}
} else
*/
*/
if(furi_string_search_str(buffer, "Genie 64bit") < furi_string_size(buffer)) {
release_button(app);
FURI_LOG_D(TAG, "Genie 64bit packet");
@ -198,7 +198,9 @@ static void genie_packet(FuriString* buffer, void* context) {
static void genie_tick(void* context) {
GenieApp* app = (GenieApp*)context;
if(!app->processing) {
if(app->pressed) {
if(app->genie_save_counter > 0xFFFF) {
release_button(app);
} else if(app->pressed) {
release_button(app);
} else {
app->click_counter++;

View File

@ -2,7 +2,7 @@
#define GENIE_ABOUT_TEXT \
"Genie garage door recorder.\n" \
"Version 2.4\n---\n" \
"Version 2.5\n---\n" \
"Custom genie firmware is\n" \
"required for this app.\n" \
"---\n" \

View File

@ -10,7 +10,7 @@
// Should match application.fam, fap_version.
#define GENIE_MAJOR_VERSION 2
#define GENIE_MINOR_VERSION 4
#define GENIE_MINOR_VERSION 5
#define GENIE_MAGIC_CODE 0x472A
@ -120,8 +120,8 @@ static uint32_t hex_to_i32(const char* data) {
return value;
}
uint16_t genie_save_bin(const char* key) {
uint16_t result = 0;
uint32_t genie_save_bin(const char* key) {
uint32_t result = 0;
uint32_t key_high = 0;
uint32_t key_low = 0;
key_high = hex_to_i32(key);
@ -189,9 +189,17 @@ uint16_t genie_save_bin(const char* key) {
uint32_t existing = storage_file_read32(file);
if(existing != 0 && existing != key_high) {
FURI_LOG_E(
TAG, "Key mismatch at %04X. Old: %08lX, New: %08lX", count, existing, key_high);
result = count;
if(count != 0xFFFF) {
FURI_LOG_E(
TAG,
"Key mismatch at %04X. Old: %08lX, New: %08lX",
count,
existing,
key_high);
result = count;
} else {
result = 0x10000;
}
break;
}
@ -213,13 +221,16 @@ uint16_t genie_save_bin(const char* key) {
if(count != 0xFFFF) {
count++;
result = count;
if(!storage_file_write16(file, count)) {
FURI_LOG_E(TAG, "Failed to write count to file: %04X", count);
break;
}
} else {
result = 0x10000;
}
result = count;
} else {
FURI_LOG_E(TAG, "Failed to open file");
break;

View File

@ -3,6 +3,6 @@
#include <furi.h>
bool genie_save(uint32_t count, FuriString* key);
uint16_t genie_save_bin(const char* key);
uint32_t genie_save_bin(const char* key);
uint32_t genie_load();
void genie_file_init();