Merge branch 'dev' into shutdown_idle
16
.github/workflows/unit_tests.yml
vendored
@@ -8,7 +8,7 @@ env:
|
|||||||
DEFAULT_TARGET: f7
|
DEFAULT_TARGET: f7
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
main:
|
run_units_on_test_bench:
|
||||||
runs-on: [self-hosted, FlipperZeroTest]
|
runs-on: [self-hosted, FlipperZeroTest]
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
@@ -22,31 +22,35 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
echo "flipper=/dev/ttyACM0" >> $GITHUB_OUTPUT
|
echo "flipper=/dev/ttyACM0" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
- name: 'Compile unit tests firmware'
|
- name: 'Flash unit tests firmware'
|
||||||
id: compile
|
id: flashing
|
||||||
run: |
|
run: |
|
||||||
FBT_TOOLCHAIN_PATH=/opt ./fbt flash OPENOCD_ADAPTER_SERIAL=2A0906016415303030303032 FIRMWARE_APP_SET=unit_tests FORCE=1
|
FBT_TOOLCHAIN_PATH=/opt ./fbt flash OPENOCD_ADAPTER_SERIAL=2A0906016415303030303032 FIRMWARE_APP_SET=unit_tests FORCE=1
|
||||||
|
|
||||||
- name: 'Wait for flipper to finish updating'
|
- name: 'Wait for flipper to finish updating'
|
||||||
id: connect
|
id: connect
|
||||||
if: steps.compile.outcome == 'success'
|
if: steps.flashing.outcome == 'success'
|
||||||
run: |
|
run: |
|
||||||
python3 ./scripts/testing/await_flipper.py ${{steps.device.outputs.flipper}}
|
. scripts/toolchain/fbtenv.sh
|
||||||
|
./scripts/testing/await_flipper.py ${{steps.device.outputs.flipper}}
|
||||||
|
|
||||||
- name: 'Format flipper SD card'
|
- name: 'Format flipper SD card'
|
||||||
id: format
|
id: format
|
||||||
if: steps.connect.outcome == 'success'
|
if: steps.connect.outcome == 'success'
|
||||||
run: |
|
run: |
|
||||||
|
. scripts/toolchain/fbtenv.sh
|
||||||
./scripts/storage.py -p ${{steps.device.outputs.flipper}} format_ext
|
./scripts/storage.py -p ${{steps.device.outputs.flipper}} format_ext
|
||||||
|
|
||||||
- name: 'Copy assets and unit tests data to flipper'
|
- name: 'Copy assets and unit tests data to flipper'
|
||||||
id: copy
|
id: copy
|
||||||
if: steps.format.outcome == 'success'
|
if: steps.format.outcome == 'success'
|
||||||
run: |
|
run: |
|
||||||
|
. scripts/toolchain/fbtenv.sh
|
||||||
./scripts/storage.py -p ${{steps.device.outputs.flipper}} send assets/resources /ext
|
./scripts/storage.py -p ${{steps.device.outputs.flipper}} send assets/resources /ext
|
||||||
./scripts/storage.py -p ${{steps.device.outputs.flipper}} send assets/unit_tests /ext/unit_tests
|
./scripts/storage.py -p ${{steps.device.outputs.flipper}} send assets/unit_tests /ext/unit_tests
|
||||||
|
|
||||||
- name: 'Run units and validate results'
|
- name: 'Run units and validate results'
|
||||||
if: steps.copy.outcome == 'success'
|
if: steps.copy.outcome == 'success'
|
||||||
run: |
|
run: |
|
||||||
python3 ./scripts/testing/units.py ${{steps.device.outputs.flipper}}
|
. scripts/toolchain/fbtenv.sh
|
||||||
|
./scripts/testing/units.py ${{steps.device.outputs.flipper}}
|
||||||
|
|||||||
10
SConstruct
@@ -33,10 +33,6 @@ coreenv = SConscript(
|
|||||||
)
|
)
|
||||||
SConscript("site_scons/cc.scons", exports={"ENV": coreenv})
|
SConscript("site_scons/cc.scons", exports={"ENV": coreenv})
|
||||||
|
|
||||||
# Store root dir in environment for certain tools
|
|
||||||
coreenv["ROOT_DIR"] = Dir(".")
|
|
||||||
|
|
||||||
|
|
||||||
# Create a separate "dist" environment and add construction envs to it
|
# Create a separate "dist" environment and add construction envs to it
|
||||||
distenv = coreenv.Clone(
|
distenv = coreenv.Clone(
|
||||||
tools=[
|
tools=[
|
||||||
@@ -233,13 +229,13 @@ distenv.PhonyTarget(
|
|||||||
# Linter
|
# Linter
|
||||||
distenv.PhonyTarget(
|
distenv.PhonyTarget(
|
||||||
"lint",
|
"lint",
|
||||||
"${PYTHON3} scripts/lint.py check ${LINT_SOURCES}",
|
"${PYTHON3} ${FBT_SCRIPT_DIR}/lint.py check ${LINT_SOURCES}",
|
||||||
LINT_SOURCES=firmware_env["LINT_SOURCES"],
|
LINT_SOURCES=firmware_env["LINT_SOURCES"],
|
||||||
)
|
)
|
||||||
|
|
||||||
distenv.PhonyTarget(
|
distenv.PhonyTarget(
|
||||||
"format",
|
"format",
|
||||||
"${PYTHON3} scripts/lint.py format ${LINT_SOURCES}",
|
"${PYTHON3} ${FBT_SCRIPT_DIR}/lint.py format ${LINT_SOURCES}",
|
||||||
LINT_SOURCES=firmware_env["LINT_SOURCES"],
|
LINT_SOURCES=firmware_env["LINT_SOURCES"],
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -280,7 +276,7 @@ distenv.PhonyTarget(
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Start Flipper CLI via PySerial's miniterm
|
# Start Flipper CLI via PySerial's miniterm
|
||||||
distenv.PhonyTarget("cli", "${PYTHON3} scripts/serial_cli.py")
|
distenv.PhonyTarget("cli", "${PYTHON3} ${FBT_SCRIPT_DIR}/serial_cli.py")
|
||||||
|
|
||||||
|
|
||||||
# Find blackmagic probe
|
# Find blackmagic probe
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ static const DuckyKey ducky_keys[] = {
|
|||||||
{"PAGEUP", HID_KEYBOARD_PAGE_UP},
|
{"PAGEUP", HID_KEYBOARD_PAGE_UP},
|
||||||
{"PAGEDOWN", HID_KEYBOARD_PAGE_DOWN},
|
{"PAGEDOWN", HID_KEYBOARD_PAGE_DOWN},
|
||||||
{"PRINTSCREEN", HID_KEYBOARD_PRINT_SCREEN},
|
{"PRINTSCREEN", HID_KEYBOARD_PRINT_SCREEN},
|
||||||
{"SCROLLOCK", HID_KEYBOARD_SCROLL_LOCK},
|
{"SCROLLLOCK", HID_KEYBOARD_SCROLL_LOCK},
|
||||||
{"SPACE", HID_KEYBOARD_SPACEBAR},
|
{"SPACE", HID_KEYBOARD_SPACEBAR},
|
||||||
{"TAB", HID_KEYBOARD_TAB},
|
{"TAB", HID_KEYBOARD_TAB},
|
||||||
{"MENU", HID_KEYBOARD_APPLICATION},
|
{"MENU", HID_KEYBOARD_APPLICATION},
|
||||||
@@ -524,12 +524,16 @@ static int32_t bad_usb_worker(void* context) {
|
|||||||
|
|
||||||
} else if(worker_state == BadUsbStateNotConnected) { // State: USB not connected
|
} else if(worker_state == BadUsbStateNotConnected) { // State: USB not connected
|
||||||
uint32_t flags = furi_thread_flags_wait(
|
uint32_t flags = furi_thread_flags_wait(
|
||||||
WorkerEvtEnd | WorkerEvtConnect, FuriFlagWaitAny, FuriWaitForever);
|
WorkerEvtEnd | WorkerEvtConnect | WorkerEvtToggle,
|
||||||
|
FuriFlagWaitAny,
|
||||||
|
FuriWaitForever);
|
||||||
furi_check((flags & FuriFlagError) == 0);
|
furi_check((flags & FuriFlagError) == 0);
|
||||||
if(flags & WorkerEvtEnd) {
|
if(flags & WorkerEvtEnd) {
|
||||||
break;
|
break;
|
||||||
} else if(flags & WorkerEvtConnect) {
|
} else if(flags & WorkerEvtConnect) {
|
||||||
worker_state = BadUsbStateIdle; // Ready to run
|
worker_state = BadUsbStateIdle; // Ready to run
|
||||||
|
} else if(flags & WorkerEvtToggle) {
|
||||||
|
worker_state = BadUsbStateWillRun; // Will run when USB is connected
|
||||||
}
|
}
|
||||||
bad_usb->st.state = worker_state;
|
bad_usb->st.state = worker_state;
|
||||||
|
|
||||||
@@ -556,6 +560,31 @@ static int32_t bad_usb_worker(void* context) {
|
|||||||
}
|
}
|
||||||
bad_usb->st.state = worker_state;
|
bad_usb->st.state = worker_state;
|
||||||
|
|
||||||
|
} else if(worker_state == BadUsbStateWillRun) { // State: start on connection
|
||||||
|
uint32_t flags = furi_thread_flags_wait(
|
||||||
|
WorkerEvtEnd | WorkerEvtConnect | WorkerEvtToggle,
|
||||||
|
FuriFlagWaitAny,
|
||||||
|
FuriWaitForever);
|
||||||
|
furi_check((flags & FuriFlagError) == 0);
|
||||||
|
if(flags & WorkerEvtEnd) {
|
||||||
|
break;
|
||||||
|
} else if(flags & WorkerEvtConnect) { // Start executing script
|
||||||
|
DOLPHIN_DEED(DolphinDeedBadUsbPlayScript);
|
||||||
|
delay_val = 0;
|
||||||
|
bad_usb->buf_len = 0;
|
||||||
|
bad_usb->st.line_cur = 0;
|
||||||
|
bad_usb->defdelay = 0;
|
||||||
|
bad_usb->repeat_cnt = 0;
|
||||||
|
bad_usb->file_end = false;
|
||||||
|
storage_file_seek(script_file, 0, true);
|
||||||
|
// extra time for PC to recognize Flipper as keyboard
|
||||||
|
furi_thread_flags_wait(0, FuriFlagWaitAny, 1500);
|
||||||
|
worker_state = BadUsbStateRunning;
|
||||||
|
} else if(flags & WorkerEvtToggle) { // Cancel scheduled execution
|
||||||
|
worker_state = BadUsbStateNotConnected;
|
||||||
|
}
|
||||||
|
bad_usb->st.state = worker_state;
|
||||||
|
|
||||||
} else if(worker_state == BadUsbStateRunning) { // State: running
|
} else if(worker_state == BadUsbStateRunning) { // State: running
|
||||||
uint16_t delay_cur = (delay_val > 1000) ? (1000) : (delay_val);
|
uint16_t delay_cur = (delay_val > 1000) ? (1000) : (delay_val);
|
||||||
uint32_t flags = furi_thread_flags_wait(
|
uint32_t flags = furi_thread_flags_wait(
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ typedef enum {
|
|||||||
BadUsbStateInit,
|
BadUsbStateInit,
|
||||||
BadUsbStateNotConnected,
|
BadUsbStateNotConnected,
|
||||||
BadUsbStateIdle,
|
BadUsbStateIdle,
|
||||||
|
BadUsbStateWillRun,
|
||||||
BadUsbStateRunning,
|
BadUsbStateRunning,
|
||||||
BadUsbStateDelay,
|
BadUsbStateDelay,
|
||||||
BadUsbStateDone,
|
BadUsbStateDone,
|
||||||
|
|||||||
@@ -29,10 +29,13 @@ static void bad_usb_draw_callback(Canvas* canvas, void* _model) {
|
|||||||
|
|
||||||
canvas_draw_icon(canvas, 22, 20, &I_UsbTree_48x22);
|
canvas_draw_icon(canvas, 22, 20, &I_UsbTree_48x22);
|
||||||
|
|
||||||
if((model->state.state == BadUsbStateIdle) || (model->state.state == BadUsbStateDone)) {
|
if((model->state.state == BadUsbStateIdle) || (model->state.state == BadUsbStateDone) ||
|
||||||
|
(model->state.state == BadUsbStateNotConnected)) {
|
||||||
elements_button_center(canvas, "Run");
|
elements_button_center(canvas, "Run");
|
||||||
} else if((model->state.state == BadUsbStateRunning) || (model->state.state == BadUsbStateDelay)) {
|
} else if((model->state.state == BadUsbStateRunning) || (model->state.state == BadUsbStateDelay)) {
|
||||||
elements_button_center(canvas, "Stop");
|
elements_button_center(canvas, "Stop");
|
||||||
|
} else if(model->state.state == BadUsbStateWillRun) {
|
||||||
|
elements_button_center(canvas, "Cancel");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(model->state.state == BadUsbStateNotConnected) {
|
if(model->state.state == BadUsbStateNotConnected) {
|
||||||
@@ -40,6 +43,11 @@ static void bad_usb_draw_callback(Canvas* canvas, void* _model) {
|
|||||||
canvas_set_font(canvas, FontPrimary);
|
canvas_set_font(canvas, FontPrimary);
|
||||||
canvas_draw_str_aligned(canvas, 127, 27, AlignRight, AlignBottom, "Connect");
|
canvas_draw_str_aligned(canvas, 127, 27, AlignRight, AlignBottom, "Connect");
|
||||||
canvas_draw_str_aligned(canvas, 127, 39, AlignRight, AlignBottom, "to USB");
|
canvas_draw_str_aligned(canvas, 127, 39, AlignRight, AlignBottom, "to USB");
|
||||||
|
} else if(model->state.state == BadUsbStateWillRun) {
|
||||||
|
canvas_draw_icon(canvas, 4, 22, &I_Clock_18x18);
|
||||||
|
canvas_set_font(canvas, FontPrimary);
|
||||||
|
canvas_draw_str_aligned(canvas, 127, 27, AlignRight, AlignBottom, "Will run");
|
||||||
|
canvas_draw_str_aligned(canvas, 127, 39, AlignRight, AlignBottom, "on connect");
|
||||||
} else if(model->state.state == BadUsbStateFileError) {
|
} else if(model->state.state == BadUsbStateFileError) {
|
||||||
canvas_draw_icon(canvas, 4, 22, &I_Error_18x18);
|
canvas_draw_icon(canvas, 4, 22, &I_Error_18x18);
|
||||||
canvas_set_font(canvas, FontPrimary);
|
canvas_set_font(canvas, FontPrimary);
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
#include "subghz_frequency_analyzer_log_item_array.h"
|
||||||
|
|
||||||
|
const char*
|
||||||
|
subghz_frequency_analyzer_log_get_order_name(SubGhzFrequencyAnalyzerLogOrderBy order_by) {
|
||||||
|
if(order_by == SubGhzFrequencyAnalyzerLogOrderBySeqAsc) {
|
||||||
|
return "Seq. A";
|
||||||
|
}
|
||||||
|
if(order_by == SubGhzFrequencyAnalyzerLogOrderByCountDesc) {
|
||||||
|
return "Count D";
|
||||||
|
}
|
||||||
|
if(order_by == SubGhzFrequencyAnalyzerLogOrderByCountAsc) {
|
||||||
|
return "Count A";
|
||||||
|
}
|
||||||
|
if(order_by == SubGhzFrequencyAnalyzerLogOrderByRSSIDesc) {
|
||||||
|
return "RSSI D";
|
||||||
|
}
|
||||||
|
if(order_by == SubGhzFrequencyAnalyzerLogOrderByRSSIAsc) {
|
||||||
|
return "RSSI A";
|
||||||
|
}
|
||||||
|
if(order_by == SubGhzFrequencyAnalyzerLogOrderByFrequencyDesc) {
|
||||||
|
return "Freq. D";
|
||||||
|
}
|
||||||
|
if(order_by == SubGhzFrequencyAnalyzerLogOrderByFrequencyAsc) {
|
||||||
|
return "Freq. A";
|
||||||
|
}
|
||||||
|
return "Seq. D";
|
||||||
|
}
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <m-tuple.h>
|
||||||
|
#include <m-array.h>
|
||||||
|
#include <m-algo.h>
|
||||||
|
#include <m-funcobj.h>
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
SubGhzFrequencyAnalyzerLogOrderBySeqDesc,
|
||||||
|
SubGhzFrequencyAnalyzerLogOrderBySeqAsc,
|
||||||
|
SubGhzFrequencyAnalyzerLogOrderByCountDesc,
|
||||||
|
SubGhzFrequencyAnalyzerLogOrderByCountAsc,
|
||||||
|
SubGhzFrequencyAnalyzerLogOrderByRSSIDesc,
|
||||||
|
SubGhzFrequencyAnalyzerLogOrderByRSSIAsc,
|
||||||
|
SubGhzFrequencyAnalyzerLogOrderByFrequencyDesc,
|
||||||
|
SubGhzFrequencyAnalyzerLogOrderByFrequencyAsc,
|
||||||
|
} SubGhzFrequencyAnalyzerLogOrderBy;
|
||||||
|
|
||||||
|
const char*
|
||||||
|
subghz_frequency_analyzer_log_get_order_name(SubGhzFrequencyAnalyzerLogOrderBy order_by);
|
||||||
|
|
||||||
|
TUPLE_DEF2(
|
||||||
|
SubGhzFrequencyAnalyzerLogItem,
|
||||||
|
(seq, uint8_t),
|
||||||
|
(frequency, uint32_t),
|
||||||
|
(count, uint8_t),
|
||||||
|
(rssi_max, uint8_t))
|
||||||
|
/* Register globaly the oplist */
|
||||||
|
#define M_OPL_SubGhzFrequencyAnalyzerLogItem_t() \
|
||||||
|
TUPLE_OPLIST(SubGhzFrequencyAnalyzerLogItem, M_POD_OPLIST, M_DEFAULT_OPLIST, M_DEFAULT_OPLIST)
|
||||||
|
|
||||||
|
/* Define the array, register the oplist and define further algorithms on it */
|
||||||
|
ARRAY_DEF(SubGhzFrequencyAnalyzerLogItemArray, SubGhzFrequencyAnalyzerLogItem_t)
|
||||||
|
#define M_OPL_SubGhzFrequencyAnalyzerLogItemArray_t() \
|
||||||
|
ARRAY_OPLIST(SubGhzFrequencyAnalyzerLogItemArray, M_OPL_SubGhzFrequencyAnalyzerLogItem_t())
|
||||||
|
ALGO_DEF(SubGhzFrequencyAnalyzerLogItemArray, SubGhzFrequencyAnalyzerLogItemArray_t)
|
||||||
|
|
||||||
|
FUNC_OBJ_INS_DEF(
|
||||||
|
SubGhzFrequencyAnalyzerLogItemArray_compare_by /* name of the instance */,
|
||||||
|
SubGhzFrequencyAnalyzerLogItemArray_cmp_obj /* name of the interface */,
|
||||||
|
(a,
|
||||||
|
b) /* name of the input parameters of the function like object. The type are inherited from the interface. */
|
||||||
|
,
|
||||||
|
{
|
||||||
|
/* code of the function object */
|
||||||
|
if(self->order_by == SubGhzFrequencyAnalyzerLogOrderByFrequencyAsc) {
|
||||||
|
return a->frequency < b->frequency ? -1 : a->frequency > b->frequency;
|
||||||
|
}
|
||||||
|
if(self->order_by == SubGhzFrequencyAnalyzerLogOrderByFrequencyDesc) {
|
||||||
|
return a->frequency > b->frequency ? -1 : a->frequency < b->frequency;
|
||||||
|
}
|
||||||
|
if(self->order_by == SubGhzFrequencyAnalyzerLogOrderByRSSIAsc) {
|
||||||
|
return a->rssi_max < b->rssi_max ? -1 : a->rssi_max > b->rssi_max;
|
||||||
|
}
|
||||||
|
if(self->order_by == SubGhzFrequencyAnalyzerLogOrderByRSSIDesc) {
|
||||||
|
return a->rssi_max > b->rssi_max ? -1 : a->rssi_max < b->rssi_max;
|
||||||
|
}
|
||||||
|
if(self->order_by == SubGhzFrequencyAnalyzerLogOrderByCountAsc) {
|
||||||
|
return a->count < b->count ? -1 : a->count > b->count;
|
||||||
|
}
|
||||||
|
if(self->order_by == SubGhzFrequencyAnalyzerLogOrderByCountDesc) {
|
||||||
|
return a->count > b->count ? -1 : a->count < b->count;
|
||||||
|
}
|
||||||
|
if(self->order_by == SubGhzFrequencyAnalyzerLogOrderBySeqAsc) {
|
||||||
|
return a->seq < b->seq ? -1 : a->seq > b->seq;
|
||||||
|
}
|
||||||
|
|
||||||
|
return a->seq > b->seq ? -1 : a->seq < b->seq;
|
||||||
|
},
|
||||||
|
/* Additional fields stored in the function object */
|
||||||
|
(order_by, SubGhzFrequencyAnalyzerLogOrderBy))
|
||||||
|
#define M_OPL_SubGhzFrequencyAnalyzerLogItemArray_compare_by_t() \
|
||||||
|
FUNC_OBJ_INS_OPLIST(SubGhzFrequencyAnalyzerLogItemArray_compare_by, M_DEFAULT_OPLIST)
|
||||||
@@ -155,9 +155,7 @@ bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event)
|
|||||||
} else if(event.event == SubGhzCustomEventSceneReceiverInfoSave) {
|
} else if(event.event == SubGhzCustomEventSceneReceiverInfoSave) {
|
||||||
//CC1101 Stop RX -> Save
|
//CC1101 Stop RX -> Save
|
||||||
subghz->state_notifications = SubGhzNotificationStateIDLE;
|
subghz->state_notifications = SubGhzNotificationStateIDLE;
|
||||||
if(subghz->txrx->hopper_state != SubGhzHopperStateOFF) {
|
subghz->txrx->hopper_state = SubGhzHopperStateOFF;
|
||||||
subghz->txrx->hopper_state = SubGhzHopperStateOFF;
|
|
||||||
}
|
|
||||||
if(subghz->txrx->txrx_state == SubGhzTxRxStateRx) {
|
if(subghz->txrx->txrx_state == SubGhzTxRxStateRx) {
|
||||||
subghz_rx_end(subghz);
|
subghz_rx_end(subghz);
|
||||||
subghz_sleep(subghz);
|
subghz_sleep(subghz);
|
||||||
|
|||||||
@@ -40,9 +40,8 @@ bool subghz_scene_rpc_on_event(void* context, SceneManagerEvent event) {
|
|||||||
bool result = false;
|
bool result = false;
|
||||||
if((subghz->txrx->txrx_state == SubGhzTxRxStateSleep) &&
|
if((subghz->txrx->txrx_state == SubGhzTxRxStateSleep) &&
|
||||||
(state == SubGhzRpcStateLoaded)) {
|
(state == SubGhzRpcStateLoaded)) {
|
||||||
subghz_blink_start(subghz);
|
|
||||||
result = subghz_tx_start(subghz, subghz->txrx->fff_data);
|
result = subghz_tx_start(subghz, subghz->txrx->fff_data);
|
||||||
result = true;
|
if(result) subghz_blink_start(subghz);
|
||||||
}
|
}
|
||||||
rpc_system_app_confirm(subghz->rpc_ctx, RpcAppEventButtonPress, result);
|
rpc_system_app_confirm(subghz->rpc_ctx, RpcAppEventButtonPress, result);
|
||||||
} else if(event.event == SubGhzCustomEventSceneRpcButtonRelease) {
|
} else if(event.event == SubGhzCustomEventSceneRpcButtonRelease) {
|
||||||
|
|||||||
@@ -5,30 +5,53 @@
|
|||||||
#include <furi.h>
|
#include <furi.h>
|
||||||
#include <furi_hal.h>
|
#include <furi_hal.h>
|
||||||
#include <input/input.h>
|
#include <input/input.h>
|
||||||
|
#include <gui/elements.h>
|
||||||
#include <notification/notification_messages.h>
|
#include <notification/notification_messages.h>
|
||||||
#include "../helpers/subghz_frequency_analyzer_worker.h"
|
#include "../helpers/subghz_frequency_analyzer_worker.h"
|
||||||
|
#include "../helpers/subghz_frequency_analyzer_log_item_array.h"
|
||||||
|
|
||||||
#include <assets_icons.h>
|
#include <assets_icons.h>
|
||||||
|
|
||||||
|
#define LOG_FREQUENCY_MAX_ITEMS 60 // uint8_t (limited by 'seq' of SubGhzFrequencyAnalyzerLogItem)
|
||||||
|
#define RSSI_OFFSET 74
|
||||||
|
#define RSSI_MAX 53 // 127 - RSSI_OFFSET
|
||||||
|
|
||||||
|
#define SNPRINTF_FREQUENCY(buff, freq) \
|
||||||
|
snprintf(buff, sizeof(buff), "%03ld.%03ld", freq / 1000000 % 1000, freq / 1000 % 1000);
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
SubGhzFrequencyAnalyzerStatusIDLE,
|
SubGhzFrequencyAnalyzerStatusIDLE,
|
||||||
} SubGhzFrequencyAnalyzerStatus;
|
} SubGhzFrequencyAnalyzerStatus;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
SubGhzFrequencyAnalyzerFragmentBottomTypeMain,
|
||||||
|
SubGhzFrequencyAnalyzerFragmentBottomTypeLog,
|
||||||
|
} SubGhzFrequencyAnalyzerFragmentBottomType;
|
||||||
|
|
||||||
struct SubGhzFrequencyAnalyzer {
|
struct SubGhzFrequencyAnalyzer {
|
||||||
View* view;
|
View* view;
|
||||||
SubGhzFrequencyAnalyzerWorker* worker;
|
SubGhzFrequencyAnalyzerWorker* worker;
|
||||||
SubGhzFrequencyAnalyzerCallback callback;
|
SubGhzFrequencyAnalyzerCallback callback;
|
||||||
void* context;
|
void* context;
|
||||||
bool locked;
|
bool locked;
|
||||||
|
uint32_t last_frequency;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t frequency;
|
uint32_t frequency;
|
||||||
float rssi;
|
uint8_t rssi;
|
||||||
uint32_t history_frequency[3];
|
uint32_t history_frequency[3];
|
||||||
bool signal;
|
bool signal;
|
||||||
|
SubGhzFrequencyAnalyzerLogItemArray_t log_frequency;
|
||||||
|
SubGhzFrequencyAnalyzerFragmentBottomType fragment_bottom_type;
|
||||||
|
SubGhzFrequencyAnalyzerLogOrderBy log_frequency_order_by;
|
||||||
|
uint8_t log_frequency_scroll_offset;
|
||||||
} SubGhzFrequencyAnalyzerModel;
|
} SubGhzFrequencyAnalyzerModel;
|
||||||
|
|
||||||
|
static inline uint8_t rssi_sanitize(float rssi) {
|
||||||
|
return (rssi * -1.0f) - RSSI_OFFSET;
|
||||||
|
}
|
||||||
|
|
||||||
void subghz_frequency_analyzer_set_callback(
|
void subghz_frequency_analyzer_set_callback(
|
||||||
SubGhzFrequencyAnalyzer* subghz_frequency_analyzer,
|
SubGhzFrequencyAnalyzer* subghz_frequency_analyzer,
|
||||||
SubGhzFrequencyAnalyzerCallback callback,
|
SubGhzFrequencyAnalyzerCallback callback,
|
||||||
@@ -39,13 +62,11 @@ void subghz_frequency_analyzer_set_callback(
|
|||||||
subghz_frequency_analyzer->context = context;
|
subghz_frequency_analyzer->context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
void subghz_frequency_analyzer_draw_rssi(Canvas* canvas, float rssi) {
|
void subghz_frequency_analyzer_draw_rssi(Canvas* canvas, uint8_t rssi, uint8_t x, uint8_t y) {
|
||||||
uint8_t x = 20;
|
|
||||||
uint8_t y = 64;
|
|
||||||
uint8_t column_number = 0;
|
uint8_t column_number = 0;
|
||||||
if(rssi) {
|
if(rssi) {
|
||||||
rssi = (rssi + 90) / 3;
|
rssi = rssi / 3;
|
||||||
for(size_t i = 1; i < (uint8_t)rssi; i++) {
|
for(uint8_t i = 1; i < rssi; i++) {
|
||||||
if(i > 20) break;
|
if(i > 20) break;
|
||||||
if(i % 4) {
|
if(i % 4) {
|
||||||
column_number++;
|
column_number++;
|
||||||
@@ -55,6 +76,54 @@ void subghz_frequency_analyzer_draw_rssi(Canvas* canvas, float rssi) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void subghz_frequency_analyzer_log_frequency_draw(
|
||||||
|
Canvas* canvas,
|
||||||
|
SubGhzFrequencyAnalyzerModel* model) {
|
||||||
|
char buffer[64];
|
||||||
|
const uint8_t offset_x = 0;
|
||||||
|
const uint8_t offset_y = 43;
|
||||||
|
canvas_set_font(canvas, FontKeyboard);
|
||||||
|
|
||||||
|
const size_t items_count = SubGhzFrequencyAnalyzerLogItemArray_size(model->log_frequency);
|
||||||
|
if(items_count == 0) {
|
||||||
|
canvas_draw_rframe(canvas, offset_x + 27u, offset_y - 3u, 73u, 16u, 5u);
|
||||||
|
canvas_draw_str_aligned(
|
||||||
|
canvas, offset_x + 64u, offset_y + 8u, AlignCenter, AlignBottom, "No records");
|
||||||
|
return;
|
||||||
|
} else if(items_count > 3) {
|
||||||
|
elements_scrollbar_pos(
|
||||||
|
canvas,
|
||||||
|
offset_x + 127,
|
||||||
|
offset_y - 8,
|
||||||
|
29,
|
||||||
|
model->log_frequency_scroll_offset,
|
||||||
|
items_count - 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
SubGhzFrequencyAnalyzerLogItem_t* log_frequency_item;
|
||||||
|
for(uint8_t i = 0; i < 3; ++i) {
|
||||||
|
const uint8_t item_pos = model->log_frequency_scroll_offset + i;
|
||||||
|
if(item_pos >= items_count) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
log_frequency_item =
|
||||||
|
SubGhzFrequencyAnalyzerLogItemArray_get(model->log_frequency, item_pos);
|
||||||
|
// Frequency
|
||||||
|
SNPRINTF_FREQUENCY(buffer, (*log_frequency_item)->frequency)
|
||||||
|
canvas_draw_str(canvas, offset_x, offset_y + i * 10, buffer);
|
||||||
|
|
||||||
|
// Count
|
||||||
|
snprintf(buffer, sizeof(buffer), "%3d", (*log_frequency_item)->count);
|
||||||
|
canvas_draw_str(canvas, offset_x + 48, offset_y + i * 10, buffer);
|
||||||
|
|
||||||
|
// Max RSSI
|
||||||
|
subghz_frequency_analyzer_draw_rssi(
|
||||||
|
canvas, (*log_frequency_item)->rssi_max, offset_x + 69, (offset_y + i * 10));
|
||||||
|
}
|
||||||
|
|
||||||
|
canvas_set_font(canvas, FontSecondary);
|
||||||
|
}
|
||||||
|
|
||||||
static void subghz_frequency_analyzer_history_frequency_draw(
|
static void subghz_frequency_analyzer_history_frequency_draw(
|
||||||
Canvas* canvas,
|
Canvas* canvas,
|
||||||
SubGhzFrequencyAnalyzerModel* model) {
|
SubGhzFrequencyAnalyzerModel* model) {
|
||||||
@@ -65,12 +134,7 @@ static void subghz_frequency_analyzer_history_frequency_draw(
|
|||||||
canvas_set_font(canvas, FontKeyboard);
|
canvas_set_font(canvas, FontKeyboard);
|
||||||
for(uint8_t i = 0; i < 3; i++) {
|
for(uint8_t i = 0; i < 3; i++) {
|
||||||
if(model->history_frequency[i]) {
|
if(model->history_frequency[i]) {
|
||||||
snprintf(
|
SNPRINTF_FREQUENCY(buffer, model->history_frequency[i])
|
||||||
buffer,
|
|
||||||
sizeof(buffer),
|
|
||||||
"%03ld.%03ld",
|
|
||||||
model->history_frequency[i] / 1000000 % 1000,
|
|
||||||
model->history_frequency[i] / 1000 % 1000);
|
|
||||||
canvas_draw_str(canvas, x, y + i * 10, buffer);
|
canvas_draw_str(canvas, x, y + i * 10, buffer);
|
||||||
} else {
|
} else {
|
||||||
canvas_draw_str(canvas, x, y + i * 10, "---.---");
|
canvas_draw_str(canvas, x, y + i * 10, "---.---");
|
||||||
@@ -81,18 +145,34 @@ static void subghz_frequency_analyzer_history_frequency_draw(
|
|||||||
}
|
}
|
||||||
|
|
||||||
void subghz_frequency_analyzer_draw(Canvas* canvas, SubGhzFrequencyAnalyzerModel* model) {
|
void subghz_frequency_analyzer_draw(Canvas* canvas, SubGhzFrequencyAnalyzerModel* model) {
|
||||||
|
furi_assert(canvas);
|
||||||
|
furi_assert(model);
|
||||||
char buffer[64];
|
char buffer[64];
|
||||||
|
|
||||||
canvas_set_color(canvas, ColorBlack);
|
canvas_set_color(canvas, ColorBlack);
|
||||||
canvas_set_font(canvas, FontSecondary);
|
canvas_set_font(canvas, FontSecondary);
|
||||||
canvas_draw_str(canvas, 20, 8, "Frequency Analyzer");
|
|
||||||
|
|
||||||
canvas_draw_str(canvas, 0, 64, "RSSI");
|
if(model->fragment_bottom_type == SubGhzFrequencyAnalyzerFragmentBottomTypeLog) {
|
||||||
subghz_frequency_analyzer_draw_rssi(canvas, model->rssi);
|
const size_t items_count = SubGhzFrequencyAnalyzerLogItemArray_size(model->log_frequency);
|
||||||
|
const char* log_order_by_name =
|
||||||
|
subghz_frequency_analyzer_log_get_order_name(model->log_frequency_order_by);
|
||||||
|
if(items_count < LOG_FREQUENCY_MAX_ITEMS) {
|
||||||
|
snprintf(buffer, sizeof(buffer), "Frequency Analyzer [%s]", log_order_by_name);
|
||||||
|
canvas_draw_str_aligned(canvas, 64, 8, AlignCenter, AlignBottom, buffer);
|
||||||
|
} else {
|
||||||
|
snprintf(buffer, sizeof(buffer), "The log is full! [%s]", log_order_by_name);
|
||||||
|
canvas_draw_str(canvas, 2, 8, buffer);
|
||||||
|
}
|
||||||
|
subghz_frequency_analyzer_log_frequency_draw(canvas, model);
|
||||||
|
} else {
|
||||||
|
canvas_draw_str(canvas, 20, 8, "Frequency Analyzer");
|
||||||
|
canvas_draw_str(canvas, 0, 64, "RSSI");
|
||||||
|
subghz_frequency_analyzer_draw_rssi(canvas, model->rssi, 20u, 64u);
|
||||||
|
|
||||||
subghz_frequency_analyzer_history_frequency_draw(canvas, model);
|
subghz_frequency_analyzer_history_frequency_draw(canvas, model);
|
||||||
|
}
|
||||||
|
|
||||||
//Frequency
|
// Frequency
|
||||||
canvas_set_font(canvas, FontBigNumbers);
|
canvas_set_font(canvas, FontBigNumbers);
|
||||||
snprintf(
|
snprintf(
|
||||||
buffer,
|
buffer,
|
||||||
@@ -103,23 +183,151 @@ void subghz_frequency_analyzer_draw(Canvas* canvas, SubGhzFrequencyAnalyzerModel
|
|||||||
if(model->signal) {
|
if(model->signal) {
|
||||||
canvas_draw_box(canvas, 4, 12, 121, 22);
|
canvas_draw_box(canvas, 4, 12, 121, 22);
|
||||||
canvas_set_color(canvas, ColorWhite);
|
canvas_set_color(canvas, ColorWhite);
|
||||||
} else {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
canvas_draw_str(canvas, 8, 30, buffer);
|
canvas_draw_str(canvas, 8, 30, buffer);
|
||||||
canvas_draw_icon(canvas, 96, 19, &I_MHz_25x11);
|
canvas_draw_icon(canvas, 96, 19, &I_MHz_25x11);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void subghz_frequency_analyzer_log_frequency_sort(SubGhzFrequencyAnalyzerModel* model) {
|
||||||
|
furi_assert(model);
|
||||||
|
M_LET((cmp, model->log_frequency_order_by), SubGhzFrequencyAnalyzerLogItemArray_compare_by_t)
|
||||||
|
SubGhzFrequencyAnalyzerLogItemArray_sort_fo(
|
||||||
|
model->log_frequency, SubGhzFrequencyAnalyzerLogItemArray_compare_by_as_interface(cmp));
|
||||||
|
}
|
||||||
|
|
||||||
bool subghz_frequency_analyzer_input(InputEvent* event, void* context) {
|
bool subghz_frequency_analyzer_input(InputEvent* event, void* context) {
|
||||||
furi_assert(context);
|
furi_assert(context);
|
||||||
|
SubGhzFrequencyAnalyzer* instance = context;
|
||||||
|
|
||||||
if(event->key == InputKeyBack) {
|
if(event->key == InputKeyBack) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if((event->type == InputTypeShort) &&
|
||||||
|
((event->key == InputKeyLeft) || (event->key == InputKeyRight))) {
|
||||||
|
with_view_model(
|
||||||
|
instance->view,
|
||||||
|
SubGhzFrequencyAnalyzerModel * model,
|
||||||
|
{
|
||||||
|
if(event->key == InputKeyLeft) {
|
||||||
|
if(model->fragment_bottom_type == 0) {
|
||||||
|
model->fragment_bottom_type = SubGhzFrequencyAnalyzerFragmentBottomTypeLog;
|
||||||
|
} else {
|
||||||
|
--model->fragment_bottom_type;
|
||||||
|
}
|
||||||
|
} else if(event->key == InputKeyRight) {
|
||||||
|
if(model->fragment_bottom_type ==
|
||||||
|
SubGhzFrequencyAnalyzerFragmentBottomTypeLog) {
|
||||||
|
model->fragment_bottom_type = 0;
|
||||||
|
} else {
|
||||||
|
++model->fragment_bottom_type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
true);
|
||||||
|
} else if((event->type == InputTypeShort) && (event->key == InputKeyOk)) {
|
||||||
|
with_view_model(
|
||||||
|
instance->view,
|
||||||
|
SubGhzFrequencyAnalyzerModel * model,
|
||||||
|
{
|
||||||
|
if(model->fragment_bottom_type == SubGhzFrequencyAnalyzerFragmentBottomTypeLog) {
|
||||||
|
++model->log_frequency_order_by;
|
||||||
|
if(model->log_frequency_order_by >
|
||||||
|
SubGhzFrequencyAnalyzerLogOrderByFrequencyAsc) {
|
||||||
|
model->log_frequency_order_by = 0;
|
||||||
|
}
|
||||||
|
subghz_frequency_analyzer_log_frequency_sort(model);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
true);
|
||||||
|
} else if((event->type == InputTypeShort) || (event->type == InputTypeRepeat)) {
|
||||||
|
with_view_model(
|
||||||
|
instance->view,
|
||||||
|
SubGhzFrequencyAnalyzerModel * model,
|
||||||
|
{
|
||||||
|
if(model->fragment_bottom_type == SubGhzFrequencyAnalyzerFragmentBottomTypeLog) {
|
||||||
|
if(event->key == InputKeyUp) {
|
||||||
|
if(model->log_frequency_scroll_offset > 0) {
|
||||||
|
--model->log_frequency_scroll_offset;
|
||||||
|
}
|
||||||
|
} else if(event->key == InputKeyDown) {
|
||||||
|
const size_t items_count =
|
||||||
|
SubGhzFrequencyAnalyzerLogItemArray_size(model->log_frequency);
|
||||||
|
if((model->log_frequency_scroll_offset + 3u) < items_count) {
|
||||||
|
++model->log_frequency_scroll_offset;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
true);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void subghz_frequency_analyzer_log_frequency_search_it(
|
||||||
|
SubGhzFrequencyAnalyzerLogItemArray_it_t* itref,
|
||||||
|
SubGhzFrequencyAnalyzerLogItemArray_t* log_frequency,
|
||||||
|
uint32_t frequency) {
|
||||||
|
furi_assert(log_frequency);
|
||||||
|
|
||||||
|
SubGhzFrequencyAnalyzerLogItemArray_it(*itref, *log_frequency);
|
||||||
|
SubGhzFrequencyAnalyzerLogItem_t* item;
|
||||||
|
while(!SubGhzFrequencyAnalyzerLogItemArray_end_p(*itref)) {
|
||||||
|
item = SubGhzFrequencyAnalyzerLogItemArray_ref(*itref);
|
||||||
|
if((*item)->frequency == frequency) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
SubGhzFrequencyAnalyzerLogItemArray_next(*itref);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool subghz_frequency_analyzer_log_frequency_insert(SubGhzFrequencyAnalyzerModel* model) {
|
||||||
|
furi_assert(model);
|
||||||
|
const size_t items_count = SubGhzFrequencyAnalyzerLogItemArray_size(model->log_frequency);
|
||||||
|
if(items_count < LOG_FREQUENCY_MAX_ITEMS) {
|
||||||
|
SubGhzFrequencyAnalyzerLogItem_t* item =
|
||||||
|
SubGhzFrequencyAnalyzerLogItemArray_push_new(model->log_frequency);
|
||||||
|
if(item == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
(*item)->frequency = model->frequency;
|
||||||
|
(*item)->count = 1u;
|
||||||
|
(*item)->rssi_max = model->rssi;
|
||||||
|
(*item)->seq = items_count;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void subghz_frequency_analyzer_log_frequency_update(
|
||||||
|
SubGhzFrequencyAnalyzerModel* model,
|
||||||
|
bool need_insert) {
|
||||||
|
furi_assert(model);
|
||||||
|
if(!model->frequency) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SubGhzFrequencyAnalyzerLogItemArray_it_t it;
|
||||||
|
subghz_frequency_analyzer_log_frequency_search_it(
|
||||||
|
&it, &model->log_frequency, model->frequency);
|
||||||
|
if(!SubGhzFrequencyAnalyzerLogItemArray_end_p(it)) {
|
||||||
|
SubGhzFrequencyAnalyzerLogItem_t* item = SubGhzFrequencyAnalyzerLogItemArray_ref(it);
|
||||||
|
if((*item)->rssi_max < model->rssi) {
|
||||||
|
(*item)->rssi_max = model->rssi;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(need_insert && (*item)->count < UINT8_MAX) {
|
||||||
|
++(*item)->count;
|
||||||
|
subghz_frequency_analyzer_log_frequency_sort(model);
|
||||||
|
}
|
||||||
|
} else if(need_insert) {
|
||||||
|
if(subghz_frequency_analyzer_log_frequency_insert(model)) {
|
||||||
|
subghz_frequency_analyzer_log_frequency_sort(model);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void subghz_frequency_analyzer_pair_callback(
|
void subghz_frequency_analyzer_pair_callback(
|
||||||
void* context,
|
void* context,
|
||||||
uint32_t frequency,
|
uint32_t frequency,
|
||||||
@@ -130,6 +338,7 @@ void subghz_frequency_analyzer_pair_callback(
|
|||||||
if(instance->callback) {
|
if(instance->callback) {
|
||||||
instance->callback(SubGhzCustomEventSceneAnalyzerUnlock, instance->context);
|
instance->callback(SubGhzCustomEventSceneAnalyzerUnlock, instance->context);
|
||||||
}
|
}
|
||||||
|
instance->last_frequency = 0;
|
||||||
//update history
|
//update history
|
||||||
with_view_model(
|
with_view_model(
|
||||||
instance->view,
|
instance->view,
|
||||||
@@ -151,9 +360,14 @@ void subghz_frequency_analyzer_pair_callback(
|
|||||||
instance->view,
|
instance->view,
|
||||||
SubGhzFrequencyAnalyzerModel * model,
|
SubGhzFrequencyAnalyzerModel * model,
|
||||||
{
|
{
|
||||||
model->rssi = rssi;
|
model->rssi = rssi_sanitize(rssi);
|
||||||
model->frequency = frequency;
|
model->frequency = frequency;
|
||||||
model->signal = signal;
|
model->signal = signal;
|
||||||
|
if(frequency) {
|
||||||
|
subghz_frequency_analyzer_log_frequency_update(
|
||||||
|
model, frequency != instance->last_frequency);
|
||||||
|
instance->last_frequency = frequency;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
true);
|
true);
|
||||||
}
|
}
|
||||||
@@ -176,11 +390,14 @@ void subghz_frequency_analyzer_enter(void* context) {
|
|||||||
instance->view,
|
instance->view,
|
||||||
SubGhzFrequencyAnalyzerModel * model,
|
SubGhzFrequencyAnalyzerModel * model,
|
||||||
{
|
{
|
||||||
model->rssi = 0;
|
model->rssi = 0u;
|
||||||
model->frequency = 0;
|
model->frequency = 0;
|
||||||
model->history_frequency[2] = 0;
|
model->fragment_bottom_type = SubGhzFrequencyAnalyzerFragmentBottomTypeMain;
|
||||||
model->history_frequency[1] = 0;
|
model->log_frequency_order_by = SubGhzFrequencyAnalyzerLogOrderBySeqDesc;
|
||||||
model->history_frequency[0] = 0;
|
model->log_frequency_scroll_offset = 0u;
|
||||||
|
model->history_frequency[0] = model->history_frequency[1] =
|
||||||
|
model->history_frequency[2] = 0u;
|
||||||
|
SubGhzFrequencyAnalyzerLogItemArray_init(model->log_frequency);
|
||||||
},
|
},
|
||||||
true);
|
true);
|
||||||
}
|
}
|
||||||
@@ -196,13 +413,26 @@ void subghz_frequency_analyzer_exit(void* context) {
|
|||||||
subghz_frequency_analyzer_worker_free(instance->worker);
|
subghz_frequency_analyzer_worker_free(instance->worker);
|
||||||
|
|
||||||
with_view_model(
|
with_view_model(
|
||||||
instance->view, SubGhzFrequencyAnalyzerModel * model, { model->rssi = 0; }, true);
|
instance->view,
|
||||||
|
SubGhzFrequencyAnalyzerModel * model,
|
||||||
|
{
|
||||||
|
model->rssi = 0u;
|
||||||
|
model->frequency = 0;
|
||||||
|
model->fragment_bottom_type = SubGhzFrequencyAnalyzerFragmentBottomTypeMain;
|
||||||
|
model->log_frequency_order_by = SubGhzFrequencyAnalyzerLogOrderBySeqDesc;
|
||||||
|
model->log_frequency_scroll_offset = 0u;
|
||||||
|
model->history_frequency[0] = model->history_frequency[1] =
|
||||||
|
model->history_frequency[2] = 0u;
|
||||||
|
SubGhzFrequencyAnalyzerLogItemArray_clear(model->log_frequency);
|
||||||
|
},
|
||||||
|
true);
|
||||||
}
|
}
|
||||||
|
|
||||||
SubGhzFrequencyAnalyzer* subghz_frequency_analyzer_alloc() {
|
SubGhzFrequencyAnalyzer* subghz_frequency_analyzer_alloc() {
|
||||||
SubGhzFrequencyAnalyzer* instance = malloc(sizeof(SubGhzFrequencyAnalyzer));
|
SubGhzFrequencyAnalyzer* instance = malloc(sizeof(SubGhzFrequencyAnalyzer));
|
||||||
|
|
||||||
// View allocation and configuration
|
// View allocation and configuration
|
||||||
|
instance->last_frequency = 0;
|
||||||
instance->view = view_alloc();
|
instance->view = view_alloc();
|
||||||
view_allocate_model(
|
view_allocate_model(
|
||||||
instance->view, ViewModelTypeLocking, sizeof(SubGhzFrequencyAnalyzerModel));
|
instance->view, ViewModelTypeLocking, sizeof(SubGhzFrequencyAnalyzerModel));
|
||||||
|
|||||||
@@ -72,8 +72,8 @@ void dap_scene_config_on_enter(void* context) {
|
|||||||
variable_item_set_current_value_index(item, config->uart_swap);
|
variable_item_set_current_value_index(item, config->uart_swap);
|
||||||
variable_item_set_current_value_text(item, uart_swap[config->uart_swap]);
|
variable_item_set_current_value_text(item, uart_swap[config->uart_swap]);
|
||||||
|
|
||||||
item = variable_item_list_add(var_item_list, "Help and Pinout", 0, NULL, NULL);
|
variable_item_list_add(var_item_list, "Help and Pinout", 0, NULL, NULL);
|
||||||
item = variable_item_list_add(var_item_list, "About", 0, NULL, NULL);
|
variable_item_list_add(var_item_list, "About", 0, NULL, NULL);
|
||||||
|
|
||||||
variable_item_list_set_selected_item(
|
variable_item_list_set_selected_item(
|
||||||
var_item_list, scene_manager_get_scene_state(app->scene_manager, DapSceneConfig));
|
var_item_list, scene_manager_get_scene_state(app->scene_manager, DapSceneConfig));
|
||||||
|
|||||||
20
applications/plugins/nfc_magic/application.fam
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
App(
|
||||||
|
appid="nfc_magic",
|
||||||
|
name="Nfc Magic",
|
||||||
|
apptype=FlipperAppType.EXTERNAL,
|
||||||
|
entry_point="nfc_magic_app",
|
||||||
|
requires=[
|
||||||
|
"storage",
|
||||||
|
"gui",
|
||||||
|
],
|
||||||
|
stack_size=4 * 1024,
|
||||||
|
order=30,
|
||||||
|
fap_icon="../../../assets/icons/Archive/125_10px.png",
|
||||||
|
fap_category="Tools",
|
||||||
|
fap_private_libs=[
|
||||||
|
Lib(
|
||||||
|
name="magic",
|
||||||
|
),
|
||||||
|
],
|
||||||
|
fap_icon_assets="assets",
|
||||||
|
)
|
||||||
BIN
applications/plugins/nfc_magic/assets/DolphinCommon_56x48.png
Normal file
|
After Width: | Height: | Size: 1.4 KiB |
BIN
applications/plugins/nfc_magic/assets/DolphinNice_96x59.png
Normal file
|
After Width: | Height: | Size: 2.4 KiB |
BIN
applications/plugins/nfc_magic/assets/Loading_24.png
Normal file
|
After Width: | Height: | Size: 3.6 KiB |
BIN
applications/plugins/nfc_magic/assets/NFC_manual_60x50.png
Normal file
|
After Width: | Height: | Size: 3.7 KiB |
214
applications/plugins/nfc_magic/lib/magic/magic.c
Normal file
@@ -0,0 +1,214 @@
|
|||||||
|
#include "magic.h"
|
||||||
|
|
||||||
|
#include <furi_hal_nfc.h>
|
||||||
|
|
||||||
|
#define TAG "Magic"
|
||||||
|
|
||||||
|
#define MAGIC_CMD_WUPA (0x40)
|
||||||
|
#define MAGIC_CMD_WIPE (0x41)
|
||||||
|
#define MAGIC_CMD_READ (0x43)
|
||||||
|
#define MAGIC_CMD_WRITE (0x43)
|
||||||
|
|
||||||
|
#define MAGIC_MIFARE_READ_CMD (0x30)
|
||||||
|
#define MAGIC_MIFARE_WRITE_CMD (0xA0)
|
||||||
|
|
||||||
|
#define MAGIC_ACK (0x0A)
|
||||||
|
|
||||||
|
#define MAGIC_BUFFER_SIZE (32)
|
||||||
|
|
||||||
|
bool magic_wupa() {
|
||||||
|
bool magic_activated = false;
|
||||||
|
uint8_t tx_data[MAGIC_BUFFER_SIZE] = {};
|
||||||
|
uint8_t rx_data[MAGIC_BUFFER_SIZE] = {};
|
||||||
|
uint16_t rx_len = 0;
|
||||||
|
FuriHalNfcReturn ret = 0;
|
||||||
|
|
||||||
|
do {
|
||||||
|
// Setup nfc poller
|
||||||
|
furi_hal_nfc_exit_sleep();
|
||||||
|
furi_hal_nfc_ll_txrx_on();
|
||||||
|
furi_hal_nfc_ll_poll();
|
||||||
|
ret = furi_hal_nfc_ll_set_mode(
|
||||||
|
FuriHalNfcModePollNfca, FuriHalNfcBitrate106, FuriHalNfcBitrate106);
|
||||||
|
if(ret != FuriHalNfcReturnOk) break;
|
||||||
|
|
||||||
|
furi_hal_nfc_ll_set_fdt_listen(FURI_HAL_NFC_LL_FDT_LISTEN_NFCA_POLLER);
|
||||||
|
furi_hal_nfc_ll_set_fdt_poll(FURI_HAL_NFC_LL_FDT_POLL_NFCA_POLLER);
|
||||||
|
furi_hal_nfc_ll_set_error_handling(FuriHalNfcErrorHandlingNfc);
|
||||||
|
furi_hal_nfc_ll_set_guard_time(FURI_HAL_NFC_LL_GT_NFCA);
|
||||||
|
|
||||||
|
// Start communication
|
||||||
|
tx_data[0] = MAGIC_CMD_WUPA;
|
||||||
|
ret = furi_hal_nfc_ll_txrx_bits(
|
||||||
|
tx_data,
|
||||||
|
7,
|
||||||
|
rx_data,
|
||||||
|
sizeof(rx_data),
|
||||||
|
&rx_len,
|
||||||
|
FURI_HAL_NFC_LL_TXRX_FLAGS_CRC_TX_MANUAL | FURI_HAL_NFC_LL_TXRX_FLAGS_AGC_ON |
|
||||||
|
FURI_HAL_NFC_LL_TXRX_FLAGS_CRC_RX_KEEP,
|
||||||
|
furi_hal_nfc_ll_ms2fc(20));
|
||||||
|
if(ret != FuriHalNfcReturnIncompleteByte) break;
|
||||||
|
if(rx_len != 4) break;
|
||||||
|
if(rx_data[0] != MAGIC_ACK) break;
|
||||||
|
magic_activated = true;
|
||||||
|
} while(false);
|
||||||
|
|
||||||
|
if(!magic_activated) {
|
||||||
|
furi_hal_nfc_ll_txrx_off();
|
||||||
|
furi_hal_nfc_start_sleep();
|
||||||
|
}
|
||||||
|
|
||||||
|
return magic_activated;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool magic_data_access_cmd() {
|
||||||
|
bool write_cmd_success = false;
|
||||||
|
uint8_t tx_data[MAGIC_BUFFER_SIZE] = {};
|
||||||
|
uint8_t rx_data[MAGIC_BUFFER_SIZE] = {};
|
||||||
|
uint16_t rx_len = 0;
|
||||||
|
FuriHalNfcReturn ret = 0;
|
||||||
|
|
||||||
|
do {
|
||||||
|
tx_data[0] = MAGIC_CMD_WRITE;
|
||||||
|
ret = furi_hal_nfc_ll_txrx_bits(
|
||||||
|
tx_data,
|
||||||
|
8,
|
||||||
|
rx_data,
|
||||||
|
sizeof(rx_data),
|
||||||
|
&rx_len,
|
||||||
|
FURI_HAL_NFC_LL_TXRX_FLAGS_CRC_TX_MANUAL | FURI_HAL_NFC_LL_TXRX_FLAGS_AGC_ON |
|
||||||
|
FURI_HAL_NFC_LL_TXRX_FLAGS_CRC_RX_KEEP,
|
||||||
|
furi_hal_nfc_ll_ms2fc(20));
|
||||||
|
if(ret != FuriHalNfcReturnIncompleteByte) break;
|
||||||
|
if(rx_len != 4) break;
|
||||||
|
if(rx_data[0] != MAGIC_ACK) break;
|
||||||
|
|
||||||
|
write_cmd_success = true;
|
||||||
|
} while(false);
|
||||||
|
|
||||||
|
if(!write_cmd_success) {
|
||||||
|
furi_hal_nfc_ll_txrx_off();
|
||||||
|
furi_hal_nfc_start_sleep();
|
||||||
|
}
|
||||||
|
|
||||||
|
return write_cmd_success;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool magic_read_block(uint8_t block_num, MfClassicBlock* data) {
|
||||||
|
furi_assert(data);
|
||||||
|
|
||||||
|
bool read_success = false;
|
||||||
|
|
||||||
|
uint8_t tx_data[MAGIC_BUFFER_SIZE] = {};
|
||||||
|
uint8_t rx_data[MAGIC_BUFFER_SIZE] = {};
|
||||||
|
uint16_t rx_len = 0;
|
||||||
|
FuriHalNfcReturn ret = 0;
|
||||||
|
|
||||||
|
do {
|
||||||
|
tx_data[0] = MAGIC_MIFARE_READ_CMD;
|
||||||
|
tx_data[1] = block_num;
|
||||||
|
ret = furi_hal_nfc_ll_txrx_bits(
|
||||||
|
tx_data,
|
||||||
|
2 * 8,
|
||||||
|
rx_data,
|
||||||
|
sizeof(rx_data),
|
||||||
|
&rx_len,
|
||||||
|
FURI_HAL_NFC_LL_TXRX_FLAGS_AGC_ON,
|
||||||
|
furi_hal_nfc_ll_ms2fc(20));
|
||||||
|
|
||||||
|
if(ret != FuriHalNfcReturnOk) break;
|
||||||
|
if(rx_len != 16 * 8) break;
|
||||||
|
memcpy(data->value, rx_data, sizeof(data->value));
|
||||||
|
read_success = true;
|
||||||
|
} while(false);
|
||||||
|
|
||||||
|
if(!read_success) {
|
||||||
|
furi_hal_nfc_ll_txrx_off();
|
||||||
|
furi_hal_nfc_start_sleep();
|
||||||
|
}
|
||||||
|
|
||||||
|
return read_success;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool magic_write_blk(uint8_t block_num, MfClassicBlock* data) {
|
||||||
|
furi_assert(data);
|
||||||
|
|
||||||
|
bool write_success = false;
|
||||||
|
uint8_t tx_data[MAGIC_BUFFER_SIZE] = {};
|
||||||
|
uint8_t rx_data[MAGIC_BUFFER_SIZE] = {};
|
||||||
|
uint16_t rx_len = 0;
|
||||||
|
FuriHalNfcReturn ret = 0;
|
||||||
|
|
||||||
|
do {
|
||||||
|
tx_data[0] = MAGIC_MIFARE_WRITE_CMD;
|
||||||
|
tx_data[1] = block_num;
|
||||||
|
ret = furi_hal_nfc_ll_txrx_bits(
|
||||||
|
tx_data,
|
||||||
|
2 * 8,
|
||||||
|
rx_data,
|
||||||
|
sizeof(rx_data),
|
||||||
|
&rx_len,
|
||||||
|
FURI_HAL_NFC_LL_TXRX_FLAGS_AGC_ON | FURI_HAL_NFC_LL_TXRX_FLAGS_CRC_RX_KEEP,
|
||||||
|
furi_hal_nfc_ll_ms2fc(20));
|
||||||
|
if(ret != FuriHalNfcReturnIncompleteByte) break;
|
||||||
|
if(rx_len != 4) break;
|
||||||
|
if(rx_data[0] != MAGIC_ACK) break;
|
||||||
|
|
||||||
|
memcpy(tx_data, data->value, sizeof(data->value));
|
||||||
|
ret = furi_hal_nfc_ll_txrx_bits(
|
||||||
|
tx_data,
|
||||||
|
16 * 8,
|
||||||
|
rx_data,
|
||||||
|
sizeof(rx_data),
|
||||||
|
&rx_len,
|
||||||
|
FURI_HAL_NFC_LL_TXRX_FLAGS_AGC_ON | FURI_HAL_NFC_LL_TXRX_FLAGS_CRC_RX_KEEP,
|
||||||
|
furi_hal_nfc_ll_ms2fc(20));
|
||||||
|
if(ret != FuriHalNfcReturnIncompleteByte) break;
|
||||||
|
if(rx_len != 4) break;
|
||||||
|
if(rx_data[0] != MAGIC_ACK) break;
|
||||||
|
|
||||||
|
write_success = true;
|
||||||
|
} while(false);
|
||||||
|
|
||||||
|
if(!write_success) {
|
||||||
|
furi_hal_nfc_ll_txrx_off();
|
||||||
|
furi_hal_nfc_start_sleep();
|
||||||
|
}
|
||||||
|
|
||||||
|
return write_success;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool magic_wipe() {
|
||||||
|
bool wipe_success = false;
|
||||||
|
uint8_t tx_data[MAGIC_BUFFER_SIZE] = {};
|
||||||
|
uint8_t rx_data[MAGIC_BUFFER_SIZE] = {};
|
||||||
|
uint16_t rx_len = 0;
|
||||||
|
FuriHalNfcReturn ret = 0;
|
||||||
|
|
||||||
|
do {
|
||||||
|
tx_data[0] = MAGIC_CMD_WIPE;
|
||||||
|
ret = furi_hal_nfc_ll_txrx_bits(
|
||||||
|
tx_data,
|
||||||
|
8,
|
||||||
|
rx_data,
|
||||||
|
sizeof(rx_data),
|
||||||
|
&rx_len,
|
||||||
|
FURI_HAL_NFC_LL_TXRX_FLAGS_CRC_TX_MANUAL | FURI_HAL_NFC_LL_TXRX_FLAGS_AGC_ON |
|
||||||
|
FURI_HAL_NFC_LL_TXRX_FLAGS_CRC_RX_KEEP,
|
||||||
|
furi_hal_nfc_ll_ms2fc(2000));
|
||||||
|
|
||||||
|
if(ret != FuriHalNfcReturnIncompleteByte) break;
|
||||||
|
if(rx_len != 4) break;
|
||||||
|
if(rx_data[0] != MAGIC_ACK) break;
|
||||||
|
|
||||||
|
wipe_success = true;
|
||||||
|
} while(false);
|
||||||
|
|
||||||
|
return wipe_success;
|
||||||
|
}
|
||||||
|
|
||||||
|
void magic_deactivate() {
|
||||||
|
furi_hal_nfc_ll_txrx_off();
|
||||||
|
furi_hal_nfc_start_sleep();
|
||||||
|
}
|
||||||
15
applications/plugins/nfc_magic/lib/magic/magic.h
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <lib/nfc/protocols/mifare_classic.h>
|
||||||
|
|
||||||
|
bool magic_wupa();
|
||||||
|
|
||||||
|
bool magic_read_block(uint8_t block_num, MfClassicBlock* data);
|
||||||
|
|
||||||
|
bool magic_data_access_cmd();
|
||||||
|
|
||||||
|
bool magic_write_blk(uint8_t block_num, MfClassicBlock* data);
|
||||||
|
|
||||||
|
bool magic_wipe();
|
||||||
|
|
||||||
|
void magic_deactivate();
|
||||||
169
applications/plugins/nfc_magic/nfc_magic.c
Normal file
@@ -0,0 +1,169 @@
|
|||||||
|
#include "nfc_magic_i.h"
|
||||||
|
|
||||||
|
bool nfc_magic_custom_event_callback(void* context, uint32_t event) {
|
||||||
|
furi_assert(context);
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
return scene_manager_handle_custom_event(nfc_magic->scene_manager, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool nfc_magic_back_event_callback(void* context) {
|
||||||
|
furi_assert(context);
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
return scene_manager_handle_back_event(nfc_magic->scene_manager);
|
||||||
|
}
|
||||||
|
|
||||||
|
void nfc_magic_tick_event_callback(void* context) {
|
||||||
|
furi_assert(context);
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
scene_manager_handle_tick_event(nfc_magic->scene_manager);
|
||||||
|
}
|
||||||
|
|
||||||
|
void nfc_magic_show_loading_popup(void* context, bool show) {
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
TaskHandle_t timer_task = xTaskGetHandle(configTIMER_SERVICE_TASK_NAME);
|
||||||
|
|
||||||
|
if(show) {
|
||||||
|
// Raise timer priority so that animations can play
|
||||||
|
vTaskPrioritySet(timer_task, configMAX_PRIORITIES - 1);
|
||||||
|
view_dispatcher_switch_to_view(nfc_magic->view_dispatcher, NfcMagicViewLoading);
|
||||||
|
} else {
|
||||||
|
// Restore default timer priority
|
||||||
|
vTaskPrioritySet(timer_task, configTIMER_TASK_PRIORITY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
NfcMagic* nfc_magic_alloc() {
|
||||||
|
NfcMagic* nfc_magic = malloc(sizeof(NfcMagic));
|
||||||
|
|
||||||
|
nfc_magic->worker = nfc_magic_worker_alloc();
|
||||||
|
nfc_magic->view_dispatcher = view_dispatcher_alloc();
|
||||||
|
nfc_magic->scene_manager = scene_manager_alloc(&nfc_magic_scene_handlers, nfc_magic);
|
||||||
|
view_dispatcher_enable_queue(nfc_magic->view_dispatcher);
|
||||||
|
view_dispatcher_set_event_callback_context(nfc_magic->view_dispatcher, nfc_magic);
|
||||||
|
view_dispatcher_set_custom_event_callback(
|
||||||
|
nfc_magic->view_dispatcher, nfc_magic_custom_event_callback);
|
||||||
|
view_dispatcher_set_navigation_event_callback(
|
||||||
|
nfc_magic->view_dispatcher, nfc_magic_back_event_callback);
|
||||||
|
view_dispatcher_set_tick_event_callback(
|
||||||
|
nfc_magic->view_dispatcher, nfc_magic_tick_event_callback, 100);
|
||||||
|
|
||||||
|
// Nfc device
|
||||||
|
nfc_magic->nfc_dev = nfc_device_alloc();
|
||||||
|
|
||||||
|
// Open GUI record
|
||||||
|
nfc_magic->gui = furi_record_open(RECORD_GUI);
|
||||||
|
view_dispatcher_attach_to_gui(
|
||||||
|
nfc_magic->view_dispatcher, nfc_magic->gui, ViewDispatcherTypeFullscreen);
|
||||||
|
|
||||||
|
// Open Notification record
|
||||||
|
nfc_magic->notifications = furi_record_open(RECORD_NOTIFICATION);
|
||||||
|
|
||||||
|
// Submenu
|
||||||
|
nfc_magic->submenu = submenu_alloc();
|
||||||
|
view_dispatcher_add_view(
|
||||||
|
nfc_magic->view_dispatcher, NfcMagicViewMenu, submenu_get_view(nfc_magic->submenu));
|
||||||
|
|
||||||
|
// Popup
|
||||||
|
nfc_magic->popup = popup_alloc();
|
||||||
|
view_dispatcher_add_view(
|
||||||
|
nfc_magic->view_dispatcher, NfcMagicViewPopup, popup_get_view(nfc_magic->popup));
|
||||||
|
|
||||||
|
// Loading
|
||||||
|
nfc_magic->loading = loading_alloc();
|
||||||
|
view_dispatcher_add_view(
|
||||||
|
nfc_magic->view_dispatcher, NfcMagicViewLoading, loading_get_view(nfc_magic->loading));
|
||||||
|
|
||||||
|
// Text Input
|
||||||
|
nfc_magic->text_input = text_input_alloc();
|
||||||
|
view_dispatcher_add_view(
|
||||||
|
nfc_magic->view_dispatcher,
|
||||||
|
NfcMagicViewTextInput,
|
||||||
|
text_input_get_view(nfc_magic->text_input));
|
||||||
|
|
||||||
|
// Custom Widget
|
||||||
|
nfc_magic->widget = widget_alloc();
|
||||||
|
view_dispatcher_add_view(
|
||||||
|
nfc_magic->view_dispatcher, NfcMagicViewWidget, widget_get_view(nfc_magic->widget));
|
||||||
|
|
||||||
|
return nfc_magic;
|
||||||
|
}
|
||||||
|
|
||||||
|
void nfc_magic_free(NfcMagic* nfc_magic) {
|
||||||
|
furi_assert(nfc_magic);
|
||||||
|
|
||||||
|
// Nfc device
|
||||||
|
nfc_device_free(nfc_magic->nfc_dev);
|
||||||
|
|
||||||
|
// Submenu
|
||||||
|
view_dispatcher_remove_view(nfc_magic->view_dispatcher, NfcMagicViewMenu);
|
||||||
|
submenu_free(nfc_magic->submenu);
|
||||||
|
|
||||||
|
// Popup
|
||||||
|
view_dispatcher_remove_view(nfc_magic->view_dispatcher, NfcMagicViewPopup);
|
||||||
|
popup_free(nfc_magic->popup);
|
||||||
|
|
||||||
|
// Loading
|
||||||
|
view_dispatcher_remove_view(nfc_magic->view_dispatcher, NfcMagicViewLoading);
|
||||||
|
loading_free(nfc_magic->loading);
|
||||||
|
|
||||||
|
// TextInput
|
||||||
|
view_dispatcher_remove_view(nfc_magic->view_dispatcher, NfcMagicViewTextInput);
|
||||||
|
text_input_free(nfc_magic->text_input);
|
||||||
|
|
||||||
|
// Custom Widget
|
||||||
|
view_dispatcher_remove_view(nfc_magic->view_dispatcher, NfcMagicViewWidget);
|
||||||
|
widget_free(nfc_magic->widget);
|
||||||
|
|
||||||
|
// Worker
|
||||||
|
nfc_magic_worker_stop(nfc_magic->worker);
|
||||||
|
nfc_magic_worker_free(nfc_magic->worker);
|
||||||
|
|
||||||
|
// View Dispatcher
|
||||||
|
view_dispatcher_free(nfc_magic->view_dispatcher);
|
||||||
|
|
||||||
|
// Scene Manager
|
||||||
|
scene_manager_free(nfc_magic->scene_manager);
|
||||||
|
|
||||||
|
// GUI
|
||||||
|
furi_record_close(RECORD_GUI);
|
||||||
|
nfc_magic->gui = NULL;
|
||||||
|
|
||||||
|
// Notifications
|
||||||
|
furi_record_close(RECORD_NOTIFICATION);
|
||||||
|
nfc_magic->notifications = NULL;
|
||||||
|
|
||||||
|
free(nfc_magic);
|
||||||
|
}
|
||||||
|
|
||||||
|
static const NotificationSequence nfc_magic_sequence_blink_start_blue = {
|
||||||
|
&message_blink_start_10,
|
||||||
|
&message_blink_set_color_blue,
|
||||||
|
&message_do_not_reset,
|
||||||
|
NULL,
|
||||||
|
};
|
||||||
|
|
||||||
|
static const NotificationSequence nfc_magic_sequence_blink_stop = {
|
||||||
|
&message_blink_stop,
|
||||||
|
NULL,
|
||||||
|
};
|
||||||
|
|
||||||
|
void nfc_magic_blink_start(NfcMagic* nfc_magic) {
|
||||||
|
notification_message(nfc_magic->notifications, &nfc_magic_sequence_blink_start_blue);
|
||||||
|
}
|
||||||
|
|
||||||
|
void nfc_magic_blink_stop(NfcMagic* nfc_magic) {
|
||||||
|
notification_message(nfc_magic->notifications, &nfc_magic_sequence_blink_stop);
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t nfc_magic_app(void* p) {
|
||||||
|
UNUSED(p);
|
||||||
|
NfcMagic* nfc_magic = nfc_magic_alloc();
|
||||||
|
|
||||||
|
scene_manager_next_scene(nfc_magic->scene_manager, NfcMagicSceneStart);
|
||||||
|
|
||||||
|
view_dispatcher_run(nfc_magic->view_dispatcher);
|
||||||
|
|
||||||
|
nfc_magic_free(nfc_magic);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
3
applications/plugins/nfc_magic/nfc_magic.h
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
typedef struct NfcMagic NfcMagic;
|
||||||
77
applications/plugins/nfc_magic/nfc_magic_i.h
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "nfc_magic.h"
|
||||||
|
#include "nfc_magic_worker.h"
|
||||||
|
|
||||||
|
#include "lib/magic/magic.h"
|
||||||
|
|
||||||
|
#include <furi.h>
|
||||||
|
#include <gui/gui.h>
|
||||||
|
#include <gui/view_dispatcher.h>
|
||||||
|
#include <gui/scene_manager.h>
|
||||||
|
#include <notification/notification_messages.h>
|
||||||
|
|
||||||
|
#include <gui/modules/submenu.h>
|
||||||
|
#include <gui/modules/popup.h>
|
||||||
|
#include <gui/modules/loading.h>
|
||||||
|
#include <gui/modules/text_input.h>
|
||||||
|
#include <gui/modules/widget.h>
|
||||||
|
|
||||||
|
#include <input/input.h>
|
||||||
|
|
||||||
|
#include "scenes/nfc_magic_scene.h"
|
||||||
|
|
||||||
|
#include <storage/storage.h>
|
||||||
|
#include <lib/toolbox/path.h>
|
||||||
|
|
||||||
|
#include <lib/nfc/nfc_device.h>
|
||||||
|
#include "nfc_magic_icons.h"
|
||||||
|
|
||||||
|
enum NfcMagicCustomEvent {
|
||||||
|
// Reserve first 100 events for button types and indexes, starting from 0
|
||||||
|
NfcMagicCustomEventReserved = 100,
|
||||||
|
|
||||||
|
NfcMagicCustomEventViewExit,
|
||||||
|
NfcMagicCustomEventWorkerExit,
|
||||||
|
NfcMagicCustomEventByteInputDone,
|
||||||
|
NfcMagicCustomEventTextInputDone,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct NfcMagic {
|
||||||
|
NfcMagicWorker* worker;
|
||||||
|
ViewDispatcher* view_dispatcher;
|
||||||
|
Gui* gui;
|
||||||
|
NotificationApp* notifications;
|
||||||
|
SceneManager* scene_manager;
|
||||||
|
// NfcMagicDevice* dev;
|
||||||
|
NfcDevice* nfc_dev;
|
||||||
|
|
||||||
|
FuriString* text_box_store;
|
||||||
|
|
||||||
|
// Common Views
|
||||||
|
Submenu* submenu;
|
||||||
|
Popup* popup;
|
||||||
|
Loading* loading;
|
||||||
|
TextInput* text_input;
|
||||||
|
Widget* widget;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
NfcMagicViewMenu,
|
||||||
|
NfcMagicViewPopup,
|
||||||
|
NfcMagicViewLoading,
|
||||||
|
NfcMagicViewTextInput,
|
||||||
|
NfcMagicViewWidget,
|
||||||
|
} NfcMagicView;
|
||||||
|
|
||||||
|
NfcMagic* nfc_magic_alloc();
|
||||||
|
|
||||||
|
void nfc_magic_text_store_set(NfcMagic* nfc_magic, const char* text, ...);
|
||||||
|
|
||||||
|
void nfc_magic_text_store_clear(NfcMagic* nfc_magic);
|
||||||
|
|
||||||
|
void nfc_magic_blink_start(NfcMagic* nfc_magic);
|
||||||
|
|
||||||
|
void nfc_magic_blink_stop(NfcMagic* nfc_magic);
|
||||||
|
|
||||||
|
void nfc_magic_show_loading_popup(void* context, bool show);
|
||||||
174
applications/plugins/nfc_magic/nfc_magic_worker.c
Normal file
@@ -0,0 +1,174 @@
|
|||||||
|
#include "nfc_magic_worker_i.h"
|
||||||
|
|
||||||
|
#include "lib/magic/magic.h"
|
||||||
|
|
||||||
|
#define TAG "NfcMagicWorker"
|
||||||
|
|
||||||
|
static void
|
||||||
|
nfc_magic_worker_change_state(NfcMagicWorker* nfc_magic_worker, NfcMagicWorkerState state) {
|
||||||
|
furi_assert(nfc_magic_worker);
|
||||||
|
|
||||||
|
nfc_magic_worker->state = state;
|
||||||
|
}
|
||||||
|
|
||||||
|
NfcMagicWorker* nfc_magic_worker_alloc() {
|
||||||
|
NfcMagicWorker* nfc_magic_worker = malloc(sizeof(NfcMagicWorker));
|
||||||
|
|
||||||
|
// Worker thread attributes
|
||||||
|
nfc_magic_worker->thread = furi_thread_alloc();
|
||||||
|
furi_thread_set_name(nfc_magic_worker->thread, "NfcMagicWorker");
|
||||||
|
furi_thread_set_stack_size(nfc_magic_worker->thread, 8192);
|
||||||
|
furi_thread_set_callback(nfc_magic_worker->thread, nfc_magic_worker_task);
|
||||||
|
furi_thread_set_context(nfc_magic_worker->thread, nfc_magic_worker);
|
||||||
|
|
||||||
|
nfc_magic_worker->callback = NULL;
|
||||||
|
nfc_magic_worker->context = NULL;
|
||||||
|
|
||||||
|
nfc_magic_worker_change_state(nfc_magic_worker, NfcMagicWorkerStateReady);
|
||||||
|
|
||||||
|
return nfc_magic_worker;
|
||||||
|
}
|
||||||
|
|
||||||
|
void nfc_magic_worker_free(NfcMagicWorker* nfc_magic_worker) {
|
||||||
|
furi_assert(nfc_magic_worker);
|
||||||
|
|
||||||
|
furi_thread_free(nfc_magic_worker->thread);
|
||||||
|
free(nfc_magic_worker);
|
||||||
|
}
|
||||||
|
|
||||||
|
void nfc_magic_worker_stop(NfcMagicWorker* nfc_magic_worker) {
|
||||||
|
furi_assert(nfc_magic_worker);
|
||||||
|
|
||||||
|
nfc_magic_worker_change_state(nfc_magic_worker, NfcMagicWorkerStateStop);
|
||||||
|
furi_thread_join(nfc_magic_worker->thread);
|
||||||
|
}
|
||||||
|
|
||||||
|
void nfc_magic_worker_start(
|
||||||
|
NfcMagicWorker* nfc_magic_worker,
|
||||||
|
NfcMagicWorkerState state,
|
||||||
|
NfcDeviceData* dev_data,
|
||||||
|
NfcMagicWorkerCallback callback,
|
||||||
|
void* context) {
|
||||||
|
furi_assert(nfc_magic_worker);
|
||||||
|
furi_assert(dev_data);
|
||||||
|
|
||||||
|
nfc_magic_worker->callback = callback;
|
||||||
|
nfc_magic_worker->context = context;
|
||||||
|
nfc_magic_worker->dev_data = dev_data;
|
||||||
|
nfc_magic_worker_change_state(nfc_magic_worker, state);
|
||||||
|
furi_thread_start(nfc_magic_worker->thread);
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t nfc_magic_worker_task(void* context) {
|
||||||
|
NfcMagicWorker* nfc_magic_worker = context;
|
||||||
|
|
||||||
|
if(nfc_magic_worker->state == NfcMagicWorkerStateCheck) {
|
||||||
|
nfc_magic_worker_check(nfc_magic_worker);
|
||||||
|
} else if(nfc_magic_worker->state == NfcMagicWorkerStateWrite) {
|
||||||
|
nfc_magic_worker_write(nfc_magic_worker);
|
||||||
|
} else if(nfc_magic_worker->state == NfcMagicWorkerStateWipe) {
|
||||||
|
nfc_magic_worker_wipe(nfc_magic_worker);
|
||||||
|
}
|
||||||
|
|
||||||
|
nfc_magic_worker_change_state(nfc_magic_worker, NfcMagicWorkerStateReady);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void nfc_magic_worker_write(NfcMagicWorker* nfc_magic_worker) {
|
||||||
|
bool card_found_notified = false;
|
||||||
|
FuriHalNfcDevData nfc_data = {};
|
||||||
|
MfClassicData* src_data = &nfc_magic_worker->dev_data->mf_classic_data;
|
||||||
|
|
||||||
|
while(nfc_magic_worker->state == NfcMagicWorkerStateWrite) {
|
||||||
|
if(furi_hal_nfc_detect(&nfc_data, 200)) {
|
||||||
|
if(!card_found_notified) {
|
||||||
|
nfc_magic_worker->callback(
|
||||||
|
NfcMagicWorkerEventCardDetected, nfc_magic_worker->context);
|
||||||
|
card_found_notified = true;
|
||||||
|
}
|
||||||
|
furi_hal_nfc_sleep();
|
||||||
|
|
||||||
|
if(!magic_wupa()) {
|
||||||
|
FURI_LOG_E(TAG, "Not Magic card");
|
||||||
|
nfc_magic_worker->callback(
|
||||||
|
NfcMagicWorkerEventWrongCard, nfc_magic_worker->context);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(!magic_data_access_cmd()) {
|
||||||
|
FURI_LOG_E(TAG, "Not Magic card");
|
||||||
|
nfc_magic_worker->callback(
|
||||||
|
NfcMagicWorkerEventWrongCard, nfc_magic_worker->context);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
for(size_t i = 0; i < 64; i++) {
|
||||||
|
FURI_LOG_D(TAG, "Writing block %d", i);
|
||||||
|
if(!magic_write_blk(i, &src_data->block[i])) {
|
||||||
|
FURI_LOG_E(TAG, "Failed to write %d block", i);
|
||||||
|
nfc_magic_worker->callback(NfcMagicWorkerEventFail, nfc_magic_worker->context);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
nfc_magic_worker->callback(NfcMagicWorkerEventSuccess, nfc_magic_worker->context);
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
if(card_found_notified) {
|
||||||
|
nfc_magic_worker->callback(
|
||||||
|
NfcMagicWorkerEventNoCardDetected, nfc_magic_worker->context);
|
||||||
|
card_found_notified = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
furi_delay_ms(300);
|
||||||
|
}
|
||||||
|
magic_deactivate();
|
||||||
|
}
|
||||||
|
|
||||||
|
void nfc_magic_worker_check(NfcMagicWorker* nfc_magic_worker) {
|
||||||
|
bool card_found_notified = false;
|
||||||
|
|
||||||
|
while(nfc_magic_worker->state == NfcMagicWorkerStateCheck) {
|
||||||
|
if(magic_wupa()) {
|
||||||
|
if(!card_found_notified) {
|
||||||
|
nfc_magic_worker->callback(
|
||||||
|
NfcMagicWorkerEventCardDetected, nfc_magic_worker->context);
|
||||||
|
card_found_notified = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
nfc_magic_worker->callback(NfcMagicWorkerEventSuccess, nfc_magic_worker->context);
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
if(card_found_notified) {
|
||||||
|
nfc_magic_worker->callback(
|
||||||
|
NfcMagicWorkerEventNoCardDetected, nfc_magic_worker->context);
|
||||||
|
card_found_notified = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
furi_delay_ms(300);
|
||||||
|
}
|
||||||
|
magic_deactivate();
|
||||||
|
}
|
||||||
|
|
||||||
|
void nfc_magic_worker_wipe(NfcMagicWorker* nfc_magic_worker) {
|
||||||
|
MfClassicBlock block;
|
||||||
|
memset(&block, 0, sizeof(MfClassicBlock));
|
||||||
|
block.value[0] = 0x01;
|
||||||
|
block.value[1] = 0x02;
|
||||||
|
block.value[2] = 0x03;
|
||||||
|
block.value[3] = 0x04;
|
||||||
|
block.value[4] = 0x04;
|
||||||
|
block.value[5] = 0x08;
|
||||||
|
block.value[6] = 0x04;
|
||||||
|
|
||||||
|
while(nfc_magic_worker->state == NfcMagicWorkerStateWipe) {
|
||||||
|
magic_deactivate();
|
||||||
|
furi_delay_ms(300);
|
||||||
|
if(!magic_wupa()) continue;
|
||||||
|
if(!magic_wipe()) continue;
|
||||||
|
if(!magic_data_access_cmd()) continue;
|
||||||
|
if(!magic_write_blk(0, &block)) continue;
|
||||||
|
nfc_magic_worker->callback(NfcMagicWorkerEventSuccess, nfc_magic_worker->context);
|
||||||
|
magic_deactivate();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
magic_deactivate();
|
||||||
|
}
|
||||||
38
applications/plugins/nfc_magic/nfc_magic_worker.h
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <lib/nfc/nfc_device.h>
|
||||||
|
|
||||||
|
typedef struct NfcMagicWorker NfcMagicWorker;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
NfcMagicWorkerStateReady,
|
||||||
|
|
||||||
|
NfcMagicWorkerStateCheck,
|
||||||
|
NfcMagicWorkerStateWrite,
|
||||||
|
NfcMagicWorkerStateWipe,
|
||||||
|
|
||||||
|
NfcMagicWorkerStateStop,
|
||||||
|
} NfcMagicWorkerState;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
NfcMagicWorkerEventSuccess,
|
||||||
|
NfcMagicWorkerEventFail,
|
||||||
|
NfcMagicWorkerEventCardDetected,
|
||||||
|
NfcMagicWorkerEventNoCardDetected,
|
||||||
|
NfcMagicWorkerEventWrongCard,
|
||||||
|
} NfcMagicWorkerEvent;
|
||||||
|
|
||||||
|
typedef bool (*NfcMagicWorkerCallback)(NfcMagicWorkerEvent event, void* context);
|
||||||
|
|
||||||
|
NfcMagicWorker* nfc_magic_worker_alloc();
|
||||||
|
|
||||||
|
void nfc_magic_worker_free(NfcMagicWorker* nfc_magic_worker);
|
||||||
|
|
||||||
|
void nfc_magic_worker_stop(NfcMagicWorker* nfc_magic_worker);
|
||||||
|
|
||||||
|
void nfc_magic_worker_start(
|
||||||
|
NfcMagicWorker* nfc_magic_worker,
|
||||||
|
NfcMagicWorkerState state,
|
||||||
|
NfcDeviceData* dev_data,
|
||||||
|
NfcMagicWorkerCallback callback,
|
||||||
|
void* context);
|
||||||
24
applications/plugins/nfc_magic/nfc_magic_worker_i.h
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <furi.h>
|
||||||
|
|
||||||
|
#include "nfc_magic_worker.h"
|
||||||
|
|
||||||
|
struct NfcMagicWorker {
|
||||||
|
FuriThread* thread;
|
||||||
|
|
||||||
|
NfcDeviceData* dev_data;
|
||||||
|
|
||||||
|
NfcMagicWorkerCallback callback;
|
||||||
|
void* context;
|
||||||
|
|
||||||
|
NfcMagicWorkerState state;
|
||||||
|
};
|
||||||
|
|
||||||
|
int32_t nfc_magic_worker_task(void* context);
|
||||||
|
|
||||||
|
void nfc_magic_worker_check(NfcMagicWorker* nfc_magic_worker);
|
||||||
|
|
||||||
|
void nfc_magic_worker_write(NfcMagicWorker* nfc_magic_worker);
|
||||||
|
|
||||||
|
void nfc_magic_worker_wipe(NfcMagicWorker* nfc_magic_worker);
|
||||||
30
applications/plugins/nfc_magic/scenes/nfc_magic_scene.c
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
#include "nfc_magic_scene.h"
|
||||||
|
|
||||||
|
// Generate scene on_enter handlers array
|
||||||
|
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_enter,
|
||||||
|
void (*const nfc_magic_on_enter_handlers[])(void*) = {
|
||||||
|
#include "nfc_magic_scene_config.h"
|
||||||
|
};
|
||||||
|
#undef ADD_SCENE
|
||||||
|
|
||||||
|
// Generate scene on_event handlers array
|
||||||
|
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_event,
|
||||||
|
bool (*const nfc_magic_on_event_handlers[])(void* context, SceneManagerEvent event) = {
|
||||||
|
#include "nfc_magic_scene_config.h"
|
||||||
|
};
|
||||||
|
#undef ADD_SCENE
|
||||||
|
|
||||||
|
// Generate scene on_exit handlers array
|
||||||
|
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_exit,
|
||||||
|
void (*const nfc_magic_on_exit_handlers[])(void* context) = {
|
||||||
|
#include "nfc_magic_scene_config.h"
|
||||||
|
};
|
||||||
|
#undef ADD_SCENE
|
||||||
|
|
||||||
|
// Initialize scene handlers configuration structure
|
||||||
|
const SceneManagerHandlers nfc_magic_scene_handlers = {
|
||||||
|
.on_enter_handlers = nfc_magic_on_enter_handlers,
|
||||||
|
.on_event_handlers = nfc_magic_on_event_handlers,
|
||||||
|
.on_exit_handlers = nfc_magic_on_exit_handlers,
|
||||||
|
.scene_num = NfcMagicSceneNum,
|
||||||
|
};
|
||||||
29
applications/plugins/nfc_magic/scenes/nfc_magic_scene.h
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <gui/scene_manager.h>
|
||||||
|
|
||||||
|
// Generate scene id and total number
|
||||||
|
#define ADD_SCENE(prefix, name, id) NfcMagicScene##id,
|
||||||
|
typedef enum {
|
||||||
|
#include "nfc_magic_scene_config.h"
|
||||||
|
NfcMagicSceneNum,
|
||||||
|
} NfcMagicScene;
|
||||||
|
#undef ADD_SCENE
|
||||||
|
|
||||||
|
extern const SceneManagerHandlers nfc_magic_scene_handlers;
|
||||||
|
|
||||||
|
// Generate scene on_enter handlers declaration
|
||||||
|
#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_enter(void*);
|
||||||
|
#include "nfc_magic_scene_config.h"
|
||||||
|
#undef ADD_SCENE
|
||||||
|
|
||||||
|
// Generate scene on_event handlers declaration
|
||||||
|
#define ADD_SCENE(prefix, name, id) \
|
||||||
|
bool prefix##_scene_##name##_on_event(void* context, SceneManagerEvent event);
|
||||||
|
#include "nfc_magic_scene_config.h"
|
||||||
|
#undef ADD_SCENE
|
||||||
|
|
||||||
|
// Generate scene on_exit handlers declaration
|
||||||
|
#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_exit(void* context);
|
||||||
|
#include "nfc_magic_scene_config.h"
|
||||||
|
#undef ADD_SCENE
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
#include "../nfc_magic_i.h"
|
||||||
|
|
||||||
|
enum {
|
||||||
|
NfcMagicSceneCheckStateCardSearch,
|
||||||
|
NfcMagicSceneCheckStateCardFound,
|
||||||
|
};
|
||||||
|
|
||||||
|
bool nfc_magic_check_worker_callback(NfcMagicWorkerEvent event, void* context) {
|
||||||
|
furi_assert(context);
|
||||||
|
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
view_dispatcher_send_custom_event(nfc_magic->view_dispatcher, event);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void nfc_magic_scene_check_setup_view(NfcMagic* nfc_magic) {
|
||||||
|
Popup* popup = nfc_magic->popup;
|
||||||
|
popup_reset(popup);
|
||||||
|
uint32_t state = scene_manager_get_scene_state(nfc_magic->scene_manager, NfcMagicSceneCheck);
|
||||||
|
|
||||||
|
if(state == NfcMagicSceneCheckStateCardSearch) {
|
||||||
|
popup_set_icon(nfc_magic->popup, 0, 8, &I_NFC_manual_60x50);
|
||||||
|
popup_set_text(
|
||||||
|
nfc_magic->popup, "Apply card to\nthe back", 128, 32, AlignRight, AlignCenter);
|
||||||
|
} else {
|
||||||
|
popup_set_icon(popup, 12, 23, &I_Loading_24);
|
||||||
|
popup_set_header(popup, "Checking\nDon't move...", 52, 32, AlignLeft, AlignCenter);
|
||||||
|
}
|
||||||
|
|
||||||
|
view_dispatcher_switch_to_view(nfc_magic->view_dispatcher, NfcMagicViewPopup);
|
||||||
|
}
|
||||||
|
|
||||||
|
void nfc_magic_scene_check_on_enter(void* context) {
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
|
||||||
|
scene_manager_set_scene_state(
|
||||||
|
nfc_magic->scene_manager, NfcMagicSceneCheck, NfcMagicSceneCheckStateCardSearch);
|
||||||
|
nfc_magic_scene_check_setup_view(nfc_magic);
|
||||||
|
|
||||||
|
// Setup and start worker
|
||||||
|
nfc_magic_worker_start(
|
||||||
|
nfc_magic->worker,
|
||||||
|
NfcMagicWorkerStateCheck,
|
||||||
|
&nfc_magic->nfc_dev->dev_data,
|
||||||
|
nfc_magic_check_worker_callback,
|
||||||
|
nfc_magic);
|
||||||
|
nfc_magic_blink_start(nfc_magic);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool nfc_magic_scene_check_on_event(void* context, SceneManagerEvent event) {
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
bool consumed = false;
|
||||||
|
|
||||||
|
if(event.type == SceneManagerEventTypeCustom) {
|
||||||
|
if(event.event == NfcMagicWorkerEventSuccess) {
|
||||||
|
scene_manager_next_scene(nfc_magic->scene_manager, NfcMagicSceneMagicInfo);
|
||||||
|
consumed = true;
|
||||||
|
} else if(event.event == NfcMagicWorkerEventWrongCard) {
|
||||||
|
scene_manager_next_scene(nfc_magic->scene_manager, NfcMagicSceneNotMagic);
|
||||||
|
consumed = true;
|
||||||
|
} else if(event.event == NfcMagicWorkerEventCardDetected) {
|
||||||
|
scene_manager_set_scene_state(
|
||||||
|
nfc_magic->scene_manager, NfcMagicSceneCheck, NfcMagicSceneCheckStateCardFound);
|
||||||
|
nfc_magic_scene_check_setup_view(nfc_magic);
|
||||||
|
consumed = true;
|
||||||
|
} else if(event.event == NfcMagicWorkerEventNoCardDetected) {
|
||||||
|
scene_manager_set_scene_state(
|
||||||
|
nfc_magic->scene_manager, NfcMagicSceneCheck, NfcMagicSceneCheckStateCardSearch);
|
||||||
|
nfc_magic_scene_check_setup_view(nfc_magic);
|
||||||
|
consumed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return consumed;
|
||||||
|
}
|
||||||
|
|
||||||
|
void nfc_magic_scene_check_on_exit(void* context) {
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
|
||||||
|
nfc_magic_worker_stop(nfc_magic->worker);
|
||||||
|
scene_manager_set_scene_state(
|
||||||
|
nfc_magic->scene_manager, NfcMagicSceneCheck, NfcMagicSceneCheckStateCardSearch);
|
||||||
|
// Clear view
|
||||||
|
popup_reset(nfc_magic->popup);
|
||||||
|
|
||||||
|
nfc_magic_blink_stop(nfc_magic);
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
ADD_SCENE(nfc_magic, start, Start)
|
||||||
|
ADD_SCENE(nfc_magic, file_select, FileSelect)
|
||||||
|
ADD_SCENE(nfc_magic, write_confirm, WriteConfirm)
|
||||||
|
ADD_SCENE(nfc_magic, wrong_card, WrongCard)
|
||||||
|
ADD_SCENE(nfc_magic, write, Write)
|
||||||
|
ADD_SCENE(nfc_magic, write_fail, WriteFail)
|
||||||
|
ADD_SCENE(nfc_magic, success, Success)
|
||||||
|
ADD_SCENE(nfc_magic, check, Check)
|
||||||
|
ADD_SCENE(nfc_magic, not_magic, NotMagic)
|
||||||
|
ADD_SCENE(nfc_magic, magic_info, MagicInfo)
|
||||||
|
ADD_SCENE(nfc_magic, wipe, Wipe)
|
||||||
|
ADD_SCENE(nfc_magic, wipe_fail, WipeFail)
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
#include "../nfc_magic_i.h"
|
||||||
|
|
||||||
|
static bool nfc_magic_scene_file_select_is_file_suitable(NfcDevice* nfc_dev) {
|
||||||
|
return (nfc_dev->format == NfcDeviceSaveFormatMifareClassic) &&
|
||||||
|
(nfc_dev->dev_data.mf_classic_data.type == MfClassicType1k) &&
|
||||||
|
(nfc_dev->dev_data.nfc_data.uid_len == 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
void nfc_magic_scene_file_select_on_enter(void* context) {
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
// Process file_select return
|
||||||
|
nfc_device_set_loading_callback(nfc_magic->nfc_dev, nfc_magic_show_loading_popup, nfc_magic);
|
||||||
|
|
||||||
|
if(nfc_file_select(nfc_magic->nfc_dev)) {
|
||||||
|
if(nfc_magic_scene_file_select_is_file_suitable(nfc_magic->nfc_dev)) {
|
||||||
|
scene_manager_next_scene(nfc_magic->scene_manager, NfcMagicSceneWriteConfirm);
|
||||||
|
} else {
|
||||||
|
scene_manager_next_scene(nfc_magic->scene_manager, NfcMagicSceneWrongCard);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
scene_manager_previous_scene(nfc_magic->scene_manager);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool nfc_magic_scene_file_select_on_event(void* context, SceneManagerEvent event) {
|
||||||
|
UNUSED(context);
|
||||||
|
UNUSED(event);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void nfc_magic_scene_file_select_on_exit(void* context) {
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
nfc_device_set_loading_callback(nfc_magic->nfc_dev, NULL, nfc_magic);
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
#include "../nfc_magic_i.h"
|
||||||
|
|
||||||
|
void nfc_magic_scene_magic_info_widget_callback(
|
||||||
|
GuiButtonType result,
|
||||||
|
InputType type,
|
||||||
|
void* context) {
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
if(type == InputTypeShort) {
|
||||||
|
view_dispatcher_send_custom_event(nfc_magic->view_dispatcher, result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void nfc_magic_scene_magic_info_on_enter(void* context) {
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
Widget* widget = nfc_magic->widget;
|
||||||
|
|
||||||
|
notification_message(nfc_magic->notifications, &sequence_success);
|
||||||
|
|
||||||
|
widget_add_icon_element(widget, 73, 17, &I_DolphinCommon_56x48);
|
||||||
|
widget_add_string_element(
|
||||||
|
widget, 3, 4, AlignLeft, AlignTop, FontPrimary, "Magic card detected");
|
||||||
|
widget_add_button_element(
|
||||||
|
widget, GuiButtonTypeLeft, "Retry", nfc_magic_scene_magic_info_widget_callback, nfc_magic);
|
||||||
|
|
||||||
|
// Setup and start worker
|
||||||
|
view_dispatcher_switch_to_view(nfc_magic->view_dispatcher, NfcMagicViewWidget);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool nfc_magic_scene_magic_info_on_event(void* context, SceneManagerEvent event) {
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
bool consumed = false;
|
||||||
|
|
||||||
|
if(event.type == SceneManagerEventTypeCustom) {
|
||||||
|
if(event.event == GuiButtonTypeLeft) {
|
||||||
|
consumed = scene_manager_previous_scene(nfc_magic->scene_manager);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return consumed;
|
||||||
|
}
|
||||||
|
|
||||||
|
void nfc_magic_scene_magic_info_on_exit(void* context) {
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
|
||||||
|
widget_reset(nfc_magic->widget);
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
#include "../nfc_magic_i.h"
|
||||||
|
|
||||||
|
void nfc_magic_scene_not_magic_widget_callback(GuiButtonType result, InputType type, void* context) {
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
if(type == InputTypeShort) {
|
||||||
|
view_dispatcher_send_custom_event(nfc_magic->view_dispatcher, result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void nfc_magic_scene_not_magic_on_enter(void* context) {
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
Widget* widget = nfc_magic->widget;
|
||||||
|
|
||||||
|
notification_message(nfc_magic->notifications, &sequence_error);
|
||||||
|
|
||||||
|
// widget_add_icon_element(widget, 73, 17, &I_DolphinCommon_56x48);
|
||||||
|
widget_add_string_element(
|
||||||
|
widget, 3, 4, AlignLeft, AlignTop, FontPrimary, "This is wrong card");
|
||||||
|
widget_add_string_multiline_element(
|
||||||
|
widget, 4, 17, AlignLeft, AlignTop, FontSecondary, "Not a magic\ncard");
|
||||||
|
widget_add_button_element(
|
||||||
|
widget, GuiButtonTypeLeft, "Retry", nfc_magic_scene_not_magic_widget_callback, nfc_magic);
|
||||||
|
|
||||||
|
// Setup and start worker
|
||||||
|
view_dispatcher_switch_to_view(nfc_magic->view_dispatcher, NfcMagicViewWidget);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool nfc_magic_scene_not_magic_on_event(void* context, SceneManagerEvent event) {
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
bool consumed = false;
|
||||||
|
|
||||||
|
if(event.type == SceneManagerEventTypeCustom) {
|
||||||
|
if(event.event == GuiButtonTypeLeft) {
|
||||||
|
consumed = scene_manager_previous_scene(nfc_magic->scene_manager);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return consumed;
|
||||||
|
}
|
||||||
|
|
||||||
|
void nfc_magic_scene_not_magic_on_exit(void* context) {
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
|
||||||
|
widget_reset(nfc_magic->widget);
|
||||||
|
}
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
#include "../nfc_magic_i.h"
|
||||||
|
enum SubmenuIndex {
|
||||||
|
SubmenuIndexCheck,
|
||||||
|
SubmenuIndexWriteGen1A,
|
||||||
|
SubmenuIndexWipe,
|
||||||
|
};
|
||||||
|
|
||||||
|
void nfc_magic_scene_start_submenu_callback(void* context, uint32_t index) {
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
view_dispatcher_send_custom_event(nfc_magic->view_dispatcher, index);
|
||||||
|
}
|
||||||
|
|
||||||
|
void nfc_magic_scene_start_on_enter(void* context) {
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
|
||||||
|
Submenu* submenu = nfc_magic->submenu;
|
||||||
|
submenu_add_item(
|
||||||
|
submenu,
|
||||||
|
"Check Magic Tag",
|
||||||
|
SubmenuIndexCheck,
|
||||||
|
nfc_magic_scene_start_submenu_callback,
|
||||||
|
nfc_magic);
|
||||||
|
submenu_add_item(
|
||||||
|
submenu,
|
||||||
|
"Write Gen1A",
|
||||||
|
SubmenuIndexWriteGen1A,
|
||||||
|
nfc_magic_scene_start_submenu_callback,
|
||||||
|
nfc_magic);
|
||||||
|
submenu_add_item(
|
||||||
|
submenu, "Wipe", SubmenuIndexWipe, nfc_magic_scene_start_submenu_callback, nfc_magic);
|
||||||
|
|
||||||
|
submenu_set_selected_item(
|
||||||
|
submenu, scene_manager_get_scene_state(nfc_magic->scene_manager, NfcMagicSceneStart));
|
||||||
|
view_dispatcher_switch_to_view(nfc_magic->view_dispatcher, NfcMagicViewMenu);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool nfc_magic_scene_start_on_event(void* context, SceneManagerEvent event) {
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
bool consumed = false;
|
||||||
|
|
||||||
|
if(event.type == SceneManagerEventTypeCustom) {
|
||||||
|
if(event.event == SubmenuIndexCheck) {
|
||||||
|
scene_manager_next_scene(nfc_magic->scene_manager, NfcMagicSceneCheck);
|
||||||
|
consumed = true;
|
||||||
|
} else if(event.event == SubmenuIndexWriteGen1A) {
|
||||||
|
scene_manager_next_scene(nfc_magic->scene_manager, NfcMagicSceneFileSelect);
|
||||||
|
consumed = true;
|
||||||
|
} else if(event.event == SubmenuIndexWipe) {
|
||||||
|
scene_manager_next_scene(nfc_magic->scene_manager, NfcMagicSceneWipe);
|
||||||
|
consumed = true;
|
||||||
|
}
|
||||||
|
scene_manager_set_scene_state(nfc_magic->scene_manager, NfcMagicSceneStart, event.event);
|
||||||
|
}
|
||||||
|
|
||||||
|
return consumed;
|
||||||
|
}
|
||||||
|
|
||||||
|
void nfc_magic_scene_start_on_exit(void* context) {
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
submenu_reset(nfc_magic->submenu);
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
#include "../nfc_magic_i.h"
|
||||||
|
|
||||||
|
void nfc_magic_scene_success_popup_callback(void* context) {
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
view_dispatcher_send_custom_event(nfc_magic->view_dispatcher, NfcMagicCustomEventViewExit);
|
||||||
|
}
|
||||||
|
|
||||||
|
void nfc_magic_scene_success_on_enter(void* context) {
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
|
||||||
|
notification_message(nfc_magic->notifications, &sequence_success);
|
||||||
|
|
||||||
|
Popup* popup = nfc_magic->popup;
|
||||||
|
popup_set_icon(popup, 32, 5, &I_DolphinNice_96x59);
|
||||||
|
popup_set_header(popup, "Success!", 10, 20, AlignLeft, AlignBottom);
|
||||||
|
popup_set_timeout(popup, 1500);
|
||||||
|
popup_set_context(popup, nfc_magic);
|
||||||
|
popup_set_callback(popup, nfc_magic_scene_success_popup_callback);
|
||||||
|
popup_enable_timeout(popup);
|
||||||
|
|
||||||
|
view_dispatcher_switch_to_view(nfc_magic->view_dispatcher, NfcMagicViewPopup);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool nfc_magic_scene_success_on_event(void* context, SceneManagerEvent event) {
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
bool consumed = false;
|
||||||
|
|
||||||
|
if(event.type == SceneManagerEventTypeCustom) {
|
||||||
|
if(event.event == NfcMagicCustomEventViewExit) {
|
||||||
|
consumed = scene_manager_search_and_switch_to_previous_scene(
|
||||||
|
nfc_magic->scene_manager, NfcMagicSceneStart);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return consumed;
|
||||||
|
}
|
||||||
|
|
||||||
|
void nfc_magic_scene_success_on_exit(void* context) {
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
|
||||||
|
// Clear view
|
||||||
|
popup_reset(nfc_magic->popup);
|
||||||
|
}
|
||||||
90
applications/plugins/nfc_magic/scenes/nfc_magic_scene_wipe.c
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
#include "../nfc_magic_i.h"
|
||||||
|
|
||||||
|
enum {
|
||||||
|
NfcMagicSceneWipeStateCardSearch,
|
||||||
|
NfcMagicSceneWipeStateCardFound,
|
||||||
|
};
|
||||||
|
|
||||||
|
bool nfc_magic_wipe_worker_callback(NfcMagicWorkerEvent event, void* context) {
|
||||||
|
furi_assert(context);
|
||||||
|
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
view_dispatcher_send_custom_event(nfc_magic->view_dispatcher, event);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void nfc_magic_scene_wipe_setup_view(NfcMagic* nfc_magic) {
|
||||||
|
Popup* popup = nfc_magic->popup;
|
||||||
|
popup_reset(popup);
|
||||||
|
uint32_t state = scene_manager_get_scene_state(nfc_magic->scene_manager, NfcMagicSceneWipe);
|
||||||
|
|
||||||
|
if(state == NfcMagicSceneWipeStateCardSearch) {
|
||||||
|
popup_set_icon(nfc_magic->popup, 0, 8, &I_NFC_manual_60x50);
|
||||||
|
popup_set_text(
|
||||||
|
nfc_magic->popup, "Apply card to\nthe back", 128, 32, AlignRight, AlignCenter);
|
||||||
|
} else {
|
||||||
|
popup_set_icon(popup, 12, 23, &I_Loading_24);
|
||||||
|
popup_set_header(popup, "Wiping\nDon't move...", 52, 32, AlignLeft, AlignCenter);
|
||||||
|
}
|
||||||
|
|
||||||
|
view_dispatcher_switch_to_view(nfc_magic->view_dispatcher, NfcMagicViewPopup);
|
||||||
|
}
|
||||||
|
|
||||||
|
void nfc_magic_scene_wipe_on_enter(void* context) {
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
|
||||||
|
scene_manager_set_scene_state(
|
||||||
|
nfc_magic->scene_manager, NfcMagicSceneWipe, NfcMagicSceneWipeStateCardSearch);
|
||||||
|
nfc_magic_scene_wipe_setup_view(nfc_magic);
|
||||||
|
|
||||||
|
// Setup and start worker
|
||||||
|
nfc_magic_worker_start(
|
||||||
|
nfc_magic->worker,
|
||||||
|
NfcMagicWorkerStateWipe,
|
||||||
|
&nfc_magic->nfc_dev->dev_data,
|
||||||
|
nfc_magic_wipe_worker_callback,
|
||||||
|
nfc_magic);
|
||||||
|
nfc_magic_blink_start(nfc_magic);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool nfc_magic_scene_wipe_on_event(void* context, SceneManagerEvent event) {
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
bool consumed = false;
|
||||||
|
|
||||||
|
if(event.type == SceneManagerEventTypeCustom) {
|
||||||
|
if(event.event == NfcMagicWorkerEventSuccess) {
|
||||||
|
scene_manager_next_scene(nfc_magic->scene_manager, NfcMagicSceneSuccess);
|
||||||
|
consumed = true;
|
||||||
|
} else if(event.event == NfcMagicWorkerEventFail) {
|
||||||
|
scene_manager_next_scene(nfc_magic->scene_manager, NfcMagicSceneWipeFail);
|
||||||
|
consumed = true;
|
||||||
|
} else if(event.event == NfcMagicWorkerEventWrongCard) {
|
||||||
|
scene_manager_next_scene(nfc_magic->scene_manager, NfcMagicSceneNotMagic);
|
||||||
|
consumed = true;
|
||||||
|
} else if(event.event == NfcMagicWorkerEventCardDetected) {
|
||||||
|
scene_manager_set_scene_state(
|
||||||
|
nfc_magic->scene_manager, NfcMagicSceneWipe, NfcMagicSceneWipeStateCardFound);
|
||||||
|
nfc_magic_scene_wipe_setup_view(nfc_magic);
|
||||||
|
consumed = true;
|
||||||
|
} else if(event.event == NfcMagicWorkerEventNoCardDetected) {
|
||||||
|
scene_manager_set_scene_state(
|
||||||
|
nfc_magic->scene_manager, NfcMagicSceneWipe, NfcMagicSceneWipeStateCardSearch);
|
||||||
|
nfc_magic_scene_wipe_setup_view(nfc_magic);
|
||||||
|
consumed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return consumed;
|
||||||
|
}
|
||||||
|
|
||||||
|
void nfc_magic_scene_wipe_on_exit(void* context) {
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
|
||||||
|
nfc_magic_worker_stop(nfc_magic->worker);
|
||||||
|
scene_manager_set_scene_state(
|
||||||
|
nfc_magic->scene_manager, NfcMagicSceneWipe, NfcMagicSceneWipeStateCardSearch);
|
||||||
|
// Clear view
|
||||||
|
popup_reset(nfc_magic->popup);
|
||||||
|
|
||||||
|
nfc_magic_blink_stop(nfc_magic);
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
#include "../nfc_magic_i.h"
|
||||||
|
|
||||||
|
void nfc_magic_scene_wipe_fail_widget_callback(GuiButtonType result, InputType type, void* context) {
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
if(type == InputTypeShort) {
|
||||||
|
view_dispatcher_send_custom_event(nfc_magic->view_dispatcher, result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void nfc_magic_scene_wipe_fail_on_enter(void* context) {
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
Widget* widget = nfc_magic->widget;
|
||||||
|
|
||||||
|
notification_message(nfc_magic->notifications, &sequence_error);
|
||||||
|
|
||||||
|
widget_add_icon_element(widget, 73, 17, &I_DolphinCommon_56x48);
|
||||||
|
widget_add_string_element(widget, 3, 4, AlignLeft, AlignTop, FontPrimary, "Wipe failed");
|
||||||
|
widget_add_button_element(
|
||||||
|
widget, GuiButtonTypeLeft, "Retry", nfc_magic_scene_wipe_fail_widget_callback, nfc_magic);
|
||||||
|
|
||||||
|
// Setup and start worker
|
||||||
|
view_dispatcher_switch_to_view(nfc_magic->view_dispatcher, NfcMagicViewWidget);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool nfc_magic_scene_wipe_fail_on_event(void* context, SceneManagerEvent event) {
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
bool consumed = false;
|
||||||
|
|
||||||
|
if(event.type == SceneManagerEventTypeCustom) {
|
||||||
|
if(event.event == GuiButtonTypeLeft) {
|
||||||
|
consumed = scene_manager_previous_scene(nfc_magic->scene_manager);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return consumed;
|
||||||
|
}
|
||||||
|
|
||||||
|
void nfc_magic_scene_wipe_fail_on_exit(void* context) {
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
|
||||||
|
widget_reset(nfc_magic->widget);
|
||||||
|
}
|
||||||
@@ -0,0 +1,90 @@
|
|||||||
|
#include "../nfc_magic_i.h"
|
||||||
|
|
||||||
|
enum {
|
||||||
|
NfcMagicSceneWriteStateCardSearch,
|
||||||
|
NfcMagicSceneWriteStateCardFound,
|
||||||
|
};
|
||||||
|
|
||||||
|
bool nfc_magic_write_worker_callback(NfcMagicWorkerEvent event, void* context) {
|
||||||
|
furi_assert(context);
|
||||||
|
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
view_dispatcher_send_custom_event(nfc_magic->view_dispatcher, event);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void nfc_magic_scene_write_setup_view(NfcMagic* nfc_magic) {
|
||||||
|
Popup* popup = nfc_magic->popup;
|
||||||
|
popup_reset(popup);
|
||||||
|
uint32_t state = scene_manager_get_scene_state(nfc_magic->scene_manager, NfcMagicSceneWrite);
|
||||||
|
|
||||||
|
if(state == NfcMagicSceneWriteStateCardSearch) {
|
||||||
|
popup_set_text(
|
||||||
|
nfc_magic->popup, "Apply card to\nthe back", 128, 32, AlignRight, AlignCenter);
|
||||||
|
popup_set_icon(nfc_magic->popup, 0, 8, &I_NFC_manual_60x50);
|
||||||
|
} else {
|
||||||
|
popup_set_icon(popup, 12, 23, &I_Loading_24);
|
||||||
|
popup_set_header(popup, "Writing\nDon't move...", 52, 32, AlignLeft, AlignCenter);
|
||||||
|
}
|
||||||
|
|
||||||
|
view_dispatcher_switch_to_view(nfc_magic->view_dispatcher, NfcMagicViewPopup);
|
||||||
|
}
|
||||||
|
|
||||||
|
void nfc_magic_scene_write_on_enter(void* context) {
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
|
||||||
|
scene_manager_set_scene_state(
|
||||||
|
nfc_magic->scene_manager, NfcMagicSceneWrite, NfcMagicSceneWriteStateCardSearch);
|
||||||
|
nfc_magic_scene_write_setup_view(nfc_magic);
|
||||||
|
|
||||||
|
// Setup and start worker
|
||||||
|
nfc_magic_worker_start(
|
||||||
|
nfc_magic->worker,
|
||||||
|
NfcMagicWorkerStateWrite,
|
||||||
|
&nfc_magic->nfc_dev->dev_data,
|
||||||
|
nfc_magic_write_worker_callback,
|
||||||
|
nfc_magic);
|
||||||
|
nfc_magic_blink_start(nfc_magic);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool nfc_magic_scene_write_on_event(void* context, SceneManagerEvent event) {
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
bool consumed = false;
|
||||||
|
|
||||||
|
if(event.type == SceneManagerEventTypeCustom) {
|
||||||
|
if(event.event == NfcMagicWorkerEventSuccess) {
|
||||||
|
scene_manager_next_scene(nfc_magic->scene_manager, NfcMagicSceneSuccess);
|
||||||
|
consumed = true;
|
||||||
|
} else if(event.event == NfcMagicWorkerEventFail) {
|
||||||
|
scene_manager_next_scene(nfc_magic->scene_manager, NfcMagicSceneWriteFail);
|
||||||
|
consumed = true;
|
||||||
|
} else if(event.event == NfcMagicWorkerEventWrongCard) {
|
||||||
|
scene_manager_next_scene(nfc_magic->scene_manager, NfcMagicSceneNotMagic);
|
||||||
|
consumed = true;
|
||||||
|
} else if(event.event == NfcMagicWorkerEventCardDetected) {
|
||||||
|
scene_manager_set_scene_state(
|
||||||
|
nfc_magic->scene_manager, NfcMagicSceneWrite, NfcMagicSceneWriteStateCardFound);
|
||||||
|
nfc_magic_scene_write_setup_view(nfc_magic);
|
||||||
|
consumed = true;
|
||||||
|
} else if(event.event == NfcMagicWorkerEventNoCardDetected) {
|
||||||
|
scene_manager_set_scene_state(
|
||||||
|
nfc_magic->scene_manager, NfcMagicSceneWrite, NfcMagicSceneWriteStateCardSearch);
|
||||||
|
nfc_magic_scene_write_setup_view(nfc_magic);
|
||||||
|
consumed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return consumed;
|
||||||
|
}
|
||||||
|
|
||||||
|
void nfc_magic_scene_write_on_exit(void* context) {
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
|
||||||
|
nfc_magic_worker_stop(nfc_magic->worker);
|
||||||
|
scene_manager_set_scene_state(
|
||||||
|
nfc_magic->scene_manager, NfcMagicSceneWrite, NfcMagicSceneWriteStateCardSearch);
|
||||||
|
// Clear view
|
||||||
|
popup_reset(nfc_magic->popup);
|
||||||
|
|
||||||
|
nfc_magic_blink_stop(nfc_magic);
|
||||||
|
}
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
#include "../nfc_magic_i.h"
|
||||||
|
|
||||||
|
void nfc_magic_scene_write_confirm_widget_callback(
|
||||||
|
GuiButtonType result,
|
||||||
|
InputType type,
|
||||||
|
void* context) {
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
if(type == InputTypeShort) {
|
||||||
|
view_dispatcher_send_custom_event(nfc_magic->view_dispatcher, result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void nfc_magic_scene_write_confirm_on_enter(void* context) {
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
Widget* widget = nfc_magic->widget;
|
||||||
|
|
||||||
|
widget_add_string_element(widget, 3, 0, AlignLeft, AlignTop, FontPrimary, "Risky operation");
|
||||||
|
widget_add_text_box_element(
|
||||||
|
widget,
|
||||||
|
0,
|
||||||
|
13,
|
||||||
|
128,
|
||||||
|
54,
|
||||||
|
AlignLeft,
|
||||||
|
AlignTop,
|
||||||
|
"Writing to this card will change manufacturer block. On some cards it may not be rewritten",
|
||||||
|
false);
|
||||||
|
widget_add_button_element(
|
||||||
|
widget,
|
||||||
|
GuiButtonTypeCenter,
|
||||||
|
"Continue",
|
||||||
|
nfc_magic_scene_write_confirm_widget_callback,
|
||||||
|
nfc_magic);
|
||||||
|
widget_add_button_element(
|
||||||
|
widget,
|
||||||
|
GuiButtonTypeLeft,
|
||||||
|
"Back",
|
||||||
|
nfc_magic_scene_write_confirm_widget_callback,
|
||||||
|
nfc_magic);
|
||||||
|
|
||||||
|
// Setup and start worker
|
||||||
|
view_dispatcher_switch_to_view(nfc_magic->view_dispatcher, NfcMagicViewWidget);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool nfc_magic_scene_write_confirm_on_event(void* context, SceneManagerEvent event) {
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
bool consumed = false;
|
||||||
|
|
||||||
|
if(event.type == SceneManagerEventTypeCustom) {
|
||||||
|
if(event.event == GuiButtonTypeLeft) {
|
||||||
|
consumed = scene_manager_previous_scene(nfc_magic->scene_manager);
|
||||||
|
} else if(event.event == GuiButtonTypeCenter) {
|
||||||
|
scene_manager_next_scene(nfc_magic->scene_manager, NfcMagicSceneWrite);
|
||||||
|
consumed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return consumed;
|
||||||
|
}
|
||||||
|
|
||||||
|
void nfc_magic_scene_write_confirm_on_exit(void* context) {
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
|
||||||
|
widget_reset(nfc_magic->widget);
|
||||||
|
}
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
#include "../nfc_magic_i.h"
|
||||||
|
|
||||||
|
void nfc_magic_scene_write_fail_widget_callback(
|
||||||
|
GuiButtonType result,
|
||||||
|
InputType type,
|
||||||
|
void* context) {
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
if(type == InputTypeShort) {
|
||||||
|
view_dispatcher_send_custom_event(nfc_magic->view_dispatcher, result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void nfc_magic_scene_write_fail_on_enter(void* context) {
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
Widget* widget = nfc_magic->widget;
|
||||||
|
|
||||||
|
notification_message(nfc_magic->notifications, &sequence_error);
|
||||||
|
|
||||||
|
widget_add_icon_element(widget, 72, 17, &I_DolphinCommon_56x48);
|
||||||
|
widget_add_string_element(
|
||||||
|
widget, 7, 4, AlignLeft, AlignTop, FontPrimary, "Writing gone wrong!");
|
||||||
|
widget_add_string_multiline_element(
|
||||||
|
widget,
|
||||||
|
7,
|
||||||
|
17,
|
||||||
|
AlignLeft,
|
||||||
|
AlignTop,
|
||||||
|
FontSecondary,
|
||||||
|
"Not all sectors\nwere written\ncorrectly.");
|
||||||
|
|
||||||
|
widget_add_button_element(
|
||||||
|
widget, GuiButtonTypeLeft, "Finish", nfc_magic_scene_write_fail_widget_callback, nfc_magic);
|
||||||
|
|
||||||
|
// Setup and start worker
|
||||||
|
view_dispatcher_switch_to_view(nfc_magic->view_dispatcher, NfcMagicViewWidget);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool nfc_magic_scene_write_fail_on_event(void* context, SceneManagerEvent event) {
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
bool consumed = false;
|
||||||
|
|
||||||
|
if(event.type == SceneManagerEventTypeCustom) {
|
||||||
|
if(event.event == GuiButtonTypeLeft) {
|
||||||
|
consumed = scene_manager_search_and_switch_to_previous_scene(
|
||||||
|
nfc_magic->scene_manager, NfcMagicSceneStart);
|
||||||
|
}
|
||||||
|
} else if(event.type == SceneManagerEventTypeBack) {
|
||||||
|
consumed = scene_manager_search_and_switch_to_previous_scene(
|
||||||
|
nfc_magic->scene_manager, NfcMagicSceneStart);
|
||||||
|
}
|
||||||
|
return consumed;
|
||||||
|
}
|
||||||
|
|
||||||
|
void nfc_magic_scene_write_fail_on_exit(void* context) {
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
|
||||||
|
widget_reset(nfc_magic->widget);
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
#include "../nfc_magic_i.h"
|
||||||
|
|
||||||
|
void nfc_magic_scene_wrong_card_widget_callback(
|
||||||
|
GuiButtonType result,
|
||||||
|
InputType type,
|
||||||
|
void* context) {
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
if(type == InputTypeShort) {
|
||||||
|
view_dispatcher_send_custom_event(nfc_magic->view_dispatcher, result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void nfc_magic_scene_wrong_card_on_enter(void* context) {
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
Widget* widget = nfc_magic->widget;
|
||||||
|
|
||||||
|
notification_message(nfc_magic->notifications, &sequence_error);
|
||||||
|
|
||||||
|
widget_add_icon_element(widget, 73, 17, &I_DolphinCommon_56x48);
|
||||||
|
widget_add_string_element(
|
||||||
|
widget, 1, 4, AlignLeft, AlignTop, FontPrimary, "This is wrong card");
|
||||||
|
widget_add_string_multiline_element(
|
||||||
|
widget,
|
||||||
|
1,
|
||||||
|
17,
|
||||||
|
AlignLeft,
|
||||||
|
AlignTop,
|
||||||
|
FontSecondary,
|
||||||
|
"Writing is supported\nonly for 4 bytes UID\nMifare CLassic 1k");
|
||||||
|
widget_add_button_element(
|
||||||
|
widget, GuiButtonTypeLeft, "Retry", nfc_magic_scene_wrong_card_widget_callback, nfc_magic);
|
||||||
|
|
||||||
|
// Setup and start worker
|
||||||
|
view_dispatcher_switch_to_view(nfc_magic->view_dispatcher, NfcMagicViewWidget);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool nfc_magic_scene_wrong_card_on_event(void* context, SceneManagerEvent event) {
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
bool consumed = false;
|
||||||
|
|
||||||
|
if(event.type == SceneManagerEventTypeCustom) {
|
||||||
|
if(event.event == GuiButtonTypeLeft) {
|
||||||
|
consumed = scene_manager_previous_scene(nfc_magic->scene_manager);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return consumed;
|
||||||
|
}
|
||||||
|
|
||||||
|
void nfc_magic_scene_wrong_card_on_exit(void* context) {
|
||||||
|
NfcMagic* nfc_magic = context;
|
||||||
|
|
||||||
|
widget_reset(nfc_magic->widget);
|
||||||
|
}
|
||||||
BIN
applications/plugins/picopass/125_10px.png
Normal file
|
After Width: | Height: | Size: 308 B |
@@ -9,7 +9,7 @@ App(
|
|||||||
],
|
],
|
||||||
stack_size=4 * 1024,
|
stack_size=4 * 1024,
|
||||||
order=30,
|
order=30,
|
||||||
fap_icon="../../../assets/icons/Archive/125_10px.png",
|
fap_icon="125_10px.png",
|
||||||
fap_category="Tools",
|
fap_category="Tools",
|
||||||
fap_libs=["mbedtls"],
|
fap_libs=["mbedtls"],
|
||||||
fap_private_libs=[
|
fap_private_libs=[
|
||||||
|
|||||||
@@ -9,8 +9,6 @@
|
|||||||
#include <furi_hal.h>
|
#include <furi_hal.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <st25r3916.h>
|
|
||||||
#include <rfal_analogConfig.h>
|
|
||||||
#include <rfal_rf.h>
|
#include <rfal_rf.h>
|
||||||
|
|
||||||
#include <platform.h>
|
#include <platform.h>
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
#include "rfal_picopass.h"
|
#include "rfal_picopass.h"
|
||||||
#include "utils.h"
|
|
||||||
|
|
||||||
#define RFAL_PICOPASS_TXRX_FLAGS \
|
#define RFAL_PICOPASS_TXRX_FLAGS \
|
||||||
(FURI_HAL_NFC_LL_TXRX_FLAGS_CRC_TX_MANUAL | FURI_HAL_NFC_LL_TXRX_FLAGS_AGC_ON | \
|
(FURI_HAL_NFC_LL_TXRX_FLAGS_CRC_TX_MANUAL | FURI_HAL_NFC_LL_TXRX_FLAGS_AGC_ON | \
|
||||||
@@ -97,7 +96,7 @@ FuriHalNfcReturn rfalPicoPassPollerSelect(uint8_t* csn, rfalPicoPassSelectRes* s
|
|||||||
|
|
||||||
rfalPicoPassSelectReq selReq;
|
rfalPicoPassSelectReq selReq;
|
||||||
selReq.CMD = RFAL_PICOPASS_CMD_SELECT;
|
selReq.CMD = RFAL_PICOPASS_CMD_SELECT;
|
||||||
ST_MEMCPY(selReq.CSN, csn, RFAL_PICOPASS_UID_LEN);
|
memcpy(selReq.CSN, csn, RFAL_PICOPASS_UID_LEN);
|
||||||
uint16_t recvLen = 0;
|
uint16_t recvLen = 0;
|
||||||
uint32_t flags = RFAL_PICOPASS_TXRX_FLAGS;
|
uint32_t flags = RFAL_PICOPASS_TXRX_FLAGS;
|
||||||
uint32_t fwt = furi_hal_nfc_ll_ms2fc(20);
|
uint32_t fwt = furi_hal_nfc_ll_ms2fc(20);
|
||||||
@@ -146,8 +145,8 @@ FuriHalNfcReturn rfalPicoPassPollerCheck(uint8_t* mac, rfalPicoPassCheckRes* chk
|
|||||||
FuriHalNfcReturn ret;
|
FuriHalNfcReturn ret;
|
||||||
rfalPicoPassCheckReq chkReq;
|
rfalPicoPassCheckReq chkReq;
|
||||||
chkReq.CMD = RFAL_PICOPASS_CMD_CHECK;
|
chkReq.CMD = RFAL_PICOPASS_CMD_CHECK;
|
||||||
ST_MEMCPY(chkReq.mac, mac, 4);
|
memcpy(chkReq.mac, mac, 4);
|
||||||
ST_MEMSET(chkReq.null, 0, 4);
|
memset(chkReq.null, 0, 4);
|
||||||
uint16_t recvLen = 0;
|
uint16_t recvLen = 0;
|
||||||
uint32_t flags = RFAL_PICOPASS_TXRX_FLAGS;
|
uint32_t flags = RFAL_PICOPASS_TXRX_FLAGS;
|
||||||
uint32_t fwt = furi_hal_nfc_ll_ms2fc(20);
|
uint32_t fwt = furi_hal_nfc_ll_ms2fc(20);
|
||||||
|
|||||||
@@ -380,6 +380,8 @@ int32_t snake_game_app(void* p) {
|
|||||||
case InputKeyBack:
|
case InputKeyBack:
|
||||||
processing = false;
|
processing = false;
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if(event.type == EventTypeTick) {
|
} else if(event.type == EventTypeTick) {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
#include <furi.h>
|
#include <furi.h>
|
||||||
#include <furi_hal.h>
|
#include <furi_hal.h>
|
||||||
|
|
||||||
#define WS_VERSION_APP "0.3.1"
|
#define WS_VERSION_APP "0.4"
|
||||||
#define WS_DEVELOPED "SkorP"
|
#define WS_DEVELOPED "SkorP"
|
||||||
#define WS_GITHUB "https://github.com/flipperdevices/flipperzero-firmware"
|
#define WS_GITHUB "https://github.com/flipperdevices/flipperzero-firmware"
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Help
|
* Help
|
||||||
* https://github.com/merbanan/rtl_433/blob/5bef4e43133ac4c0e2d18d36f87c52b4f9458453/src/devices/acurite.c
|
* https://github.com/merbanan/rtl_433/blob/master/src/devices/acurite.c
|
||||||
*
|
*
|
||||||
* Acurite 592TXR Temperature Humidity sensor decoder
|
* Acurite 592TXR Temperature Humidity sensor decoder
|
||||||
* Message Type 0x04, 7 bytes
|
* Message Type 0x04, 7 bytes
|
||||||
|
|||||||
278
applications/plugins/weather_station/protocols/ambient_weather.c
Normal file
@@ -0,0 +1,278 @@
|
|||||||
|
#include "ambient_weather.h"
|
||||||
|
#include <lib/toolbox/manchester_decoder.h>
|
||||||
|
|
||||||
|
#define TAG "WSProtocolAmbient_Weather"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Help
|
||||||
|
* https://github.com/merbanan/rtl_433/blob/master/src/devices/ambient_weather.c
|
||||||
|
*
|
||||||
|
* Decode Ambient Weather F007TH, F012TH, TF 30.3208.02, SwitchDoc F016TH.
|
||||||
|
* Devices supported:
|
||||||
|
* - Ambient Weather F007TH Thermo-Hygrometer.
|
||||||
|
* - Ambient Weather F012TH Indoor/Display Thermo-Hygrometer.
|
||||||
|
* - TFA senders 30.3208.02 from the TFA "Klima-Monitor" 30.3054,
|
||||||
|
* - SwitchDoc Labs F016TH.
|
||||||
|
* This decoder handles the 433mhz/868mhz thermo-hygrometers.
|
||||||
|
* The 915mhz (WH*) family of devices use different modulation/encoding.
|
||||||
|
* Byte 0 Byte 1 Byte 2 Byte 3 Byte 4 Byte 5
|
||||||
|
* xxxxMMMM IIIIIIII BCCCTTTT TTTTTTTT HHHHHHHH MMMMMMMM
|
||||||
|
* - x: Unknown 0x04 on F007TH/F012TH
|
||||||
|
* - M: Model Number?, 0x05 on F007TH/F012TH/SwitchDocLabs F016TH
|
||||||
|
* - I: ID byte (8 bits), volatie, changes at power up,
|
||||||
|
* - B: Battery Low
|
||||||
|
* - C: Channel (3 bits 1-8) - F007TH set by Dip switch, F012TH soft setting
|
||||||
|
* - T: Temperature 12 bits - Fahrenheit * 10 + 400
|
||||||
|
* - H: Humidity (8 bits)
|
||||||
|
* - M: Message integrity check LFSR Digest-8, gen 0x98, key 0x3e, init 0x64
|
||||||
|
*
|
||||||
|
* three repeats without gap
|
||||||
|
* full preamble is 0x00145 (the last bits might not be fixed, e.g. 0x00146)
|
||||||
|
* and on decoding also 0xffd45
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define AMBIENT_WEATHER_PACKET_HEADER_1 0xFFD440000000000 //0xffd45 .. 0xffd46
|
||||||
|
#define AMBIENT_WEATHER_PACKET_HEADER_2 0x001440000000000 //0x00145 .. 0x00146
|
||||||
|
#define AMBIENT_WEATHER_PACKET_HEADER_MASK 0xFFFFC0000000000
|
||||||
|
|
||||||
|
static const SubGhzBlockConst ws_protocol_ambient_weather_const = {
|
||||||
|
.te_short = 500,
|
||||||
|
.te_long = 1000,
|
||||||
|
.te_delta = 120,
|
||||||
|
.min_count_bit_for_found = 48,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct WSProtocolDecoderAmbient_Weather {
|
||||||
|
SubGhzProtocolDecoderBase base;
|
||||||
|
|
||||||
|
SubGhzBlockDecoder decoder;
|
||||||
|
WSBlockGeneric generic;
|
||||||
|
ManchesterState manchester_saved_state;
|
||||||
|
uint16_t header_count;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct WSProtocolEncoderAmbient_Weather {
|
||||||
|
SubGhzProtocolEncoderBase base;
|
||||||
|
|
||||||
|
SubGhzProtocolBlockEncoder encoder;
|
||||||
|
WSBlockGeneric generic;
|
||||||
|
};
|
||||||
|
|
||||||
|
const SubGhzProtocolDecoder ws_protocol_ambient_weather_decoder = {
|
||||||
|
.alloc = ws_protocol_decoder_ambient_weather_alloc,
|
||||||
|
.free = ws_protocol_decoder_ambient_weather_free,
|
||||||
|
|
||||||
|
.feed = ws_protocol_decoder_ambient_weather_feed,
|
||||||
|
.reset = ws_protocol_decoder_ambient_weather_reset,
|
||||||
|
|
||||||
|
.get_hash_data = ws_protocol_decoder_ambient_weather_get_hash_data,
|
||||||
|
.serialize = ws_protocol_decoder_ambient_weather_serialize,
|
||||||
|
.deserialize = ws_protocol_decoder_ambient_weather_deserialize,
|
||||||
|
.get_string = ws_protocol_decoder_ambient_weather_get_string,
|
||||||
|
};
|
||||||
|
|
||||||
|
const SubGhzProtocolEncoder ws_protocol_ambient_weather_encoder = {
|
||||||
|
.alloc = NULL,
|
||||||
|
.free = NULL,
|
||||||
|
|
||||||
|
.deserialize = NULL,
|
||||||
|
.stop = NULL,
|
||||||
|
.yield = NULL,
|
||||||
|
};
|
||||||
|
|
||||||
|
const SubGhzProtocol ws_protocol_ambient_weather = {
|
||||||
|
.name = WS_PROTOCOL_AMBIENT_WEATHER_NAME,
|
||||||
|
.type = SubGhzProtocolWeatherStation,
|
||||||
|
.flag = SubGhzProtocolFlag_433 | SubGhzProtocolFlag_315 | SubGhzProtocolFlag_868 |
|
||||||
|
SubGhzProtocolFlag_AM | SubGhzProtocolFlag_Decodable,
|
||||||
|
|
||||||
|
.decoder = &ws_protocol_ambient_weather_decoder,
|
||||||
|
.encoder = &ws_protocol_ambient_weather_encoder,
|
||||||
|
};
|
||||||
|
|
||||||
|
void* ws_protocol_decoder_ambient_weather_alloc(SubGhzEnvironment* environment) {
|
||||||
|
UNUSED(environment);
|
||||||
|
WSProtocolDecoderAmbient_Weather* instance = malloc(sizeof(WSProtocolDecoderAmbient_Weather));
|
||||||
|
instance->base.protocol = &ws_protocol_ambient_weather;
|
||||||
|
instance->generic.protocol_name = instance->base.protocol->name;
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ws_protocol_decoder_ambient_weather_free(void* context) {
|
||||||
|
furi_assert(context);
|
||||||
|
WSProtocolDecoderAmbient_Weather* instance = context;
|
||||||
|
free(instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ws_protocol_decoder_ambient_weather_reset(void* context) {
|
||||||
|
furi_assert(context);
|
||||||
|
WSProtocolDecoderAmbient_Weather* instance = context;
|
||||||
|
manchester_advance(
|
||||||
|
instance->manchester_saved_state,
|
||||||
|
ManchesterEventReset,
|
||||||
|
&instance->manchester_saved_state,
|
||||||
|
NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool ws_protocol_ambient_weather_check_crc(WSProtocolDecoderAmbient_Weather* instance) {
|
||||||
|
uint8_t msg[] = {
|
||||||
|
instance->decoder.decode_data >> 40,
|
||||||
|
instance->decoder.decode_data >> 32,
|
||||||
|
instance->decoder.decode_data >> 24,
|
||||||
|
instance->decoder.decode_data >> 16,
|
||||||
|
instance->decoder.decode_data >> 8};
|
||||||
|
|
||||||
|
uint8_t crc = subghz_protocol_blocks_lfsr_digest8(msg, 5, 0x98, 0x3e) ^ 0x64;
|
||||||
|
return (crc == (uint8_t)(instance->decoder.decode_data & 0xFF));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Analysis of received data
|
||||||
|
* @param instance Pointer to a WSBlockGeneric* instance
|
||||||
|
*/
|
||||||
|
static void ws_protocol_ambient_weather_remote_controller(WSBlockGeneric* instance) {
|
||||||
|
instance->id = (instance->data >> 32) & 0xFF;
|
||||||
|
instance->battery_low = (instance->data >> 31) & 1;
|
||||||
|
instance->channel = ((instance->data >> 28) & 0x07) + 1;
|
||||||
|
instance->temp = ws_block_generic_fahrenheit_to_celsius(
|
||||||
|
((float)((instance->data >> 16) & 0x0FFF) - 400.0f) / 10.0f);
|
||||||
|
instance->humidity = (instance->data >> 8) & 0xFF;
|
||||||
|
instance->btn = WS_NO_BTN;
|
||||||
|
|
||||||
|
// ToDo maybe it won't be needed
|
||||||
|
/*
|
||||||
|
Sanity checks to reduce false positives and other bad data
|
||||||
|
Packets with Bad data often pass the MIC check.
|
||||||
|
- humidity > 100 (such as 255) and
|
||||||
|
- temperatures > 140 F (such as 369.5 F and 348.8 F
|
||||||
|
Specs in the F007TH and F012TH manuals state the range is:
|
||||||
|
- Temperature: -40 to 140 F
|
||||||
|
- Humidity: 10 to 99%
|
||||||
|
@todo - sanity check b[0] "model number"
|
||||||
|
- 0x45 - F007TH and F012TH
|
||||||
|
- 0x?5 - SwitchDocLabs F016TH temperature sensor (based on comment b[0] & 0x0f == 5)
|
||||||
|
- ? - TFA 30.3208.02
|
||||||
|
if (instance->humidity < 0 || instance->humidity > 100) {
|
||||||
|
ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (instance->temp < -40.0 || instance->temp > 140.0) {
|
||||||
|
ERROR;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
void ws_protocol_decoder_ambient_weather_feed(void* context, bool level, uint32_t duration) {
|
||||||
|
furi_assert(context);
|
||||||
|
WSProtocolDecoderAmbient_Weather* instance = context;
|
||||||
|
|
||||||
|
ManchesterEvent event = ManchesterEventReset;
|
||||||
|
if(!level) {
|
||||||
|
if(DURATION_DIFF(duration, ws_protocol_ambient_weather_const.te_short) <
|
||||||
|
ws_protocol_ambient_weather_const.te_delta) {
|
||||||
|
event = ManchesterEventShortLow;
|
||||||
|
} else if(
|
||||||
|
DURATION_DIFF(duration, ws_protocol_ambient_weather_const.te_long) <
|
||||||
|
ws_protocol_ambient_weather_const.te_delta * 2) {
|
||||||
|
event = ManchesterEventLongLow;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if(DURATION_DIFF(duration, ws_protocol_ambient_weather_const.te_short) <
|
||||||
|
ws_protocol_ambient_weather_const.te_delta) {
|
||||||
|
event = ManchesterEventShortHigh;
|
||||||
|
} else if(
|
||||||
|
DURATION_DIFF(duration, ws_protocol_ambient_weather_const.te_long) <
|
||||||
|
ws_protocol_ambient_weather_const.te_delta * 2) {
|
||||||
|
event = ManchesterEventLongHigh;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(event != ManchesterEventReset) {
|
||||||
|
bool data;
|
||||||
|
bool data_ok = manchester_advance(
|
||||||
|
instance->manchester_saved_state, event, &instance->manchester_saved_state, &data);
|
||||||
|
|
||||||
|
if(data_ok) {
|
||||||
|
instance->decoder.decode_data = (instance->decoder.decode_data << 1) | !data;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(((instance->decoder.decode_data & AMBIENT_WEATHER_PACKET_HEADER_MASK) ==
|
||||||
|
AMBIENT_WEATHER_PACKET_HEADER_1) ||
|
||||||
|
((instance->decoder.decode_data & AMBIENT_WEATHER_PACKET_HEADER_MASK) ==
|
||||||
|
AMBIENT_WEATHER_PACKET_HEADER_2)) {
|
||||||
|
if(ws_protocol_ambient_weather_check_crc(instance)) {
|
||||||
|
instance->decoder.decode_data = instance->decoder.decode_data;
|
||||||
|
instance->generic.data = instance->decoder.decode_data;
|
||||||
|
instance->generic.data_count_bit =
|
||||||
|
ws_protocol_ambient_weather_const.min_count_bit_for_found;
|
||||||
|
ws_protocol_ambient_weather_remote_controller(&instance->generic);
|
||||||
|
if(instance->base.callback)
|
||||||
|
instance->base.callback(&instance->base, instance->base.context);
|
||||||
|
instance->decoder.decode_data = 0;
|
||||||
|
instance->decoder.decode_count_bit = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
instance->decoder.decode_data = 0;
|
||||||
|
instance->decoder.decode_count_bit = 0;
|
||||||
|
manchester_advance(
|
||||||
|
instance->manchester_saved_state,
|
||||||
|
ManchesterEventReset,
|
||||||
|
&instance->manchester_saved_state,
|
||||||
|
NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t ws_protocol_decoder_ambient_weather_get_hash_data(void* context) {
|
||||||
|
furi_assert(context);
|
||||||
|
WSProtocolDecoderAmbient_Weather* instance = context;
|
||||||
|
return subghz_protocol_blocks_get_hash_data(
|
||||||
|
&instance->decoder, (instance->decoder.decode_count_bit / 8) + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ws_protocol_decoder_ambient_weather_serialize(
|
||||||
|
void* context,
|
||||||
|
FlipperFormat* flipper_format,
|
||||||
|
SubGhzRadioPreset* preset) {
|
||||||
|
furi_assert(context);
|
||||||
|
WSProtocolDecoderAmbient_Weather* instance = context;
|
||||||
|
return ws_block_generic_serialize(&instance->generic, flipper_format, preset);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ws_protocol_decoder_ambient_weather_deserialize(void* context, FlipperFormat* flipper_format) {
|
||||||
|
furi_assert(context);
|
||||||
|
WSProtocolDecoderAmbient_Weather* instance = context;
|
||||||
|
bool ret = false;
|
||||||
|
do {
|
||||||
|
if(!ws_block_generic_deserialize(&instance->generic, flipper_format)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(instance->generic.data_count_bit !=
|
||||||
|
ws_protocol_ambient_weather_const.min_count_bit_for_found) {
|
||||||
|
FURI_LOG_E(TAG, "Wrong number of bits in key");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
ret = true;
|
||||||
|
} while(false);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ws_protocol_decoder_ambient_weather_get_string(void* context, FuriString* output) {
|
||||||
|
furi_assert(context);
|
||||||
|
WSProtocolDecoderAmbient_Weather* instance = context;
|
||||||
|
furi_string_printf(
|
||||||
|
output,
|
||||||
|
"%s %dbit\r\n"
|
||||||
|
"Key:0x%lX%08lX\r\n"
|
||||||
|
"Sn:0x%lX Ch:%d Bat:%d\r\n"
|
||||||
|
"Temp:%d.%d C Hum:%d%%",
|
||||||
|
instance->generic.protocol_name,
|
||||||
|
instance->generic.data_count_bit,
|
||||||
|
(uint32_t)(instance->generic.data >> 32),
|
||||||
|
(uint32_t)(instance->generic.data),
|
||||||
|
instance->generic.id,
|
||||||
|
instance->generic.channel,
|
||||||
|
instance->generic.battery_low,
|
||||||
|
(int16_t)instance->generic.temp,
|
||||||
|
abs(((int16_t)(instance->generic.temp * 10) - (((int16_t)instance->generic.temp) * 10))),
|
||||||
|
instance->generic.humidity);
|
||||||
|
}
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <lib/subghz/protocols/base.h>
|
||||||
|
|
||||||
|
#include <lib/subghz/blocks/const.h>
|
||||||
|
#include <lib/subghz/blocks/decoder.h>
|
||||||
|
#include <lib/subghz/blocks/encoder.h>
|
||||||
|
#include "ws_generic.h"
|
||||||
|
#include <lib/subghz/blocks/math.h>
|
||||||
|
|
||||||
|
#define WS_PROTOCOL_AMBIENT_WEATHER_NAME "Ambient_Weather"
|
||||||
|
|
||||||
|
typedef struct WSProtocolDecoderAmbient_Weather WSProtocolDecoderAmbient_Weather;
|
||||||
|
typedef struct WSProtocolEncoderAmbient_Weather WSProtocolEncoderAmbient_Weather;
|
||||||
|
|
||||||
|
extern const SubGhzProtocolDecoder ws_protocol_ambient_weather_decoder;
|
||||||
|
extern const SubGhzProtocolEncoder ws_protocol_ambient_weather_encoder;
|
||||||
|
extern const SubGhzProtocol ws_protocol_ambient_weather;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allocate WSProtocolDecoderAmbient_Weather.
|
||||||
|
* @param environment Pointer to a SubGhzEnvironment instance
|
||||||
|
* @return WSProtocolDecoderAmbient_Weather* pointer to a WSProtocolDecoderAmbient_Weather instance
|
||||||
|
*/
|
||||||
|
void* ws_protocol_decoder_ambient_weather_alloc(SubGhzEnvironment* environment);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Free WSProtocolDecoderAmbient_Weather.
|
||||||
|
* @param context Pointer to a WSProtocolDecoderAmbient_Weather instance
|
||||||
|
*/
|
||||||
|
void ws_protocol_decoder_ambient_weather_free(void* context);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reset decoder WSProtocolDecoderAmbient_Weather.
|
||||||
|
* @param context Pointer to a WSProtocolDecoderAmbient_Weather instance
|
||||||
|
*/
|
||||||
|
void ws_protocol_decoder_ambient_weather_reset(void* context);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse a raw sequence of levels and durations received from the air.
|
||||||
|
* @param context Pointer to a WSProtocolDecoderAmbient_Weather instance
|
||||||
|
* @param level Signal level true-high false-low
|
||||||
|
* @param duration Duration of this level in, us
|
||||||
|
*/
|
||||||
|
void ws_protocol_decoder_ambient_weather_feed(void* context, bool level, uint32_t duration);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getting the hash sum of the last randomly received parcel.
|
||||||
|
* @param context Pointer to a WSProtocolDecoderAmbient_Weather instance
|
||||||
|
* @return hash Hash sum
|
||||||
|
*/
|
||||||
|
uint8_t ws_protocol_decoder_ambient_weather_get_hash_data(void* context);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serialize data WSProtocolDecoderAmbient_Weather.
|
||||||
|
* @param context Pointer to a WSProtocolDecoderAmbient_Weather instance
|
||||||
|
* @param flipper_format Pointer to a FlipperFormat instance
|
||||||
|
* @param preset The modulation on which the signal was received, SubGhzRadioPreset
|
||||||
|
* @return true On success
|
||||||
|
*/
|
||||||
|
bool ws_protocol_decoder_ambient_weather_serialize(
|
||||||
|
void* context,
|
||||||
|
FlipperFormat* flipper_format,
|
||||||
|
SubGhzRadioPreset* preset);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deserialize data WSProtocolDecoderAmbient_Weather.
|
||||||
|
* @param context Pointer to a WSProtocolDecoderAmbient_Weather instance
|
||||||
|
* @param flipper_format Pointer to a FlipperFormat instance
|
||||||
|
* @return true On success
|
||||||
|
*/
|
||||||
|
bool ws_protocol_decoder_ambient_weather_deserialize(void* context, FlipperFormat* flipper_format);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getting a textual representation of the received data.
|
||||||
|
* @param context Pointer to a WSProtocolDecoderAmbient_Weather instance
|
||||||
|
* @param output Resulting text
|
||||||
|
*/
|
||||||
|
void ws_protocol_decoder_ambient_weather_get_string(void* context, FuriString* output);
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Help
|
* Help
|
||||||
* https://github.com/merbanan/rtl_433/blob/5f0ff6db624270a4598958ab9dd79bb385ced3ef/src/devices/gt_wt_03.c
|
* https://github.com/merbanan/rtl_433/blob/master/src/devices/gt_wt_03.c
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* Globaltronics GT-WT-03 sensor on 433.92MHz.
|
* Globaltronics GT-WT-03 sensor on 433.92MHz.
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Help
|
* Help
|
||||||
* https://github.com/merbanan/rtl_433/blob/7e83cfd27d14247b6c3c81732bfe4a4f9a974d30/src/devices/lacrosse_tx141x.c
|
* https://github.com/merbanan/rtl_433/blob/master/src/devices/lacrosse_tx141x.c
|
||||||
*
|
*
|
||||||
* iiii iiii | bkcc tttt | tttt tttt | hhhh hhhh | cccc cccc | u
|
* iiii iiii | bkcc tttt | tttt tttt | hhhh hhhh | cccc cccc | u
|
||||||
* - i: identification; changes on battery switch
|
* - i: identification; changes on battery switch
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Help
|
* Help
|
||||||
* https://github.com/merbanan/rtl_433/blob/ef2d37cf51e3264d11cde9149ef87de2f0a4d37a/src/devices/nexus.c
|
* https://github.com/merbanan/rtl_433/blob/master/src/devices/nexus.c
|
||||||
*
|
*
|
||||||
* Nexus sensor protocol with ID, temperature and optional humidity
|
* Nexus sensor protocol with ID, temperature and optional humidity
|
||||||
* also FreeTec (Pearl) NC-7345 sensors for FreeTec Weatherstation NC-7344,
|
* also FreeTec (Pearl) NC-7345 sensors for FreeTec Weatherstation NC-7344,
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ const SubGhzProtocol* weather_station_protocol_registry_items[] = {
|
|||||||
&ws_protocol_lacrosse_tx141thbv2,
|
&ws_protocol_lacrosse_tx141thbv2,
|
||||||
&ws_protocol_oregon2,
|
&ws_protocol_oregon2,
|
||||||
&ws_protocol_acurite_592txr,
|
&ws_protocol_acurite_592txr,
|
||||||
|
&ws_protocol_ambient_weather,
|
||||||
};
|
};
|
||||||
|
|
||||||
const SubGhzProtocolRegistry weather_station_protocol_registry = {
|
const SubGhzProtocolRegistry weather_station_protocol_registry = {
|
||||||
|
|||||||
@@ -9,5 +9,6 @@
|
|||||||
#include "lacrosse_tx141thbv2.h"
|
#include "lacrosse_tx141thbv2.h"
|
||||||
#include "oregon2.h"
|
#include "oregon2.h"
|
||||||
#include "acurite_592txr.h"
|
#include "acurite_592txr.h"
|
||||||
|
#include "ambient_weather.h"
|
||||||
|
|
||||||
extern const SubGhzProtocolRegistry weather_station_protocol_registry;
|
extern const SubGhzProtocolRegistry weather_station_protocol_registry;
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ static bool pin_name_to_int(FuriString* pin_name, size_t* result) {
|
|||||||
bool debug = furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug);
|
bool debug = furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug);
|
||||||
for(size_t i = 0; i < COUNT_OF(cli_command_gpio_pins); i++) {
|
for(size_t i = 0; i < COUNT_OF(cli_command_gpio_pins); i++) {
|
||||||
if(!furi_string_cmp(pin_name, cli_command_gpio_pins[i].name)) {
|
if(!furi_string_cmp(pin_name, cli_command_gpio_pins[i].name)) {
|
||||||
if(!cli_command_gpio_pins[i].debug || (cli_command_gpio_pins[i].debug && debug)) {
|
if(!cli_command_gpio_pins[i].debug || debug) {
|
||||||
*result = i;
|
*result = i;
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
@@ -55,7 +55,7 @@ static void gpio_print_pins(void) {
|
|||||||
printf("Wrong pin name. Available pins: ");
|
printf("Wrong pin name. Available pins: ");
|
||||||
bool debug = furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug);
|
bool debug = furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug);
|
||||||
for(size_t i = 0; i < COUNT_OF(cli_command_gpio_pins); i++) {
|
for(size_t i = 0; i < COUNT_OF(cli_command_gpio_pins); i++) {
|
||||||
if(!cli_command_gpio_pins[i].debug || (cli_command_gpio_pins[i].debug && debug)) {
|
if(!cli_command_gpio_pins[i].debug || debug) {
|
||||||
printf("%s ", cli_command_gpio_pins[i].name);
|
printf("%s ", cli_command_gpio_pins[i].name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -160,7 +160,7 @@ static bool desktop_view_locked_input(InputEvent* event, void* context) {
|
|||||||
view_commit_model(locked_view->view, is_changed);
|
view_commit_model(locked_view->view, is_changed);
|
||||||
|
|
||||||
if(view_state == DesktopViewLockedStateUnlocked) {
|
if(view_state == DesktopViewLockedStateUnlocked) {
|
||||||
return view_state != DesktopViewLockedStateUnlocked;
|
return false;
|
||||||
} else if(view_state == DesktopViewLockedStateLocked && pin_locked) {
|
} else if(view_state == DesktopViewLockedStateLocked && pin_locked) {
|
||||||
locked_view->callback(DesktopLockedEventShowPinInput, locked_view->context);
|
locked_view->callback(DesktopLockedEventShowPinInput, locked_view->context);
|
||||||
} else if(
|
} else if(
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ App(
|
|||||||
order=70,
|
order=70,
|
||||||
sdk_headers=[
|
sdk_headers=[
|
||||||
"gui.h",
|
"gui.h",
|
||||||
|
"icon_i.h",
|
||||||
"elements.h",
|
"elements.h",
|
||||||
"view_dispatcher.h",
|
"view_dispatcher.h",
|
||||||
"view_stack.h",
|
"view_stack.h",
|
||||||
|
|||||||
@@ -304,8 +304,7 @@ void view_dispatcher_handle_custom_event(ViewDispatcher* view_dispatcher, uint32
|
|||||||
}
|
}
|
||||||
// If custom event is not consumed in View, call callback
|
// If custom event is not consumed in View, call callback
|
||||||
if(!is_consumed && view_dispatcher->custom_event_callback) {
|
if(!is_consumed && view_dispatcher->custom_event_callback) {
|
||||||
is_consumed =
|
view_dispatcher->custom_event_callback(view_dispatcher->event_context, event);
|
||||||
view_dispatcher->custom_event_callback(view_dispatcher->event_context, event);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,61 +7,51 @@
|
|||||||
|
|
||||||
// TODO add mutex to view_port ops
|
// TODO add mutex to view_port ops
|
||||||
|
|
||||||
static void view_port_remap_buttons_vertical(InputEvent* event) {
|
_Static_assert(ViewPortOrientationMAX == 4, "Incorrect ViewPortOrientation count");
|
||||||
switch(event->key) {
|
_Static_assert(
|
||||||
case InputKeyUp:
|
(ViewPortOrientationHorizontal == 0 && ViewPortOrientationHorizontalFlip == 1 &&
|
||||||
event->key = InputKeyRight;
|
ViewPortOrientationVertical == 2 && ViewPortOrientationVerticalFlip == 3),
|
||||||
break;
|
"Incorrect ViewPortOrientation order");
|
||||||
case InputKeyDown:
|
_Static_assert(InputKeyMAX == 6, "Incorrect InputKey count");
|
||||||
event->key = InputKeyLeft;
|
_Static_assert(
|
||||||
break;
|
(InputKeyUp == 0 && InputKeyDown == 1 && InputKeyRight == 2 && InputKeyLeft == 3 &&
|
||||||
case InputKeyRight:
|
InputKeyOk == 4 && InputKeyBack == 5),
|
||||||
event->key = InputKeyDown;
|
"Incorrect InputKey order");
|
||||||
break;
|
|
||||||
case InputKeyLeft:
|
|
||||||
event->key = InputKeyUp;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void view_port_remap_buttons_vertical_flip(InputEvent* event) {
|
/** InputKey directional keys mappings for different screen orientations
|
||||||
switch(event->key) {
|
*
|
||||||
case InputKeyUp:
|
*/
|
||||||
event->key = InputKeyLeft;
|
static const InputKey view_port_input_mapping[ViewPortOrientationMAX][InputKeyMAX] = {
|
||||||
break;
|
{InputKeyUp,
|
||||||
case InputKeyDown:
|
InputKeyDown,
|
||||||
event->key = InputKeyRight;
|
InputKeyRight,
|
||||||
break;
|
InputKeyLeft,
|
||||||
case InputKeyRight:
|
InputKeyOk,
|
||||||
event->key = InputKeyUp;
|
InputKeyBack}, //ViewPortOrientationHorizontal
|
||||||
break;
|
{InputKeyDown,
|
||||||
case InputKeyLeft:
|
InputKeyUp,
|
||||||
event->key = InputKeyDown;
|
InputKeyLeft,
|
||||||
break;
|
InputKeyRight,
|
||||||
default:
|
InputKeyOk,
|
||||||
break;
|
InputKeyBack}, //ViewPortOrientationHorizontalFlip
|
||||||
}
|
{InputKeyRight,
|
||||||
}
|
InputKeyLeft,
|
||||||
|
InputKeyDown,
|
||||||
|
InputKeyUp,
|
||||||
|
InputKeyOk,
|
||||||
|
InputKeyBack}, //ViewPortOrientationVertical
|
||||||
|
{InputKeyLeft,
|
||||||
|
InputKeyRight,
|
||||||
|
InputKeyUp,
|
||||||
|
InputKeyDown,
|
||||||
|
InputKeyOk,
|
||||||
|
InputKeyBack}, //ViewPortOrientationVerticalFlip
|
||||||
|
};
|
||||||
|
|
||||||
static void view_port_remap_buttons_horizontal_flip(InputEvent* event) {
|
// Remaps directional pad buttons on Flipper based on ViewPort orientation
|
||||||
switch(event->key) {
|
static void view_port_map_input(InputEvent* event, ViewPortOrientation orientation) {
|
||||||
case InputKeyUp:
|
furi_assert(orientation < ViewPortOrientationMAX && event->key < InputKeyMAX);
|
||||||
event->key = InputKeyDown;
|
event->key = view_port_input_mapping[orientation][event->key];
|
||||||
break;
|
|
||||||
case InputKeyDown:
|
|
||||||
event->key = InputKeyUp;
|
|
||||||
break;
|
|
||||||
case InputKeyRight:
|
|
||||||
event->key = InputKeyLeft;
|
|
||||||
break;
|
|
||||||
case InputKeyLeft:
|
|
||||||
event->key = InputKeyRight;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void view_port_setup_canvas_orientation(const ViewPort* view_port, Canvas* canvas) {
|
static void view_port_setup_canvas_orientation(const ViewPort* view_port, Canvas* canvas) {
|
||||||
@@ -170,19 +160,7 @@ void view_port_input(ViewPort* view_port, InputEvent* event) {
|
|||||||
|
|
||||||
if(view_port->input_callback) {
|
if(view_port->input_callback) {
|
||||||
ViewPortOrientation orientation = view_port_get_orientation(view_port);
|
ViewPortOrientation orientation = view_port_get_orientation(view_port);
|
||||||
switch(orientation) {
|
view_port_map_input(event, orientation);
|
||||||
case ViewPortOrientationHorizontalFlip:
|
|
||||||
view_port_remap_buttons_horizontal_flip(event);
|
|
||||||
break;
|
|
||||||
case ViewPortOrientationVertical:
|
|
||||||
view_port_remap_buttons_vertical(event);
|
|
||||||
break;
|
|
||||||
case ViewPortOrientationVerticalFlip:
|
|
||||||
view_port_remap_buttons_vertical_flip(event);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
view_port->input_callback(event, view_port->input_callback_context);
|
view_port->input_callback(event, view_port->input_callback_context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ typedef enum {
|
|||||||
ViewPortOrientationHorizontalFlip,
|
ViewPortOrientationHorizontalFlip,
|
||||||
ViewPortOrientationVertical,
|
ViewPortOrientationVertical,
|
||||||
ViewPortOrientationVerticalFlip,
|
ViewPortOrientationVerticalFlip,
|
||||||
|
ViewPortOrientationMAX, /**< Special value, don't use it */
|
||||||
} ViewPortOrientation;
|
} ViewPortOrientation;
|
||||||
|
|
||||||
/** ViewPort Draw callback
|
/** ViewPort Draw callback
|
||||||
|
|||||||
@@ -60,8 +60,9 @@ const char* input_get_type_name(InputType type) {
|
|||||||
return "Long";
|
return "Long";
|
||||||
case InputTypeRepeat:
|
case InputTypeRepeat:
|
||||||
return "Repeat";
|
return "Repeat";
|
||||||
|
default:
|
||||||
|
return "Unknown";
|
||||||
}
|
}
|
||||||
return "Unknown";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t input_srv(void* p) {
|
int32_t input_srv(void* p) {
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ typedef enum {
|
|||||||
InputTypeShort, /**< Short event, emitted after InputTypeRelease done withing INPUT_LONG_PRESS interval */
|
InputTypeShort, /**< Short event, emitted after InputTypeRelease done withing INPUT_LONG_PRESS interval */
|
||||||
InputTypeLong, /**< Long event, emmited after INPUT_LONG_PRESS interval, asynchronouse to InputTypeRelease */
|
InputTypeLong, /**< Long event, emmited after INPUT_LONG_PRESS interval, asynchronouse to InputTypeRelease */
|
||||||
InputTypeRepeat, /**< Repeat event, emmited with INPUT_REPEATE_PRESS period after InputTypeLong event */
|
InputTypeRepeat, /**< Repeat event, emmited with INPUT_REPEATE_PRESS period after InputTypeLong event */
|
||||||
|
InputTypeMAX, /**< Special value for exceptional */
|
||||||
} InputType;
|
} InputType;
|
||||||
|
|
||||||
/** Input Event, dispatches with FuriPubSub */
|
/** Input Event, dispatches with FuriPubSub */
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ static const uint8_t reset_blink_mask = 1 << 6;
|
|||||||
|
|
||||||
void notification_vibro_on();
|
void notification_vibro_on();
|
||||||
void notification_vibro_off();
|
void notification_vibro_off();
|
||||||
void notification_sound_on(float pwm, float freq);
|
void notification_sound_on(float freq, float volume);
|
||||||
void notification_sound_off();
|
void notification_sound_off();
|
||||||
|
|
||||||
uint8_t notification_settings_get_display_brightness(NotificationApp* app, uint8_t value);
|
uint8_t notification_settings_get_display_brightness(NotificationApp* app, uint8_t value);
|
||||||
|
|||||||
@@ -138,6 +138,41 @@ static void rpc_system_storage_info_process(const PB_Main* request, void* contex
|
|||||||
furi_record_close(RECORD_STORAGE);
|
furi_record_close(RECORD_STORAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void rpc_system_storage_timestamp_process(const PB_Main* request, void* context) {
|
||||||
|
furi_assert(request);
|
||||||
|
furi_assert(context);
|
||||||
|
furi_assert(request->which_content == PB_Main_storage_timestamp_request_tag);
|
||||||
|
|
||||||
|
FURI_LOG_D(TAG, "Timestamp");
|
||||||
|
|
||||||
|
RpcStorageSystem* rpc_storage = context;
|
||||||
|
RpcSession* session = rpc_storage->session;
|
||||||
|
furi_assert(session);
|
||||||
|
|
||||||
|
rpc_system_storage_reset_state(rpc_storage, session, true);
|
||||||
|
|
||||||
|
PB_Main* response = malloc(sizeof(PB_Main));
|
||||||
|
response->command_id = request->command_id;
|
||||||
|
|
||||||
|
Storage* fs_api = furi_record_open(RECORD_STORAGE);
|
||||||
|
|
||||||
|
const char* path = request->content.storage_timestamp_request.path;
|
||||||
|
uint32_t timestamp = 0;
|
||||||
|
FS_Error error = storage_common_timestamp(fs_api, path, ×tamp);
|
||||||
|
|
||||||
|
response->command_status = rpc_system_storage_get_error(error);
|
||||||
|
response->which_content = PB_Main_empty_tag;
|
||||||
|
|
||||||
|
if(error == FSE_OK) {
|
||||||
|
response->which_content = PB_Main_storage_timestamp_response_tag;
|
||||||
|
response->content.storage_timestamp_response.timestamp = timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
rpc_send_and_release(session, response);
|
||||||
|
free(response);
|
||||||
|
furi_record_close(RECORD_STORAGE);
|
||||||
|
}
|
||||||
|
|
||||||
static void rpc_system_storage_stat_process(const PB_Main* request, void* context) {
|
static void rpc_system_storage_stat_process(const PB_Main* request, void* context) {
|
||||||
furi_assert(request);
|
furi_assert(request);
|
||||||
furi_assert(context);
|
furi_assert(context);
|
||||||
@@ -405,6 +440,10 @@ static void rpc_system_storage_write_process(const PB_Main* request, void* conte
|
|||||||
if(!fs_operation_success) {
|
if(!fs_operation_success) {
|
||||||
send_response = true;
|
send_response = true;
|
||||||
command_status = rpc_system_storage_get_file_error(file);
|
command_status = rpc_system_storage_get_file_error(file);
|
||||||
|
if(command_status == PB_CommandStatus_OK) {
|
||||||
|
// Report errors not handled by underlying APIs
|
||||||
|
command_status = PB_CommandStatus_ERROR_STORAGE_INTERNAL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(send_response) {
|
if(send_response) {
|
||||||
@@ -668,6 +707,9 @@ void* rpc_system_storage_alloc(RpcSession* session) {
|
|||||||
rpc_handler.message_handler = rpc_system_storage_info_process;
|
rpc_handler.message_handler = rpc_system_storage_info_process;
|
||||||
rpc_add_handler(session, PB_Main_storage_info_request_tag, &rpc_handler);
|
rpc_add_handler(session, PB_Main_storage_info_request_tag, &rpc_handler);
|
||||||
|
|
||||||
|
rpc_handler.message_handler = rpc_system_storage_timestamp_process;
|
||||||
|
rpc_add_handler(session, PB_Main_storage_timestamp_request_tag, &rpc_handler);
|
||||||
|
|
||||||
rpc_handler.message_handler = rpc_system_storage_stat_process;
|
rpc_handler.message_handler = rpc_system_storage_stat_process;
|
||||||
rpc_add_handler(session, PB_Main_storage_stat_request_tag, &rpc_handler);
|
rpc_add_handler(session, PB_Main_storage_stat_request_tag, &rpc_handler);
|
||||||
|
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ Storage* storage_app_alloc() {
|
|||||||
|
|
||||||
for(uint8_t i = 0; i < STORAGE_COUNT; i++) {
|
for(uint8_t i = 0; i < STORAGE_COUNT; i++) {
|
||||||
storage_data_init(&app->storage[i]);
|
storage_data_init(&app->storage[i]);
|
||||||
|
storage_data_timestamp(&app->storage[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef FURI_RAM_EXEC
|
#ifndef FURI_RAM_EXEC
|
||||||
|
|||||||
@@ -177,6 +177,16 @@ bool storage_dir_rewind(File* file);
|
|||||||
|
|
||||||
/******************* Common Functions *******************/
|
/******************* Common Functions *******************/
|
||||||
|
|
||||||
|
/** Retrieves unix timestamp of last access
|
||||||
|
*
|
||||||
|
* @param storage The storage instance
|
||||||
|
* @param path path to file/directory
|
||||||
|
* @param timestamp the timestamp pointer
|
||||||
|
*
|
||||||
|
* @return FS_Error operation result
|
||||||
|
*/
|
||||||
|
FS_Error storage_common_timestamp(Storage* storage, const char* path, uint32_t* timestamp);
|
||||||
|
|
||||||
/** Retrieves information about a file/directory
|
/** Retrieves information about a file/directory
|
||||||
* @param app pointer to the api
|
* @param app pointer to the api
|
||||||
* @param path path to file/directory
|
* @param path path to file/directory
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ static void storage_cli_print_usage() {
|
|||||||
printf("\tmkdir\t - creates a new directory\r\n");
|
printf("\tmkdir\t - creates a new directory\r\n");
|
||||||
printf("\tmd5\t - md5 hash of the file\r\n");
|
printf("\tmd5\t - md5 hash of the file\r\n");
|
||||||
printf("\tstat\t - info about file or dir\r\n");
|
printf("\tstat\t - info about file or dir\r\n");
|
||||||
|
printf("\ttimestamp\t - last modification timestamp\r\n");
|
||||||
};
|
};
|
||||||
|
|
||||||
static void storage_cli_print_error(FS_Error error) {
|
static void storage_cli_print_error(FS_Error error) {
|
||||||
@@ -386,6 +387,22 @@ static void storage_cli_stat(Cli* cli, FuriString* path) {
|
|||||||
furi_record_close(RECORD_STORAGE);
|
furi_record_close(RECORD_STORAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void storage_cli_timestamp(Cli* cli, FuriString* path) {
|
||||||
|
UNUSED(cli);
|
||||||
|
Storage* api = furi_record_open(RECORD_STORAGE);
|
||||||
|
|
||||||
|
uint32_t timestamp = 0;
|
||||||
|
FS_Error error = storage_common_timestamp(api, furi_string_get_cstr(path), ×tamp);
|
||||||
|
|
||||||
|
if(error != FSE_OK) {
|
||||||
|
printf("Invalid arguments\r\n");
|
||||||
|
} else {
|
||||||
|
printf("Timestamp %lu\r\n", timestamp);
|
||||||
|
}
|
||||||
|
|
||||||
|
furi_record_close(RECORD_STORAGE);
|
||||||
|
}
|
||||||
|
|
||||||
static void storage_cli_copy(Cli* cli, FuriString* old_path, FuriString* args) {
|
static void storage_cli_copy(Cli* cli, FuriString* old_path, FuriString* args) {
|
||||||
UNUSED(cli);
|
UNUSED(cli);
|
||||||
Storage* api = furi_record_open(RECORD_STORAGE);
|
Storage* api = furi_record_open(RECORD_STORAGE);
|
||||||
@@ -578,6 +595,11 @@ void storage_cli(Cli* cli, FuriString* args, void* context) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(furi_string_cmp_str(cmd, "timestamp") == 0) {
|
||||||
|
storage_cli_timestamp(cli, path);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
storage_cli_print_usage();
|
storage_cli_print_usage();
|
||||||
} while(false);
|
} while(false);
|
||||||
|
|
||||||
|
|||||||
@@ -354,6 +354,16 @@ bool storage_dir_rewind(File* file) {
|
|||||||
|
|
||||||
/****************** COMMON ******************/
|
/****************** COMMON ******************/
|
||||||
|
|
||||||
|
FS_Error storage_common_timestamp(Storage* storage, const char* path, uint32_t* timestamp) {
|
||||||
|
S_API_PROLOGUE;
|
||||||
|
|
||||||
|
SAData data = {.ctimestamp = {.path = path, .timestamp = timestamp}};
|
||||||
|
|
||||||
|
S_API_MESSAGE(StorageCommandCommonTimestamp);
|
||||||
|
S_API_EPILOGUE;
|
||||||
|
return S_RETURN_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
FS_Error storage_common_stat(Storage* storage, const char* path, FileInfo* fileinfo) {
|
FS_Error storage_common_stat(Storage* storage, const char* path, FileInfo* fileinfo) {
|
||||||
S_API_PROLOGUE;
|
S_API_PROLOGUE;
|
||||||
|
|
||||||
|
|||||||
@@ -82,6 +82,14 @@ const char* storage_data_status_text(StorageData* storage) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void storage_data_timestamp(StorageData* storage) {
|
||||||
|
storage->timestamp = furi_hal_rtc_get_timestamp();
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t storage_data_get_timestamp(StorageData* storage) {
|
||||||
|
return storage->timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
/****************** storage glue ******************/
|
/****************** storage glue ******************/
|
||||||
|
|
||||||
bool storage_has_file(const File* file, StorageData* storage_data) {
|
bool storage_has_file(const File* file, StorageData* storage_data) {
|
||||||
|
|||||||
@@ -42,6 +42,8 @@ bool storage_data_lock(StorageData* storage);
|
|||||||
bool storage_data_unlock(StorageData* storage);
|
bool storage_data_unlock(StorageData* storage);
|
||||||
StorageStatus storage_data_status(StorageData* storage);
|
StorageStatus storage_data_status(StorageData* storage);
|
||||||
const char* storage_data_status_text(StorageData* storage);
|
const char* storage_data_status_text(StorageData* storage);
|
||||||
|
void storage_data_timestamp(StorageData* storage);
|
||||||
|
uint32_t storage_data_get_timestamp(StorageData* storage);
|
||||||
|
|
||||||
LIST_DEF(
|
LIST_DEF(
|
||||||
StorageFileList,
|
StorageFileList,
|
||||||
@@ -58,6 +60,7 @@ struct StorageData {
|
|||||||
FuriMutex* mutex;
|
FuriMutex* mutex;
|
||||||
StorageStatus status;
|
StorageStatus status;
|
||||||
StorageFileList_t files;
|
StorageFileList_t files;
|
||||||
|
uint32_t timestamp;
|
||||||
};
|
};
|
||||||
|
|
||||||
bool storage_has_file(const File* file, StorageData* storage_data);
|
bool storage_has_file(const File* file, StorageData* storage_data);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <furi.h>
|
#include <furi.h>
|
||||||
|
#include <furi_hal.h>
|
||||||
#include <gui/gui.h>
|
#include <gui/gui.h>
|
||||||
#include "storage_glue.h"
|
#include "storage_glue.h"
|
||||||
#include "storage_sd_api.h"
|
#include "storage_sd_api.h"
|
||||||
|
|||||||
@@ -42,6 +42,11 @@ typedef struct {
|
|||||||
uint16_t name_length;
|
uint16_t name_length;
|
||||||
} SADataDRead;
|
} SADataDRead;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
const char* path;
|
||||||
|
uint32_t* timestamp;
|
||||||
|
} SADataCTimestamp;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
const char* path;
|
const char* path;
|
||||||
FileInfo* fileinfo;
|
FileInfo* fileinfo;
|
||||||
@@ -78,6 +83,7 @@ typedef union {
|
|||||||
SADataDOpen dopen;
|
SADataDOpen dopen;
|
||||||
SADataDRead dread;
|
SADataDRead dread;
|
||||||
|
|
||||||
|
SADataCTimestamp ctimestamp;
|
||||||
SADataCStat cstat;
|
SADataCStat cstat;
|
||||||
SADataCFSInfo cfsinfo;
|
SADataCFSInfo cfsinfo;
|
||||||
|
|
||||||
@@ -112,6 +118,7 @@ typedef enum {
|
|||||||
StorageCommandDirClose,
|
StorageCommandDirClose,
|
||||||
StorageCommandDirRead,
|
StorageCommandDirRead,
|
||||||
StorageCommandDirRewind,
|
StorageCommandDirRewind,
|
||||||
|
StorageCommandCommonTimestamp,
|
||||||
StorageCommandCommonStat,
|
StorageCommandCommonStat,
|
||||||
StorageCommandCommonRemove,
|
StorageCommandCommonRemove,
|
||||||
StorageCommandCommonMkDir,
|
StorageCommandCommonMkDir,
|
||||||
|
|||||||
@@ -114,6 +114,9 @@ bool storage_process_file_open(
|
|||||||
if(storage_path_already_open(real_path, storage->files)) {
|
if(storage_path_already_open(real_path, storage->files)) {
|
||||||
file->error_id = FSE_ALREADY_OPEN;
|
file->error_id = FSE_ALREADY_OPEN;
|
||||||
} else {
|
} else {
|
||||||
|
if(access_mode & FSAM_WRITE) {
|
||||||
|
storage_data_timestamp(storage);
|
||||||
|
}
|
||||||
storage_push_storage_file(file, real_path, type, storage);
|
storage_push_storage_file(file, real_path, type, storage);
|
||||||
FS_CALL(storage, file.open(storage, file, remove_vfs(path), access_mode, open_mode));
|
FS_CALL(storage, file.open(storage, file, remove_vfs(path), access_mode, open_mode));
|
||||||
}
|
}
|
||||||
@@ -166,6 +169,7 @@ static uint16_t storage_process_file_write(
|
|||||||
if(storage == NULL) {
|
if(storage == NULL) {
|
||||||
file->error_id = FSE_INVALID_PARAMETER;
|
file->error_id = FSE_INVALID_PARAMETER;
|
||||||
} else {
|
} else {
|
||||||
|
storage_data_timestamp(storage);
|
||||||
FS_CALL(storage, file.write(storage, file, buff, bytes_to_write));
|
FS_CALL(storage, file.write(storage, file, buff, bytes_to_write));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -209,6 +213,7 @@ static bool storage_process_file_truncate(Storage* app, File* file) {
|
|||||||
if(storage == NULL) {
|
if(storage == NULL) {
|
||||||
file->error_id = FSE_INVALID_PARAMETER;
|
file->error_id = FSE_INVALID_PARAMETER;
|
||||||
} else {
|
} else {
|
||||||
|
storage_data_timestamp(storage);
|
||||||
FS_CALL(storage, file.truncate(storage, file));
|
FS_CALL(storage, file.truncate(storage, file));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,6 +227,7 @@ static bool storage_process_file_sync(Storage* app, File* file) {
|
|||||||
if(storage == NULL) {
|
if(storage == NULL) {
|
||||||
file->error_id = FSE_INVALID_PARAMETER;
|
file->error_id = FSE_INVALID_PARAMETER;
|
||||||
} else {
|
} else {
|
||||||
|
storage_data_timestamp(storage);
|
||||||
FS_CALL(storage, file.sync(storage, file));
|
FS_CALL(storage, file.sync(storage, file));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -332,6 +338,21 @@ bool storage_process_dir_rewind(Storage* app, File* file) {
|
|||||||
|
|
||||||
/******************* Common FS Functions *******************/
|
/******************* Common FS Functions *******************/
|
||||||
|
|
||||||
|
static FS_Error
|
||||||
|
storage_process_common_timestamp(Storage* app, const char* path, uint32_t* timestamp) {
|
||||||
|
FS_Error ret = FSE_OK;
|
||||||
|
StorageType type = storage_get_type_by_path(app, path);
|
||||||
|
|
||||||
|
if(storage_type_is_not_valid(type)) {
|
||||||
|
ret = FSE_INVALID_NAME;
|
||||||
|
} else {
|
||||||
|
StorageData* storage = storage_get_storage_by_type(app, type);
|
||||||
|
*timestamp = storage_data_get_timestamp(storage);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
static FS_Error storage_process_common_stat(Storage* app, const char* path, FileInfo* fileinfo) {
|
static FS_Error storage_process_common_stat(Storage* app, const char* path, FileInfo* fileinfo) {
|
||||||
FS_Error ret = FSE_OK;
|
FS_Error ret = FSE_OK;
|
||||||
StorageType type = storage_get_type_by_path(app, path);
|
StorageType type = storage_get_type_by_path(app, path);
|
||||||
@@ -366,6 +387,7 @@ static FS_Error storage_process_common_remove(Storage* app, const char* path) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
storage_data_timestamp(storage);
|
||||||
FS_CALL(storage, common.remove(storage, remove_vfs(path)));
|
FS_CALL(storage, common.remove(storage, remove_vfs(path)));
|
||||||
} while(false);
|
} while(false);
|
||||||
|
|
||||||
@@ -382,6 +404,7 @@ static FS_Error storage_process_common_mkdir(Storage* app, const char* path) {
|
|||||||
ret = FSE_INVALID_NAME;
|
ret = FSE_INVALID_NAME;
|
||||||
} else {
|
} else {
|
||||||
StorageData* storage = storage_get_storage_by_type(app, type);
|
StorageData* storage = storage_get_storage_by_type(app, type);
|
||||||
|
storage_data_timestamp(storage);
|
||||||
FS_CALL(storage, common.mkdir(storage, remove_vfs(path)));
|
FS_CALL(storage, common.mkdir(storage, remove_vfs(path)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -417,6 +440,7 @@ static FS_Error storage_process_sd_format(Storage* app) {
|
|||||||
ret = FSE_NOT_READY;
|
ret = FSE_NOT_READY;
|
||||||
} else {
|
} else {
|
||||||
ret = sd_format_card(&app->storage[ST_EXT]);
|
ret = sd_format_card(&app->storage[ST_EXT]);
|
||||||
|
storage_data_timestamp(&app->storage[ST_EXT]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@@ -429,6 +453,7 @@ static FS_Error storage_process_sd_unmount(Storage* app) {
|
|||||||
ret = FSE_NOT_READY;
|
ret = FSE_NOT_READY;
|
||||||
} else {
|
} else {
|
||||||
sd_unmount_card(&app->storage[ST_EXT]);
|
sd_unmount_card(&app->storage[ST_EXT]);
|
||||||
|
storage_data_timestamp(&app->storage[ST_EXT]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@@ -541,6 +566,10 @@ void storage_process_message_internal(Storage* app, StorageMessage* message) {
|
|||||||
message->return_data->bool_value =
|
message->return_data->bool_value =
|
||||||
storage_process_dir_rewind(app, message->data->file.file);
|
storage_process_dir_rewind(app, message->data->file.file);
|
||||||
break;
|
break;
|
||||||
|
case StorageCommandCommonTimestamp:
|
||||||
|
message->return_data->error_value = storage_process_common_timestamp(
|
||||||
|
app, message->data->ctimestamp.path, message->data->ctimestamp.timestamp);
|
||||||
|
break;
|
||||||
case StorageCommandCommonStat:
|
case StorageCommandCommonStat:
|
||||||
message->return_data->error_value = storage_process_common_stat(
|
message->return_data->error_value = storage_process_common_stat(
|
||||||
app, message->data->cstat.path, message->data->cstat.fileinfo);
|
app, message->data->cstat.path, message->data->cstat.fileinfo);
|
||||||
|
|||||||
@@ -90,6 +90,7 @@ static bool sd_mount_card(StorageData* storage, bool notify) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
storage_data_timestamp(storage);
|
||||||
storage_data_unlock(storage);
|
storage_data_unlock(storage);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -3,6 +3,9 @@
|
|||||||
#include <gui/elements.h>
|
#include <gui/elements.h>
|
||||||
#include <assets_icons.h>
|
#include <assets_icons.h>
|
||||||
|
|
||||||
|
#define LOW_CHARGE_THRESHOLD 10
|
||||||
|
#define HIGH_DRAIN_CURRENT_THRESHOLD 100
|
||||||
|
|
||||||
struct BatteryInfo {
|
struct BatteryInfo {
|
||||||
View* view;
|
View* view;
|
||||||
};
|
};
|
||||||
@@ -28,9 +31,9 @@ static void draw_battery(Canvas* canvas, BatteryInfoModel* data, int x, int y) {
|
|||||||
canvas_draw_icon(canvas, x, y, &I_BatteryBody_52x28);
|
canvas_draw_icon(canvas, x, y, &I_BatteryBody_52x28);
|
||||||
if(charge_current > 0) {
|
if(charge_current > 0) {
|
||||||
canvas_draw_icon(canvas, x + 16, y + 7, &I_FaceCharging_29x14);
|
canvas_draw_icon(canvas, x + 16, y + 7, &I_FaceCharging_29x14);
|
||||||
} else if(drain_current > 100) {
|
} else if(drain_current > HIGH_DRAIN_CURRENT_THRESHOLD) {
|
||||||
canvas_draw_icon(canvas, x + 16, y + 7, &I_FaceConfused_29x14);
|
canvas_draw_icon(canvas, x + 16, y + 7, &I_FaceConfused_29x14);
|
||||||
} else if(data->charge < 10) {
|
} else if(data->charge < LOW_CHARGE_THRESHOLD) {
|
||||||
canvas_draw_icon(canvas, x + 16, y + 7, &I_FaceNopower_29x14);
|
canvas_draw_icon(canvas, x + 16, y + 7, &I_FaceNopower_29x14);
|
||||||
} else {
|
} else {
|
||||||
canvas_draw_icon(canvas, x + 16, y + 7, &I_FaceNormal_29x14);
|
canvas_draw_icon(canvas, x + 16, y + 7, &I_FaceNormal_29x14);
|
||||||
@@ -51,11 +54,19 @@ static void draw_battery(Canvas* canvas, BatteryInfoModel* data, int x, int y) {
|
|||||||
(uint32_t)(data->vbus_voltage * 10) % 10,
|
(uint32_t)(data->vbus_voltage * 10) % 10,
|
||||||
charge_current);
|
charge_current);
|
||||||
} else if(drain_current > 0) {
|
} else if(drain_current > 0) {
|
||||||
snprintf(emote, sizeof(emote), "%s", drain_current > 100 ? "Oh no!" : "Om-nom-nom!");
|
snprintf(
|
||||||
|
emote,
|
||||||
|
sizeof(emote),
|
||||||
|
"%s",
|
||||||
|
drain_current > HIGH_DRAIN_CURRENT_THRESHOLD ? "Oh no!" : "Om-nom-nom!");
|
||||||
snprintf(header, sizeof(header), "%s", "Consumption is");
|
snprintf(header, sizeof(header), "%s", "Consumption is");
|
||||||
snprintf(
|
snprintf(
|
||||||
value, sizeof(value), "%ld %s", drain_current, drain_current > 100 ? "mA!" : "mA");
|
value,
|
||||||
} else if(charge_current != 0 || drain_current != 0) {
|
sizeof(value),
|
||||||
|
"%ld %s",
|
||||||
|
drain_current,
|
||||||
|
drain_current > HIGH_DRAIN_CURRENT_THRESHOLD ? "mA!" : "mA");
|
||||||
|
} else if(drain_current != 0) {
|
||||||
snprintf(header, 20, "...");
|
snprintf(header, 20, "...");
|
||||||
} else {
|
} else {
|
||||||
snprintf(header, sizeof(header), "Charged!");
|
snprintf(header, sizeof(header), "Charged!");
|
||||||
|
|||||||
BIN
assets/dolphin/external/L1_Mods_128x64/frame_0.png
vendored
Normal file
|
After Width: | Height: | Size: 4.2 KiB |
BIN
assets/dolphin/external/L1_Mods_128x64/frame_1.png
vendored
Normal file
|
After Width: | Height: | Size: 4.2 KiB |
BIN
assets/dolphin/external/L1_Mods_128x64/frame_10.png
vendored
Normal file
|
After Width: | Height: | Size: 4.3 KiB |
BIN
assets/dolphin/external/L1_Mods_128x64/frame_11.png
vendored
Normal file
|
After Width: | Height: | Size: 4.2 KiB |
BIN
assets/dolphin/external/L1_Mods_128x64/frame_12.png
vendored
Normal file
|
After Width: | Height: | Size: 4.2 KiB |
BIN
assets/dolphin/external/L1_Mods_128x64/frame_13.png
vendored
Normal file
|
After Width: | Height: | Size: 4.3 KiB |
BIN
assets/dolphin/external/L1_Mods_128x64/frame_14.png
vendored
Normal file
|
After Width: | Height: | Size: 4.2 KiB |
BIN
assets/dolphin/external/L1_Mods_128x64/frame_15.png
vendored
Normal file
|
After Width: | Height: | Size: 4.2 KiB |
BIN
assets/dolphin/external/L1_Mods_128x64/frame_16.png
vendored
Normal file
|
After Width: | Height: | Size: 4.2 KiB |
BIN
assets/dolphin/external/L1_Mods_128x64/frame_17.png
vendored
Normal file
|
After Width: | Height: | Size: 4.2 KiB |
BIN
assets/dolphin/external/L1_Mods_128x64/frame_18.png
vendored
Normal file
|
After Width: | Height: | Size: 4.2 KiB |
BIN
assets/dolphin/external/L1_Mods_128x64/frame_19.png
vendored
Normal file
|
After Width: | Height: | Size: 4.2 KiB |
BIN
assets/dolphin/external/L1_Mods_128x64/frame_2.png
vendored
Normal file
|
After Width: | Height: | Size: 4.2 KiB |
BIN
assets/dolphin/external/L1_Mods_128x64/frame_20.png
vendored
Normal file
|
After Width: | Height: | Size: 4.2 KiB |
BIN
assets/dolphin/external/L1_Mods_128x64/frame_21.png
vendored
Normal file
|
After Width: | Height: | Size: 4.3 KiB |
BIN
assets/dolphin/external/L1_Mods_128x64/frame_22.png
vendored
Normal file
|
After Width: | Height: | Size: 4.2 KiB |
BIN
assets/dolphin/external/L1_Mods_128x64/frame_23.png
vendored
Normal file
|
After Width: | Height: | Size: 4.2 KiB |
BIN
assets/dolphin/external/L1_Mods_128x64/frame_24.png
vendored
Normal file
|
After Width: | Height: | Size: 4.2 KiB |
BIN
assets/dolphin/external/L1_Mods_128x64/frame_25.png
vendored
Normal file
|
After Width: | Height: | Size: 4.1 KiB |
BIN
assets/dolphin/external/L1_Mods_128x64/frame_26.png
vendored
Normal file
|
After Width: | Height: | Size: 4.2 KiB |
BIN
assets/dolphin/external/L1_Mods_128x64/frame_27.png
vendored
Normal file
|
After Width: | Height: | Size: 4.3 KiB |
BIN
assets/dolphin/external/L1_Mods_128x64/frame_28.png
vendored
Normal file
|
After Width: | Height: | Size: 4.3 KiB |
BIN
assets/dolphin/external/L1_Mods_128x64/frame_29.png
vendored
Normal file
|
After Width: | Height: | Size: 4.3 KiB |
BIN
assets/dolphin/external/L1_Mods_128x64/frame_3.png
vendored
Normal file
|
After Width: | Height: | Size: 4.2 KiB |
BIN
assets/dolphin/external/L1_Mods_128x64/frame_30.png
vendored
Normal file
|
After Width: | Height: | Size: 4.3 KiB |
BIN
assets/dolphin/external/L1_Mods_128x64/frame_31.png
vendored
Normal file
|
After Width: | Height: | Size: 4.3 KiB |