This commit is contained in:
Willy-JL
2023-07-13 20:08:56 +02:00
361 changed files with 14305 additions and 2100 deletions

View File

@@ -13,7 +13,7 @@
"label": "[Debug] Build",
"group": "build",
"type": "shell",
"command": "./fbt FIRMWARE_APP_SET=debug_pack"
"command": "./fbt"
},
{
"label": "[Release] Flash (ST-Link)",
@@ -25,7 +25,7 @@
"label": "[Debug] Flash (ST-Link)",
"group": "build",
"type": "shell",
"command": "./fbt FIRMWARE_APP_SET=debug_pack FORCE=1 flash"
"command": "./fbt FORCE=1 flash"
},
{
"label": "[Release] Flash (blackmagic)",
@@ -37,7 +37,7 @@
"label": "[Debug] Flash (blackmagic)",
"group": "build",
"type": "shell",
"command": "./fbt FIRMWARE_APP_SET=debug_pack FORCE=1 flash_blackmagic"
"command": "./fbt FORCE=1 flash_blackmagic"
},
{
"label": "[Release] Flash (JLink)",
@@ -49,7 +49,7 @@
"label": "[Debug] Flash (JLink)",
"group": "build",
"type": "shell",
"command": "./fbt FIRMWARE_APP_SET=debug_pack FORCE=1 jflash"
"command": "./fbt FORCE=1 jflash"
},
{
"label": "[Release] Build update bundle",
@@ -61,7 +61,7 @@
"label": "[Debug] Build update bundle",
"group": "build",
"type": "shell",
"command": "./fbt FIRMWARE_APP_SET=debug_pack updater_package"
"command": "./fbt updater_package"
},
{
"label": "[Release] Build updater",
@@ -73,13 +73,13 @@
"label": "[Debug] Build updater",
"group": "build",
"type": "shell",
"command": "./fbt FIRMWARE_APP_SET=debug_pack updater_all"
"command": "./fbt updater_all"
},
{
"label": "[Debug] Flash (USB, w/o resources)",
"group": "build",
"type": "shell",
"command": "./fbt FIRMWARE_APP_SET=debug_pack FORCE=1 flash_usb"
"command": "./fbt FORCE=1 flash_usb"
},
{
"label": "[Release] Flash (USB, w/o resources)",
@@ -97,7 +97,7 @@
"label": "[Debug] Flash (USB, with resources)",
"group": "build",
"type": "shell",
"command": "./fbt FIRMWARE_APP_SET=debug_pack FORCE=1 flash_usb_full"
"command": "./fbt FORCE=1 flash_usb_full"
},
{
"label": "[Release] Flash (USB, with resources)",

View File

@@ -0,0 +1,14 @@
App(
appid="subghz_test",
name="Sub-Ghz test",
apptype=FlipperAppType.DEBUG,
targets=["f7"],
entry_point="subghz_test_app",
requires=["gui"],
stack_size=4 * 1024,
order=50,
fap_icon="subghz_test_10px.png",
fap_category="Debug",
fap_icon_assets="images",
fap_version="0.1",
)

View File

@@ -0,0 +1,7 @@
#pragma once
typedef enum {
//SubGhzTestCustomEvent
SubGhzTestCustomEventStartId = 100,
SubGhzTestCustomEventSceneShowOnlyRX,
} SubGhzTestCustomEvent;

View File

@@ -1,4 +1,4 @@
#include "subghz_testing.h"
#include "subghz_test_frequency.h"
const uint32_t subghz_frequencies_testing[] = {
/* 300 - 348 */

View File

@@ -1,5 +1,5 @@
#pragma once
#include "../subghz_i.h"
#include "../subghz_test_app_i.h"
extern const uint32_t subghz_frequencies_testing[];
extern const uint32_t subghz_frequencies_count_testing;

View File

@@ -0,0 +1,18 @@
#pragma once
#include <furi.h>
#include <furi_hal.h>
#define SUBGHZ_TEST_VERSION_APP "0.1"
#define SUBGHZ_TEST_DEVELOPED "SkorP"
#define SUBGHZ_TEST_GITHUB "https://github.com/flipperdevices/flipperzero-firmware"
typedef enum {
SubGhzTestViewVariableItemList,
SubGhzTestViewSubmenu,
SubGhzTestViewStatic,
SubGhzTestViewCarrier,
SubGhzTestViewPacket,
SubGhzTestViewWidget,
SubGhzTestViewPopup,
} SubGhzTestView;

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@@ -0,0 +1,244 @@
#include "math.h"
uint64_t subghz_protocol_blocks_reverse_key(uint64_t key, uint8_t bit_count) {
uint64_t reverse_key = 0;
for(uint8_t i = 0; i < bit_count; i++) {
reverse_key = reverse_key << 1 | bit_read(key, i);
}
return reverse_key;
}
uint8_t subghz_protocol_blocks_get_parity(uint64_t key, uint8_t bit_count) {
uint8_t parity = 0;
for(uint8_t i = 0; i < bit_count; i++) {
parity += bit_read(key, i);
}
return parity & 0x01;
}
uint8_t subghz_protocol_blocks_crc4(
uint8_t const message[],
size_t size,
uint8_t polynomial,
uint8_t init) {
uint8_t remainder = init << 4; // LSBs are unused
uint8_t poly = polynomial << 4;
uint8_t bit;
while(size--) {
remainder ^= *message++;
for(bit = 0; bit < 8; bit++) {
if(remainder & 0x80) {
remainder = (remainder << 1) ^ poly;
} else {
remainder = (remainder << 1);
}
}
}
return remainder >> 4 & 0x0f; // discard the LSBs
}
uint8_t subghz_protocol_blocks_crc7(
uint8_t const message[],
size_t size,
uint8_t polynomial,
uint8_t init) {
uint8_t remainder = init << 1; // LSB is unused
uint8_t poly = polynomial << 1;
for(size_t byte = 0; byte < size; ++byte) {
remainder ^= message[byte];
for(uint8_t bit = 0; bit < 8; ++bit) {
if(remainder & 0x80) {
remainder = (remainder << 1) ^ poly;
} else {
remainder = (remainder << 1);
}
}
}
return remainder >> 1 & 0x7f; // discard the LSB
}
uint8_t subghz_protocol_blocks_crc8(
uint8_t const message[],
size_t size,
uint8_t polynomial,
uint8_t init) {
uint8_t remainder = init;
for(size_t byte = 0; byte < size; ++byte) {
remainder ^= message[byte];
for(uint8_t bit = 0; bit < 8; ++bit) {
if(remainder & 0x80) {
remainder = (remainder << 1) ^ polynomial;
} else {
remainder = (remainder << 1);
}
}
}
return remainder;
}
uint8_t subghz_protocol_blocks_crc8le(
uint8_t const message[],
size_t size,
uint8_t polynomial,
uint8_t init) {
uint8_t remainder = subghz_protocol_blocks_reverse_key(init, 8);
polynomial = subghz_protocol_blocks_reverse_key(polynomial, 8);
for(size_t byte = 0; byte < size; ++byte) {
remainder ^= message[byte];
for(uint8_t bit = 0; bit < 8; ++bit) {
if(remainder & 1) {
remainder = (remainder >> 1) ^ polynomial;
} else {
remainder = (remainder >> 1);
}
}
}
return remainder;
}
uint16_t subghz_protocol_blocks_crc16lsb(
uint8_t const message[],
size_t size,
uint16_t polynomial,
uint16_t init) {
uint16_t remainder = init;
for(size_t byte = 0; byte < size; ++byte) {
remainder ^= message[byte];
for(uint8_t bit = 0; bit < 8; ++bit) {
if(remainder & 1) {
remainder = (remainder >> 1) ^ polynomial;
} else {
remainder = (remainder >> 1);
}
}
}
return remainder;
}
uint16_t subghz_protocol_blocks_crc16(
uint8_t const message[],
size_t size,
uint16_t polynomial,
uint16_t init) {
uint16_t remainder = init;
for(size_t byte = 0; byte < size; ++byte) {
remainder ^= message[byte] << 8;
for(uint8_t bit = 0; bit < 8; ++bit) {
if(remainder & 0x8000) {
remainder = (remainder << 1) ^ polynomial;
} else {
remainder = (remainder << 1);
}
}
}
return remainder;
}
uint8_t subghz_protocol_blocks_lfsr_digest8(
uint8_t const message[],
size_t size,
uint8_t gen,
uint8_t key) {
uint8_t sum = 0;
for(size_t byte = 0; byte < size; ++byte) {
uint8_t data = message[byte];
for(int i = 7; i >= 0; --i) {
// XOR key into sum if data bit is set
if((data >> i) & 1) sum ^= key;
// roll the key right (actually the LSB is dropped here)
// and apply the gen (needs to include the dropped LSB as MSB)
if(key & 1)
key = (key >> 1) ^ gen;
else
key = (key >> 1);
}
}
return sum;
}
uint8_t subghz_protocol_blocks_lfsr_digest8_reflect(
uint8_t const message[],
size_t size,
uint8_t gen,
uint8_t key) {
uint8_t sum = 0;
// Process message from last byte to first byte (reflected)
for(int byte = size - 1; byte >= 0; --byte) {
uint8_t data = message[byte];
// Process individual bits of each byte (reflected)
for(uint8_t i = 0; i < 8; ++i) {
// XOR key into sum if data bit is set
if((data >> i) & 1) {
sum ^= key;
}
// roll the key left (actually the LSB is dropped here)
// and apply the gen (needs to include the dropped lsb as MSB)
if(key & 0x80)
key = (key << 1) ^ gen;
else
key = (key << 1);
}
}
return sum;
}
uint16_t subghz_protocol_blocks_lfsr_digest16(
uint8_t const message[],
size_t size,
uint16_t gen,
uint16_t key) {
uint16_t sum = 0;
for(size_t byte = 0; byte < size; ++byte) {
uint8_t data = message[byte];
for(int8_t i = 7; i >= 0; --i) {
// if data bit is set then xor with key
if((data >> i) & 1) sum ^= key;
// roll the key right (actually the LSB is dropped here)
// and apply the gen (needs to include the dropped LSB as MSB)
if(key & 1)
key = (key >> 1) ^ gen;
else
key = (key >> 1);
}
}
return sum;
}
uint8_t subghz_protocol_blocks_add_bytes(uint8_t const message[], size_t size) {
uint32_t result = 0;
for(size_t i = 0; i < size; ++i) {
result += message[i];
}
return (uint8_t)result;
}
uint8_t subghz_protocol_blocks_parity8(uint8_t byte) {
byte ^= byte >> 4;
byte &= 0xf;
return (0x6996 >> byte) & 1;
}
uint8_t subghz_protocol_blocks_parity_bytes(uint8_t const message[], size_t size) {
uint8_t result = 0;
for(size_t i = 0; i < size; ++i) {
result ^= subghz_protocol_blocks_parity8(message[i]);
}
return result;
}
uint8_t subghz_protocol_blocks_xor_bytes(uint8_t const message[], size_t size) {
uint8_t result = 0;
for(size_t i = 0; i < size; ++i) {
result ^= message[i];
}
return result;
}

View File

@@ -0,0 +1,222 @@
#pragma once
#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>
#define bit_read(value, bit) (((value) >> (bit)) & 0x01)
#define bit_set(value, bit) \
({ \
__typeof__(value) _one = (1); \
(value) |= (_one << (bit)); \
})
#define bit_clear(value, bit) \
({ \
__typeof__(value) _one = (1); \
(value) &= ~(_one << (bit)); \
})
#define bit_write(value, bit, bitvalue) (bitvalue ? bit_set(value, bit) : bit_clear(value, bit))
#define DURATION_DIFF(x, y) (((x) < (y)) ? ((y) - (x)) : ((x) - (y)))
#ifdef __cplusplus
extern "C" {
#endif
/** Flip the data bitwise
*
* @param key In data
* @param bit_count number of data bits
*
* @return Reverse data
*/
uint64_t subghz_protocol_blocks_reverse_key(uint64_t key, uint8_t bit_count);
/** Get parity the data bitwise
*
* @param key In data
* @param bit_count number of data bits
*
* @return parity
*/
uint8_t subghz_protocol_blocks_get_parity(uint64_t key, uint8_t bit_count);
/** CRC-4
*
* @param message array of bytes to check
* @param size number of bytes in message
* @param polynomial CRC polynomial
* @param init starting crc value
*
* @return CRC value
*/
uint8_t subghz_protocol_blocks_crc4(
uint8_t const message[],
size_t size,
uint8_t polynomial,
uint8_t init);
/** CRC-7
*
* @param message array of bytes to check
* @param size number of bytes in message
* @param polynomial CRC polynomial
* @param init starting crc value
*
* @return CRC value
*/
uint8_t subghz_protocol_blocks_crc7(
uint8_t const message[],
size_t size,
uint8_t polynomial,
uint8_t init);
/** Generic Cyclic Redundancy Check CRC-8. Example polynomial: 0x31 = x8 + x5 +
* x4 + 1 (x8 is implicit) Example polynomial: 0x80 = x8 + x7 (a normal
* bit-by-bit parity XOR)
*
* @param message array of bytes to check
* @param size number of bytes in message
* @param polynomial byte is from x^7 to x^0 (x^8 is implicitly one)
* @param init starting crc value
*
* @return CRC value
*/
uint8_t subghz_protocol_blocks_crc8(
uint8_t const message[],
size_t size,
uint8_t polynomial,
uint8_t init);
/** "Little-endian" Cyclic Redundancy Check CRC-8 LE Input and output are
* reflected, i.e. least significant bit is shifted in first
*
* @param message array of bytes to check
* @param size number of bytes in message
* @param polynomial CRC polynomial
* @param init starting crc value
*
* @return CRC value
*/
uint8_t subghz_protocol_blocks_crc8le(
uint8_t const message[],
size_t size,
uint8_t polynomial,
uint8_t init);
/** CRC-16 LSB. Input and output are reflected, i.e. least significant bit is
* shifted in first. Note that poly and init already need to be reflected
*
* @param message array of bytes to check
* @param size number of bytes in message
* @param polynomial CRC polynomial
* @param init starting crc value
*
* @return CRC value
*/
uint16_t subghz_protocol_blocks_crc16lsb(
uint8_t const message[],
size_t size,
uint16_t polynomial,
uint16_t init);
/** CRC-16
*
* @param message array of bytes to check
* @param size number of bytes in message
* @param polynomial CRC polynomial
* @param init starting crc value
*
* @return CRC value
*/
uint16_t subghz_protocol_blocks_crc16(
uint8_t const message[],
size_t size,
uint16_t polynomial,
uint16_t init);
/** Digest-8 by "LFSR-based Toeplitz hash"
*
* @param message bytes of message data
* @param size number of bytes to digest
* @param gen key stream generator, needs to includes the MSB if the
* LFSR is rolling
* @param key initial key
*
* @return digest value
*/
uint8_t subghz_protocol_blocks_lfsr_digest8(
uint8_t const message[],
size_t size,
uint8_t gen,
uint8_t key);
/** Digest-8 by "LFSR-based Toeplitz hash", byte reflect, bit reflect
*
* @param message bytes of message data
* @param size number of bytes to digest
* @param gen key stream generator, needs to includes the MSB if the
* LFSR is rolling
* @param key initial key
*
* @return digest value
*/
uint8_t subghz_protocol_blocks_lfsr_digest8_reflect(
uint8_t const message[],
size_t size,
uint8_t gen,
uint8_t key);
/** Digest-16 by "LFSR-based Toeplitz hash"
*
* @param message bytes of message data
* @param size number of bytes to digest
* @param gen key stream generator, needs to includes the MSB if the
* LFSR is rolling
* @param key initial key
*
* @return digest value
*/
uint16_t subghz_protocol_blocks_lfsr_digest16(
uint8_t const message[],
size_t size,
uint16_t gen,
uint16_t key);
/** Compute Addition of a number of bytes
*
* @param message bytes of message data
* @param size number of bytes to sum
*
* @return summation value
*/
uint8_t subghz_protocol_blocks_add_bytes(uint8_t const message[], size_t size);
/** Compute bit parity of a single byte (8 bits)
*
* @param byte single byte to check
*
* @return 1 odd parity, 0 even parity
*/
uint8_t subghz_protocol_blocks_parity8(uint8_t byte);
/** Compute bit parity of a number of bytes
*
* @param message bytes of message data
* @param size number of bytes to sum
*
* @return 1 odd parity, 0 even parity
*/
uint8_t subghz_protocol_blocks_parity_bytes(uint8_t const message[], size_t size);
/** Compute XOR (byte-wide parity) of a number of bytes
*
* @param message bytes of message data
* @param size number of bytes to sum
*
* @return summation value, per bit-position 1 odd parity, 0 even parity
*/
uint8_t subghz_protocol_blocks_xor_bytes(uint8_t const message[], size_t size);
#ifdef __cplusplus
}
#endif

View File

@@ -1,7 +1,7 @@
#include "princeton_for_testing.h"
#include <furi_hal.h>
#include "../blocks/math.h"
#include "math.h"
/*
* Help

View File

@@ -1,6 +1,8 @@
#pragma once
#include "base.h"
//#include "base.h"
#include <furi.h>
#include <lib/toolbox/level_duration.h>
/** SubGhzDecoderPrinceton anonymous type */
typedef struct SubGhzDecoderPrinceton SubGhzDecoderPrinceton;

View File

@@ -0,0 +1,30 @@
#include "../subghz_test_app_i.h"
// Generate scene on_enter handlers array
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_enter,
void (*const subghz_test_scene_on_enter_handlers[])(void*) = {
#include "subghz_test_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 subghz_test_scene_on_event_handlers[])(void* context, SceneManagerEvent event) = {
#include "subghz_test_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 subghz_test_scene_on_exit_handlers[])(void* context) = {
#include "subghz_test_scene_config.h"
};
#undef ADD_SCENE
// Initialize scene handlers configuration structure
const SceneManagerHandlers subghz_test_scene_handlers = {
.on_enter_handlers = subghz_test_scene_on_enter_handlers,
.on_event_handlers = subghz_test_scene_on_event_handlers,
.on_exit_handlers = subghz_test_scene_on_exit_handlers,
.scene_num = SubGhzTestSceneNum,
};

View File

@@ -0,0 +1,29 @@
#pragma once
#include <gui/scene_manager.h>
// Generate scene id and total number
#define ADD_SCENE(prefix, name, id) SubGhzTestScene##id,
typedef enum {
#include "subghz_test_scene_config.h"
SubGhzTestSceneNum,
} SubGhzTestScene;
#undef ADD_SCENE
extern const SceneManagerHandlers subghz_test_scene_handlers;
// Generate scene on_enter handlers declaration
#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_enter(void*);
#include "subghz_test_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 "subghz_test_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 "subghz_test_scene_config.h"
#undef ADD_SCENE

View File

@@ -0,0 +1,66 @@
#include "../subghz_test_app_i.h"
void subghz_test_scene_about_widget_callback(GuiButtonType result, InputType type, void* context) {
SubGhzTestApp* app = context;
if(type == InputTypeShort) {
view_dispatcher_send_custom_event(app->view_dispatcher, result);
}
}
void subghz_test_scene_about_on_enter(void* context) {
SubGhzTestApp* app = context;
FuriString* temp_str;
temp_str = furi_string_alloc();
furi_string_printf(temp_str, "\e#%s\n", "Information");
furi_string_cat_printf(temp_str, "Version: %s\n", SUBGHZ_TEST_VERSION_APP);
furi_string_cat_printf(temp_str, "Developed by: %s\n", SUBGHZ_TEST_DEVELOPED);
furi_string_cat_printf(temp_str, "Github: %s\n\n", SUBGHZ_TEST_GITHUB);
furi_string_cat_printf(temp_str, "\e#%s\n", "Description");
furi_string_cat_printf(
temp_str,
"This application is designed\nto test the functionality of the\nbuilt-in CC1101 module.\n\n");
widget_add_text_box_element(
app->widget,
0,
0,
128,
14,
AlignCenter,
AlignBottom,
"\e#\e! \e!\n",
false);
widget_add_text_box_element(
app->widget,
0,
2,
128,
14,
AlignCenter,
AlignBottom,
"\e#\e! Sub-Ghz Test \e!\n",
false);
widget_add_text_scroll_element(app->widget, 0, 16, 128, 50, furi_string_get_cstr(temp_str));
furi_string_free(temp_str);
view_dispatcher_switch_to_view(app->view_dispatcher, SubGhzTestViewWidget);
}
bool subghz_test_scene_about_on_event(void* context, SceneManagerEvent event) {
SubGhzTestApp* app = context;
bool consumed = false;
UNUSED(app);
UNUSED(event);
return consumed;
}
void subghz_test_scene_about_on_exit(void* context) {
SubGhzTestApp* app = context;
// Clear views
widget_reset(app->widget);
}

View File

@@ -0,0 +1,29 @@
#include "../subghz_test_app_i.h"
void subghz_test_scene_carrier_callback(SubGhzTestCarrierEvent event, void* context) {
furi_assert(context);
SubGhzTestApp* app = context;
view_dispatcher_send_custom_event(app->view_dispatcher, event);
}
void subghz_test_scene_carrier_on_enter(void* context) {
SubGhzTestApp* app = context;
subghz_test_carrier_set_callback(
app->subghz_test_carrier, subghz_test_scene_carrier_callback, app);
view_dispatcher_switch_to_view(app->view_dispatcher, SubGhzTestViewCarrier);
}
bool subghz_test_scene_carrier_on_event(void* context, SceneManagerEvent event) {
SubGhzTestApp* app = context;
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SubGhzTestCarrierEventOnlyRx) {
scene_manager_next_scene(app->scene_manager, SubGhzTestSceneShowOnlyRx);
return true;
}
}
return false;
}
void subghz_test_scene_carrier_on_exit(void* context) {
UNUSED(context);
}

View File

@@ -0,0 +1,6 @@
ADD_SCENE(subghz_test, start, Start)
ADD_SCENE(subghz_test, about, About)
ADD_SCENE(subghz_test, carrier, Carrier)
ADD_SCENE(subghz_test, packet, Packet)
ADD_SCENE(subghz_test, static, Static)
ADD_SCENE(subghz_test, show_only_rx, ShowOnlyRx)

View File

@@ -0,0 +1,29 @@
#include "../subghz_test_app_i.h"
void subghz_test_scene_packet_callback(SubGhzTestPacketEvent event, void* context) {
furi_assert(context);
SubGhzTestApp* app = context;
view_dispatcher_send_custom_event(app->view_dispatcher, event);
}
void subghz_test_scene_packet_on_enter(void* context) {
SubGhzTestApp* app = context;
subghz_test_packet_set_callback(
app->subghz_test_packet, subghz_test_scene_packet_callback, app);
view_dispatcher_switch_to_view(app->view_dispatcher, SubGhzTestViewPacket);
}
bool subghz_test_scene_packet_on_event(void* context, SceneManagerEvent event) {
SubGhzTestApp* app = context;
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SubGhzTestPacketEventOnlyRx) {
scene_manager_next_scene(app->scene_manager, SubGhzTestSceneShowOnlyRx);
return true;
}
}
return false;
}
void subghz_test_scene_packet_on_exit(void* context) {
UNUSED(context);
}

View File

@@ -0,0 +1,49 @@
#include "../subghz_test_app_i.h"
#include <subghz_test_icons.h>
void subghz_test_scene_show_only_rx_popup_callback(void* context) {
SubGhzTestApp* app = context;
view_dispatcher_send_custom_event(app->view_dispatcher, SubGhzTestCustomEventSceneShowOnlyRX);
}
void subghz_test_scene_show_only_rx_on_enter(void* context) {
SubGhzTestApp* app = context;
// Setup view
Popup* popup = app->popup;
const char* header_text = "Transmission is blocked";
const char* message_text = "Transmission on\nthis frequency is\nrestricted in\nyour region";
if(!furi_hal_region_is_provisioned()) {
header_text = "Firmware update needed";
message_text = "Please update\nfirmware before\nusing this feature\nflipp.dev/upd";
}
popup_set_header(popup, header_text, 63, 3, AlignCenter, AlignTop);
popup_set_text(popup, message_text, 0, 17, AlignLeft, AlignTop);
popup_set_icon(popup, 72, 17, &I_DolphinCommon_56x48);
popup_set_timeout(popup, 1500);
popup_set_context(popup, app);
popup_set_callback(popup, subghz_test_scene_show_only_rx_popup_callback);
popup_enable_timeout(popup);
view_dispatcher_switch_to_view(app->view_dispatcher, SubGhzTestViewPopup);
}
bool subghz_test_scene_show_only_rx_on_event(void* context, SceneManagerEvent event) {
SubGhzTestApp* app = context;
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SubGhzTestCustomEventSceneShowOnlyRX) {
scene_manager_previous_scene(app->scene_manager);
return true;
}
}
return false;
}
void subghz_test_scene_show_only_rx_on_exit(void* context) {
SubGhzTestApp* app = context;
Popup* popup = app->popup;
popup_reset(popup);
}

View File

@@ -0,0 +1,77 @@
#include "../subghz_test_app_i.h"
typedef enum {
SubmenuIndexSubGhzTestCarrier,
SubmenuIndexSubGhzTestPacket,
SubmenuIndexSubGhzTestStatic,
SubmenuIndexSubGhzTestAbout,
} SubmenuIndex;
void subghz_test_scene_start_submenu_callback(void* context, uint32_t index) {
SubGhzTestApp* app = context;
view_dispatcher_send_custom_event(app->view_dispatcher, index);
}
void subghz_test_scene_start_on_enter(void* context) {
SubGhzTestApp* app = context;
Submenu* submenu = app->submenu;
submenu_add_item(
submenu,
"Carrier",
SubmenuIndexSubGhzTestCarrier,
subghz_test_scene_start_submenu_callback,
app);
submenu_add_item(
submenu,
"Packet",
SubmenuIndexSubGhzTestPacket,
subghz_test_scene_start_submenu_callback,
app);
submenu_add_item(
submenu,
"Static",
SubmenuIndexSubGhzTestStatic,
subghz_test_scene_start_submenu_callback,
app);
submenu_add_item(
submenu,
"About",
SubmenuIndexSubGhzTestAbout,
subghz_test_scene_start_submenu_callback,
app);
submenu_set_selected_item(
submenu, scene_manager_get_scene_state(app->scene_manager, SubGhzTestSceneStart));
view_dispatcher_switch_to_view(app->view_dispatcher, SubGhzTestViewSubmenu);
}
bool subghz_test_scene_start_on_event(void* context, SceneManagerEvent event) {
SubGhzTestApp* app = context;
bool consumed = false;
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SubmenuIndexSubGhzTestAbout) {
scene_manager_next_scene(app->scene_manager, SubGhzTestSceneAbout);
consumed = true;
} else if(event.event == SubmenuIndexSubGhzTestCarrier) {
scene_manager_next_scene(app->scene_manager, SubGhzTestSceneCarrier);
consumed = true;
} else if(event.event == SubmenuIndexSubGhzTestPacket) {
scene_manager_next_scene(app->scene_manager, SubGhzTestScenePacket);
consumed = true;
} else if(event.event == SubmenuIndexSubGhzTestStatic) {
scene_manager_next_scene(app->scene_manager, SubGhzTestSceneStatic);
consumed = true;
}
scene_manager_set_scene_state(app->scene_manager, SubGhzTestSceneStart, event.event);
}
return consumed;
}
void subghz_test_scene_start_on_exit(void* context) {
SubGhzTestApp* app = context;
submenu_reset(app->submenu);
}

View File

@@ -0,0 +1,29 @@
#include "../subghz_test_app_i.h"
void subghz_test_scene_static_callback(SubGhzTestStaticEvent event, void* context) {
furi_assert(context);
SubGhzTestApp* app = context;
view_dispatcher_send_custom_event(app->view_dispatcher, event);
}
void subghz_test_scene_static_on_enter(void* context) {
SubGhzTestApp* app = context;
subghz_test_static_set_callback(
app->subghz_test_static, subghz_test_scene_static_callback, app);
view_dispatcher_switch_to_view(app->view_dispatcher, SubGhzTestViewStatic);
}
bool subghz_test_scene_static_on_event(void* context, SceneManagerEvent event) {
SubGhzTestApp* app = context;
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SubGhzTestStaticEventOnlyRx) {
scene_manager_next_scene(app->scene_manager, SubGhzTestSceneShowOnlyRx);
return true;
}
}
return false;
}
void subghz_test_scene_static_on_exit(void* context) {
UNUSED(context);
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 181 B

View File

@@ -0,0 +1,139 @@
#include "subghz_test_app_i.h"
#include <furi.h>
#include <furi_hal.h>
static bool subghz_test_app_custom_event_callback(void* context, uint32_t event) {
furi_assert(context);
SubGhzTestApp* app = context;
return scene_manager_handle_custom_event(app->scene_manager, event);
}
static bool subghz_test_app_back_event_callback(void* context) {
furi_assert(context);
SubGhzTestApp* app = context;
return scene_manager_handle_back_event(app->scene_manager);
}
static void subghz_test_app_tick_event_callback(void* context) {
furi_assert(context);
SubGhzTestApp* app = context;
scene_manager_handle_tick_event(app->scene_manager);
}
SubGhzTestApp* subghz_test_app_alloc() {
SubGhzTestApp* app = malloc(sizeof(SubGhzTestApp));
// GUI
app->gui = furi_record_open(RECORD_GUI);
// View Dispatcher
app->view_dispatcher = view_dispatcher_alloc();
app->scene_manager = scene_manager_alloc(&subghz_test_scene_handlers, app);
view_dispatcher_enable_queue(app->view_dispatcher);
view_dispatcher_set_event_callback_context(app->view_dispatcher, app);
view_dispatcher_set_custom_event_callback(
app->view_dispatcher, subghz_test_app_custom_event_callback);
view_dispatcher_set_navigation_event_callback(
app->view_dispatcher, subghz_test_app_back_event_callback);
view_dispatcher_set_tick_event_callback(
app->view_dispatcher, subghz_test_app_tick_event_callback, 100);
view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
// Open Notification record
app->notifications = furi_record_open(RECORD_NOTIFICATION);
// SubMenu
app->submenu = submenu_alloc();
view_dispatcher_add_view(
app->view_dispatcher, SubGhzTestViewSubmenu, submenu_get_view(app->submenu));
// Widget
app->widget = widget_alloc();
view_dispatcher_add_view(
app->view_dispatcher, SubGhzTestViewWidget, widget_get_view(app->widget));
// Popup
app->popup = popup_alloc();
view_dispatcher_add_view(
app->view_dispatcher, SubGhzTestViewPopup, popup_get_view(app->popup));
// Carrier Test Module
app->subghz_test_carrier = subghz_test_carrier_alloc();
view_dispatcher_add_view(
app->view_dispatcher,
SubGhzTestViewCarrier,
subghz_test_carrier_get_view(app->subghz_test_carrier));
// Packet Test
app->subghz_test_packet = subghz_test_packet_alloc();
view_dispatcher_add_view(
app->view_dispatcher,
SubGhzTestViewPacket,
subghz_test_packet_get_view(app->subghz_test_packet));
// Static send
app->subghz_test_static = subghz_test_static_alloc();
view_dispatcher_add_view(
app->view_dispatcher,
SubGhzTestViewStatic,
subghz_test_static_get_view(app->subghz_test_static));
scene_manager_next_scene(app->scene_manager, SubGhzTestSceneStart);
return app;
}
void subghz_test_app_free(SubGhzTestApp* app) {
furi_assert(app);
// Submenu
view_dispatcher_remove_view(app->view_dispatcher, SubGhzTestViewSubmenu);
submenu_free(app->submenu);
// Widget
view_dispatcher_remove_view(app->view_dispatcher, SubGhzTestViewWidget);
widget_free(app->widget);
// Popup
view_dispatcher_remove_view(app->view_dispatcher, SubGhzTestViewPopup);
popup_free(app->popup);
// Carrier Test
view_dispatcher_remove_view(app->view_dispatcher, SubGhzTestViewCarrier);
subghz_test_carrier_free(app->subghz_test_carrier);
// Packet Test
view_dispatcher_remove_view(app->view_dispatcher, SubGhzTestViewPacket);
subghz_test_packet_free(app->subghz_test_packet);
// Static
view_dispatcher_remove_view(app->view_dispatcher, SubGhzTestViewStatic);
subghz_test_static_free(app->subghz_test_static);
// View dispatcher
view_dispatcher_free(app->view_dispatcher);
scene_manager_free(app->scene_manager);
// Notifications
furi_record_close(RECORD_NOTIFICATION);
app->notifications = NULL;
// Close records
furi_record_close(RECORD_GUI);
free(app);
}
int32_t subghz_test_app(void* p) {
UNUSED(p);
SubGhzTestApp* subghz_test_app = subghz_test_app_alloc();
view_dispatcher_run(subghz_test_app->view_dispatcher);
subghz_test_app_free(subghz_test_app);
return 0;
}

View File

@@ -0,0 +1,5 @@
#include "subghz_test_app_i.h"
#include <furi.h>
#define TAG "SubGhzTest"

View File

@@ -0,0 +1,32 @@
#pragma once
#include "helpers/subghz_test_types.h"
#include "helpers/subghz_test_event.h"
#include "scenes/subghz_test_scene.h"
#include <gui/gui.h>
#include <gui/view_dispatcher.h>
#include <gui/scene_manager.h>
#include <gui/modules/submenu.h>
#include <gui/modules/widget.h>
#include <gui/modules/popup.h>
#include <notification/notification_messages.h>
#include "views/subghz_test_static.h"
#include "views/subghz_test_carrier.h"
#include "views/subghz_test_packet.h"
typedef struct SubGhzTestApp SubGhzTestApp;
struct SubGhzTestApp {
Gui* gui;
ViewDispatcher* view_dispatcher;
SceneManager* scene_manager;
NotificationApp* notifications;
Submenu* submenu;
Widget* widget;
Popup* popup;
SubGhzTestStatic* subghz_test_static;
SubGhzTestCarrier* subghz_test_carrier;
SubGhzTestPacket* subghz_test_packet;
};

View File

@@ -1,6 +1,7 @@
#include "subghz_test_carrier.h"
#include "../subghz_i.h"
#include "../helpers/subghz_testing.h"
#include "../subghz_test_app_i.h"
#include "../helpers/subghz_test_frequency.h"
#include <lib/subghz/devices/cc1101_configs.h>
#include <math.h>
#include <furi.h>
@@ -11,6 +12,7 @@ struct SubGhzTestCarrier {
View* view;
FuriTimer* timer;
SubGhzTestCarrierCallback callback;
// const SubGhzDevice* radio_device;
void* context;
};
@@ -83,6 +85,7 @@ void subghz_test_carrier_draw(Canvas* canvas, SubGhzTestCarrierModel* model) {
bool subghz_test_carrier_input(InputEvent* event, void* context) {
furi_assert(context);
SubGhzTestCarrier* subghz_test_carrier = context;
// const SubGhzDevice* radio_device = subghz_test_carrier->radio_device;
if(event->key == InputKeyBack || event->type != InputTypeShort) {
return false;
@@ -93,6 +96,7 @@ bool subghz_test_carrier_input(InputEvent* event, void* context) {
SubGhzTestCarrierModel * model,
{
furi_hal_subghz_idle();
// subghz_devices_idle(radio_device);
if(event->key == InputKeyLeft) {
if(model->frequency > 0) model->frequency--;
@@ -113,24 +117,36 @@ bool subghz_test_carrier_input(InputEvent* event, void* context) {
model->real_frequency =
furi_hal_subghz_set_frequency(subghz_frequencies_testing[model->frequency]);
furi_hal_subghz_set_path(model->path);
// model->real_frequency = subghz_devices_set_frequency(
// radio_device, subghz_frequencies_testing[model->frequency]);
if(model->status == SubGhzTestCarrierModelStatusRx) {
furi_hal_gpio_init(
furi_hal_subghz.cc1101_g0_pin, GpioModeInput, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
furi_hal_subghz_rx();
// furi_hal_gpio_init(
// subghz_devices_get_data_gpio(radio_device),
// GpioModeInput,
// GpioPullNo,
// GpioSpeedLow);
// subghz_devices_set_rx(radio_device);
} else {
furi_hal_gpio_init(
furi_hal_subghz.cc1101_g0_pin,
GpioModeOutputPushPull,
GpioPullNo,
GpioSpeedLow);
furi_hal_gpio_write(furi_hal_subghz.cc1101_g0_pin, true);
&gpio_cc1101_g0, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_write(&gpio_cc1101_g0, true);
if(!furi_hal_subghz_tx()) {
furi_hal_gpio_init(
furi_hal_subghz.cc1101_g0_pin, GpioModeInput, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
subghz_test_carrier->callback(
SubGhzTestCarrierEventOnlyRx, subghz_test_carrier->context);
}
// if(!subghz_devices_set_tx(radio_device)) {
// furi_hal_gpio_init(
// subghz_devices_get_data_gpio(radio_device),
// GpioModeInput,
// GpioPullNo,
// GpioSpeedLow);
// subghz_test_carrier->callback(
// SubGhzTestCarrierEventOnlyRx, subghz_test_carrier->context);
// }
}
},
true);
@@ -141,11 +157,19 @@ bool subghz_test_carrier_input(InputEvent* event, void* context) {
void subghz_test_carrier_enter(void* context) {
furi_assert(context);
SubGhzTestCarrier* subghz_test_carrier = context;
// furi_assert(subghz_test_carrier->radio_device);
// const SubGhzDevice* radio_device = subghz_test_carrier->radio_device;
furi_hal_subghz_reset();
furi_hal_subghz_load_preset(FuriHalSubGhzPresetOok650Async);
furi_hal_subghz_load_custom_preset(subghz_device_cc1101_preset_ook_650khz_async_regs);
furi_hal_gpio_init(furi_hal_subghz.cc1101_g0_pin, GpioModeInput, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
// subghz_devices_reset(radio_device);
// subghz_devices_load_preset(radio_device, FuriHalSubGhzPresetOok650Async, NULL);
// furi_hal_gpio_init(
// subghz_devices_get_data_gpio(radio_device), GpioModeInput, GpioPullNo, GpioSpeedLow);
with_view_model(
subghz_test_carrier->view,
@@ -154,6 +178,8 @@ void subghz_test_carrier_enter(void* context) {
model->frequency = subghz_frequencies_433_92_testing; // 433
model->real_frequency =
furi_hal_subghz_set_frequency(subghz_frequencies_testing[model->frequency]);
// model->real_frequency = subghz_devices_set_frequency(
// radio_device, subghz_frequencies_testing[model->frequency]);
model->path = FuriHalSubGhzPathIsolate; // isolate
model->rssi = 0.0f;
model->status = SubGhzTestCarrierModelStatusRx;
@@ -161,6 +187,7 @@ void subghz_test_carrier_enter(void* context) {
true);
furi_hal_subghz_rx();
// subghz_devices_set_rx(radio_device);
furi_timer_start(subghz_test_carrier->timer, furi_kernel_get_tick_frequency() / 4);
}
@@ -173,6 +200,7 @@ void subghz_test_carrier_exit(void* context) {
// Reinitialize IC to default state
furi_hal_subghz_sleep();
// subghz_devices_sleep(subghz_test_carrier->radio_device);
}
void subghz_test_carrier_rssi_timer_callback(void* context) {
@@ -185,6 +213,7 @@ void subghz_test_carrier_rssi_timer_callback(void* context) {
{
if(model->status == SubGhzTestCarrierModelStatusRx) {
model->rssi = furi_hal_subghz_get_rssi();
// model->rssi = subghz_devices_get_rssi(subghz_test_carrier->radio_device);
}
},
false);
@@ -220,3 +249,10 @@ View* subghz_test_carrier_get_view(SubGhzTestCarrier* subghz_test_carrier) {
furi_assert(subghz_test_carrier);
return subghz_test_carrier->view;
}
// void subghz_test_carrier_set_radio(
// SubGhzTestCarrier* subghz_test_carrier,
// const SubGhzDevice* radio_device) {
// furi_assert(subghz_test_carrier);
// subghz_test_carrier->radio_device = radio_device;
// }

View File

@@ -1,6 +1,7 @@
#pragma once
#include <gui/view.h>
// #include <lib/subghz/devices/devices.h>
typedef enum {
SubGhzTestCarrierEventOnlyRx,
@@ -20,3 +21,7 @@ SubGhzTestCarrier* subghz_test_carrier_alloc();
void subghz_test_carrier_free(SubGhzTestCarrier* subghz_test_carrier);
View* subghz_test_carrier_get_view(SubGhzTestCarrier* subghz_test_carrier);
// void subghz_test_carrier_set_radio(
// SubGhzTestCarrier* subghz_test_carrier,
// const SubGhzDevice* radio_device);

View File

@@ -1,13 +1,14 @@
#include "subghz_test_packet.h"
#include "../subghz_i.h"
#include "../helpers/subghz_testing.h"
#include "../subghz_test_app_i.h"
#include "../helpers/subghz_test_frequency.h"
#include <lib/subghz/devices/cc1101_configs.h>
#include <math.h>
#include <furi.h>
#include <furi_hal.h>
#include <input/input.h>
#include <toolbox/level_duration.h>
#include <lib/subghz/protocols/princeton_for_testing.h>
#include "../protocol/princeton_for_testing.h"
#define SUBGHZ_TEST_PACKET_COUNT 500
@@ -194,7 +195,7 @@ void subghz_test_packet_enter(void* context) {
SubGhzTestPacket* instance = context;
furi_hal_subghz_reset();
furi_hal_subghz_load_preset(FuriHalSubGhzPresetOok650Async);
furi_hal_subghz_load_custom_preset(subghz_device_cc1101_preset_ook_650khz_async_regs);
with_view_model(
instance->view,

View File

@@ -1,13 +1,14 @@
#include "subghz_test_static.h"
#include "../subghz_i.h"
#include "../helpers/subghz_testing.h"
#include "../subghz_test_app_i.h"
#include "../helpers/subghz_test_frequency.h"
#include <lib/subghz/devices/cc1101_configs.h>
#include <math.h>
#include <furi.h>
#include <furi_hal.h>
#include <input/input.h>
#include <notification/notification_messages.h>
#include <lib/subghz/protocols/princeton_for_testing.h>
#include "../protocol/princeton_for_testing.h"
#define TAG "SubGhzTestStatic"
@@ -141,11 +142,10 @@ void subghz_test_static_enter(void* context) {
SubGhzTestStatic* instance = context;
furi_hal_subghz_reset();
furi_hal_subghz_load_preset(FuriHalSubGhzPresetOok650Async);
furi_hal_subghz_load_custom_preset(subghz_device_cc1101_preset_ook_650khz_async_regs);
furi_hal_gpio_init(
furi_hal_subghz.cc1101_g0_pin, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_write(furi_hal_subghz.cc1101_g0_pin, false);
furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_write(&gpio_cc1101_g0, false);
instance->status_tx = SubGhzTestStaticStatusIDLE;
with_view_model(

View File

@@ -425,6 +425,7 @@ MU_TEST(infrared_test_decoder_mixed) {
infrared_test_run_decoder(InfraredProtocolSamsung32, 1);
infrared_test_run_decoder(InfraredProtocolSIRC, 3);
infrared_test_run_decoder(InfraredProtocolKaseikyo, 1);
infrared_test_run_decoder(InfraredProtocolRCA, 1);
}
MU_TEST(infrared_test_decoder_nec) {
@@ -499,6 +500,15 @@ MU_TEST(infrared_test_decoder_kaseikyo) {
infrared_test_run_decoder(InfraredProtocolKaseikyo, 6);
}
MU_TEST(infrared_test_decoder_rca) {
infrared_test_run_decoder(InfraredProtocolRCA, 1);
infrared_test_run_decoder(InfraredProtocolRCA, 2);
infrared_test_run_decoder(InfraredProtocolRCA, 3);
infrared_test_run_decoder(InfraredProtocolRCA, 4);
infrared_test_run_decoder(InfraredProtocolRCA, 5);
infrared_test_run_decoder(InfraredProtocolRCA, 6);
}
MU_TEST(infrared_test_encoder_decoder_all) {
infrared_test_run_encoder_decoder(InfraredProtocolNEC, 1);
infrared_test_run_encoder_decoder(InfraredProtocolNECext, 1);
@@ -509,6 +519,7 @@ MU_TEST(infrared_test_encoder_decoder_all) {
infrared_test_run_encoder_decoder(InfraredProtocolRC5, 1);
infrared_test_run_encoder_decoder(InfraredProtocolSIRC, 1);
infrared_test_run_encoder_decoder(InfraredProtocolKaseikyo, 1);
infrared_test_run_encoder_decoder(InfraredProtocolRCA, 1);
}
MU_TEST_SUITE(infrared_test) {
@@ -527,6 +538,7 @@ MU_TEST_SUITE(infrared_test) {
MU_RUN_TEST(infrared_test_decoder_samsung32);
MU_RUN_TEST(infrared_test_decoder_necext1);
MU_RUN_TEST(infrared_test_decoder_kaseikyo);
MU_RUN_TEST(infrared_test_decoder_rca);
MU_RUN_TEST(infrared_test_decoder_mixed);
MU_RUN_TEST(infrared_test_encoder_decoder_all);
}

View File

@@ -0,0 +1,813 @@
#include "cc1101_ext.h"
#include <lib/subghz/devices/cc1101_configs.h>
#include <furi_hal_version.h>
#include <furi_hal_rtc.h>
#include <furi_hal_spi.h>
#include <furi_hal_interrupt.h>
#include <furi_hal_resources.h>
#include <furi_hal_bus.h>
#include <stm32wbxx_ll_dma.h>
#include <furi_hal_cortex.h>
#include <furi.h>
#include <cc1101.h>
#include <stdio.h>
#define TAG "SubGhz_Device_CC1101_Ext"
#define SUBGHZ_DEVICE_CC1101_EXT_TX_GPIO &gpio_ext_pb2
#define SUBGHZ_DEVICE_CC1101_EXT_DANGEROUS_RANGE false
/* DMA Channels definition */
#define SUBGHZ_DEVICE_CC1101_EXT_DMA DMA2
#define SUBGHZ_DEVICE_CC1101_EXT_DMA_CH3_CHANNEL LL_DMA_CHANNEL_3
#define SUBGHZ_DEVICE_CC1101_EXT_DMA_CH4_CHANNEL LL_DMA_CHANNEL_4
#define SUBGHZ_DEVICE_CC1101_EXT_DMA_CH5_CHANNEL LL_DMA_CHANNEL_5
#define SUBGHZ_DEVICE_CC1101_EXT_DMA_CH3_IRQ FuriHalInterruptIdDma2Ch3
#define SUBGHZ_DEVICE_CC1101_EXT_DMA_CH3_DEF \
SUBGHZ_DEVICE_CC1101_EXT_DMA, SUBGHZ_DEVICE_CC1101_EXT_DMA_CH3_CHANNEL
#define SUBGHZ_DEVICE_CC1101_EXT_DMA_CH4_DEF \
SUBGHZ_DEVICE_CC1101_EXT_DMA, SUBGHZ_DEVICE_CC1101_EXT_DMA_CH4_CHANNEL
#define SUBGHZ_DEVICE_CC1101_EXT_DMA_CH5_DEF \
SUBGHZ_DEVICE_CC1101_EXT_DMA, SUBGHZ_DEVICE_CC1101_EXT_DMA_CH5_CHANNEL
/** Low level buffer dimensions and guard times */
#define SUBGHZ_DEVICE_CC1101_EXT_ASYNC_TX_BUFFER_FULL (256)
#define SUBGHZ_DEVICE_CC1101_EXT_ASYNC_TX_BUFFER_HALF \
(SUBGHZ_DEVICE_CC1101_EXT_ASYNC_TX_BUFFER_FULL / 2)
#define SUBGHZ_DEVICE_CC1101_EXT_ASYNC_TX_GUARD_TIME 999
/** SubGhz state */
typedef enum {
SubGhzDeviceCC1101ExtStateInit, /**< Init pending */
SubGhzDeviceCC1101ExtStateIdle, /**< Idle, energy save mode */
SubGhzDeviceCC1101ExtStateAsyncRx, /**< Async RX started */
SubGhzDeviceCC1101ExtStateAsyncTx, /**< Async TX started, DMA and timer is on */
SubGhzDeviceCC1101ExtStateAsyncTxEnd, /**< Async TX complete, cleanup needed */
} SubGhzDeviceCC1101ExtState;
/** SubGhz regulation, receive transmission on the current frequency for the
* region */
typedef enum {
SubGhzDeviceCC1101ExtRegulationOnlyRx, /**only Rx*/
SubGhzDeviceCC1101ExtRegulationTxRx, /**TxRx*/
} SubGhzDeviceCC1101ExtRegulation;
typedef struct {
uint32_t* buffer;
LevelDuration carry_ld;
SubGhzDeviceCC1101ExtCallback callback;
void* callback_context;
uint32_t gpio_tx_buff[2];
uint32_t debug_gpio_buff[2];
} SubGhzDeviceCC1101ExtAsyncTx;
typedef struct {
uint32_t capture_delta_duration;
SubGhzDeviceCC1101ExtCaptureCallback capture_callback;
void* capture_callback_context;
} SubGhzDeviceCC1101ExtAsyncRx;
typedef struct {
volatile SubGhzDeviceCC1101ExtState state;
volatile SubGhzDeviceCC1101ExtRegulation regulation;
const GpioPin* async_mirror_pin;
FuriHalSpiBusHandle* spi_bus_handle;
const GpioPin* g0_pin;
SubGhzDeviceCC1101ExtAsyncTx async_tx;
SubGhzDeviceCC1101ExtAsyncRx async_rx;
} SubGhzDeviceCC1101Ext;
static SubGhzDeviceCC1101Ext* subghz_device_cc1101_ext = NULL;
static bool subghz_device_cc1101_ext_check_init() {
furi_assert(subghz_device_cc1101_ext->state == SubGhzDeviceCC1101ExtStateInit);
subghz_device_cc1101_ext->state = SubGhzDeviceCC1101ExtStateIdle;
bool ret = false;
CC1101Status cc1101_status = {0};
furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle);
FuriHalCortexTimer timer = furi_hal_cortex_timer_get(100 * 1000);
do {
// Reset
furi_hal_gpio_init(
subghz_device_cc1101_ext->g0_pin, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_init(
subghz_device_cc1101_ext->spi_bus_handle->miso,
GpioModeInput,
GpioPullUp,
GpioSpeedLow);
cc1101_status = cc1101_reset(subghz_device_cc1101_ext->spi_bus_handle);
if(cc1101_status.CHIP_RDYn != 0) {
//timeout or error
break;
}
cc1101_status = cc1101_write_reg(
subghz_device_cc1101_ext->spi_bus_handle, CC1101_IOCFG0, CC1101IocfgHighImpedance);
if(cc1101_status.CHIP_RDYn != 0) {
//timeout or error
break;
}
// Prepare GD0 for power on self test
furi_hal_gpio_init(
subghz_device_cc1101_ext->g0_pin, GpioModeInput, GpioPullUp, GpioSpeedLow);
// GD0 low
cc1101_status = cc1101_write_reg(
subghz_device_cc1101_ext->spi_bus_handle, CC1101_IOCFG0, CC1101IocfgHW);
if(cc1101_status.CHIP_RDYn != 0) {
//timeout or error
break;
}
while(furi_hal_gpio_read(subghz_device_cc1101_ext->g0_pin) != false) {
if(furi_hal_cortex_timer_is_expired(timer)) {
//timeout
break;
}
}
if(furi_hal_cortex_timer_is_expired(timer)) {
//timeout
break;
}
// GD0 high
furi_hal_gpio_init(
subghz_device_cc1101_ext->g0_pin, GpioModeInput, GpioPullDown, GpioSpeedLow);
cc1101_status = cc1101_write_reg(
subghz_device_cc1101_ext->spi_bus_handle,
CC1101_IOCFG0,
CC1101IocfgHW | CC1101_IOCFG_INV);
if(cc1101_status.CHIP_RDYn != 0) {
//timeout or error
break;
}
while(furi_hal_gpio_read(subghz_device_cc1101_ext->g0_pin) != true) {
if(furi_hal_cortex_timer_is_expired(timer)) {
//timeout
break;
}
}
if(furi_hal_cortex_timer_is_expired(timer)) {
//timeout
break;
}
// Reset GD0 to floating state
cc1101_status = cc1101_write_reg(
subghz_device_cc1101_ext->spi_bus_handle, CC1101_IOCFG0, CC1101IocfgHighImpedance);
if(cc1101_status.CHIP_RDYn != 0) {
//timeout or error
break;
}
furi_hal_gpio_init(
subghz_device_cc1101_ext->g0_pin, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
// Go to sleep
cc1101_status = cc1101_shutdown(subghz_device_cc1101_ext->spi_bus_handle);
if(cc1101_status.CHIP_RDYn != 0) {
//timeout or error
break;
}
ret = true;
} while(false);
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle);
if(ret) {
FURI_LOG_I(TAG, "Init OK");
} else {
FURI_LOG_E(TAG, "Init failed");
furi_hal_gpio_init(
subghz_device_cc1101_ext->g0_pin, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
}
return ret;
}
bool subghz_device_cc1101_ext_alloc() {
furi_assert(subghz_device_cc1101_ext == NULL);
subghz_device_cc1101_ext = malloc(sizeof(SubGhzDeviceCC1101Ext));
subghz_device_cc1101_ext->state = SubGhzDeviceCC1101ExtStateInit;
subghz_device_cc1101_ext->regulation = SubGhzDeviceCC1101ExtRegulationTxRx;
subghz_device_cc1101_ext->async_mirror_pin = NULL;
subghz_device_cc1101_ext->spi_bus_handle = &furi_hal_spi_bus_handle_external;
subghz_device_cc1101_ext->g0_pin = SUBGHZ_DEVICE_CC1101_EXT_TX_GPIO;
subghz_device_cc1101_ext->async_rx.capture_delta_duration = 0;
furi_hal_spi_bus_handle_init(subghz_device_cc1101_ext->spi_bus_handle);
return subghz_device_cc1101_ext_check_init();
}
void subghz_device_cc1101_ext_free() {
furi_assert(subghz_device_cc1101_ext != NULL);
furi_hal_spi_bus_handle_deinit(subghz_device_cc1101_ext->spi_bus_handle);
free(subghz_device_cc1101_ext);
subghz_device_cc1101_ext = NULL;
}
void subghz_device_cc1101_ext_set_async_mirror_pin(const GpioPin* pin) {
subghz_device_cc1101_ext->async_mirror_pin = pin;
}
const GpioPin* subghz_device_cc1101_ext_get_data_gpio() {
return subghz_device_cc1101_ext->g0_pin;
}
bool subghz_device_cc1101_ext_is_connect() {
bool ret = false;
if(subghz_device_cc1101_ext == NULL) { // not initialized
ret = subghz_device_cc1101_ext_alloc();
subghz_device_cc1101_ext_free();
} else { // initialized
furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle);
uint8_t partnumber = cc1101_get_partnumber(subghz_device_cc1101_ext->spi_bus_handle);
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle);
ret = (partnumber != 0) && (partnumber != 0xFF);
}
return ret;
}
void subghz_device_cc1101_ext_sleep() {
furi_assert(subghz_device_cc1101_ext->state == SubGhzDeviceCC1101ExtStateIdle);
furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle);
cc1101_switch_to_idle(subghz_device_cc1101_ext->spi_bus_handle);
cc1101_write_reg(
subghz_device_cc1101_ext->spi_bus_handle, CC1101_IOCFG0, CC1101IocfgHighImpedance);
furi_hal_gpio_init(subghz_device_cc1101_ext->g0_pin, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
cc1101_shutdown(subghz_device_cc1101_ext->spi_bus_handle);
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle);
}
void subghz_device_cc1101_ext_dump_state() {
furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle);
printf(
"[subghz_device_cc1101_ext] cc1101 chip %d, version %d\r\n",
cc1101_get_partnumber(subghz_device_cc1101_ext->spi_bus_handle),
cc1101_get_version(subghz_device_cc1101_ext->spi_bus_handle));
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle);
}
void subghz_device_cc1101_ext_load_custom_preset(const uint8_t* preset_data) {
//load config
furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle);
cc1101_reset(subghz_device_cc1101_ext->spi_bus_handle);
uint32_t i = 0;
uint8_t pa[8] = {0};
while(preset_data[i]) {
cc1101_write_reg(
subghz_device_cc1101_ext->spi_bus_handle, preset_data[i], preset_data[i + 1]);
i += 2;
}
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle);
//load pa table
memcpy(&pa[0], &preset_data[i + 2], 8);
subghz_device_cc1101_ext_load_patable(pa);
//show debug
if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) {
i = 0;
FURI_LOG_D(TAG, "Loading custom preset");
while(preset_data[i]) {
FURI_LOG_D(TAG, "Reg[%lu]: %02X=%02X", i, preset_data[i], preset_data[i + 1]);
i += 2;
}
for(uint8_t y = i; y < i + 10; y++) {
FURI_LOG_D(TAG, "PA[%u]: %02X", y, preset_data[y]);
}
}
}
void subghz_device_cc1101_ext_load_registers(const uint8_t* data) {
furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle);
cc1101_reset(subghz_device_cc1101_ext->spi_bus_handle);
uint32_t i = 0;
while(data[i]) {
cc1101_write_reg(subghz_device_cc1101_ext->spi_bus_handle, data[i], data[i + 1]);
i += 2;
}
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle);
}
void subghz_device_cc1101_ext_load_patable(const uint8_t data[8]) {
furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle);
cc1101_set_pa_table(subghz_device_cc1101_ext->spi_bus_handle, data);
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle);
}
void subghz_device_cc1101_ext_write_packet(const uint8_t* data, uint8_t size) {
furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle);
cc1101_flush_tx(subghz_device_cc1101_ext->spi_bus_handle);
cc1101_write_reg(subghz_device_cc1101_ext->spi_bus_handle, CC1101_FIFO, size);
cc1101_write_fifo(subghz_device_cc1101_ext->spi_bus_handle, data, size);
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle);
}
void subghz_device_cc1101_ext_flush_rx() {
furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle);
cc1101_flush_rx(subghz_device_cc1101_ext->spi_bus_handle);
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle);
}
void subghz_device_cc1101_ext_flush_tx() {
furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle);
cc1101_flush_tx(subghz_device_cc1101_ext->spi_bus_handle);
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle);
}
bool subghz_device_cc1101_ext_rx_pipe_not_empty() {
CC1101RxBytes status[1];
furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle);
cc1101_read_reg(
subghz_device_cc1101_ext->spi_bus_handle,
(CC1101_STATUS_RXBYTES) | CC1101_BURST,
(uint8_t*)status);
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle);
// TODO: you can add a buffer overflow flag if needed
if(status->NUM_RXBYTES > 0) {
return true;
} else {
return false;
}
}
bool subghz_device_cc1101_ext_is_rx_data_crc_valid() {
furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle);
uint8_t data[1];
cc1101_read_reg(
subghz_device_cc1101_ext->spi_bus_handle, CC1101_STATUS_LQI | CC1101_BURST, data);
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle);
if(((data[0] >> 7) & 0x01)) {
return true;
} else {
return false;
}
}
void subghz_device_cc1101_ext_read_packet(uint8_t* data, uint8_t* size) {
furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle);
cc1101_read_fifo(subghz_device_cc1101_ext->spi_bus_handle, data, size);
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle);
}
void subghz_device_cc1101_ext_shutdown() {
furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle);
// Reset and shutdown
cc1101_shutdown(subghz_device_cc1101_ext->spi_bus_handle);
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle);
}
void subghz_device_cc1101_ext_reset() {
furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle);
furi_hal_gpio_init(subghz_device_cc1101_ext->g0_pin, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
cc1101_switch_to_idle(subghz_device_cc1101_ext->spi_bus_handle);
cc1101_reset(subghz_device_cc1101_ext->spi_bus_handle);
cc1101_write_reg(
subghz_device_cc1101_ext->spi_bus_handle, CC1101_IOCFG0, CC1101IocfgHighImpedance);
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle);
}
void subghz_device_cc1101_ext_idle() {
furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle);
cc1101_switch_to_idle(subghz_device_cc1101_ext->spi_bus_handle);
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle);
}
void subghz_device_cc1101_ext_rx() {
furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle);
cc1101_switch_to_rx(subghz_device_cc1101_ext->spi_bus_handle);
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle);
}
bool subghz_device_cc1101_ext_tx() {
if(subghz_device_cc1101_ext->regulation != SubGhzDeviceCC1101ExtRegulationTxRx) return false;
furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle);
cc1101_switch_to_tx(subghz_device_cc1101_ext->spi_bus_handle);
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle);
return true;
}
float subghz_device_cc1101_ext_get_rssi() {
furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle);
int32_t rssi_dec = cc1101_get_rssi(subghz_device_cc1101_ext->spi_bus_handle);
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle);
float rssi = rssi_dec;
if(rssi_dec >= 128) {
rssi = ((rssi - 256.0f) / 2.0f) - 74.0f;
} else {
rssi = (rssi / 2.0f) - 74.0f;
}
return rssi;
}
uint8_t subghz_device_cc1101_ext_get_lqi() {
furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle);
uint8_t data[1];
cc1101_read_reg(
subghz_device_cc1101_ext->spi_bus_handle, CC1101_STATUS_LQI | CC1101_BURST, data);
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle);
return data[0] & 0x7F;
}
bool subghz_device_cc1101_ext_is_frequency_valid(uint32_t value) {
if(!(value >= 281000000 && value <= 361000000) &&
!(value >= 378000000 && value <= 481000000) &&
!(value >= 749000000 && value <= 962000000)) {
return false;
}
return true;
}
bool subghz_device_cc1101_ext_is_tx_allowed(uint32_t value) {
if(!(SUBGHZ_DEVICE_CC1101_EXT_DANGEROUS_RANGE) &&
!(value >= 299999755 && value <= 350000335) && // was increased from 348 to 350
!(value >= 386999938 && value <= 467750000) && // was increased from 464 to 467.75
!(value >= 778999847 && value <= 928000000)) {
FURI_LOG_I(TAG, "Frequency blocked - outside default range");
return false;
} else if(
(SUBGHZ_DEVICE_CC1101_EXT_DANGEROUS_RANGE) &&
!subghz_device_cc1101_ext_is_frequency_valid(value)) {
FURI_LOG_I(TAG, "Frequency blocked - outside dangerous range");
return false;
}
return true;
}
uint32_t subghz_device_cc1101_ext_set_frequency(uint32_t value) {
if(subghz_device_cc1101_ext_is_tx_allowed(value)) {
subghz_device_cc1101_ext->regulation = SubGhzDeviceCC1101ExtRegulationTxRx;
} else {
subghz_device_cc1101_ext->regulation = SubGhzDeviceCC1101ExtRegulationTxRx;
}
furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle);
uint32_t real_frequency =
cc1101_set_frequency(subghz_device_cc1101_ext->spi_bus_handle, value);
cc1101_calibrate(subghz_device_cc1101_ext->spi_bus_handle);
while(true) {
CC1101Status status = cc1101_get_status(subghz_device_cc1101_ext->spi_bus_handle);
if(status.STATE == CC1101StateIDLE) break;
}
furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle);
return real_frequency;
}
static bool subghz_device_cc1101_ext_start_debug() {
bool ret = false;
if(subghz_device_cc1101_ext->async_mirror_pin != NULL) {
furi_hal_gpio_init(
subghz_device_cc1101_ext->async_mirror_pin,
GpioModeOutputPushPull,
GpioPullNo,
GpioSpeedVeryHigh);
ret = true;
}
return ret;
}
static bool subghz_device_cc1101_ext_stop_debug() {
bool ret = false;
if(subghz_device_cc1101_ext->async_mirror_pin != NULL) {
furi_hal_gpio_init(
subghz_device_cc1101_ext->async_mirror_pin, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
ret = true;
}
return ret;
}
static void subghz_device_cc1101_ext_capture_ISR() {
if(!furi_hal_gpio_read(subghz_device_cc1101_ext->g0_pin)) {
if(subghz_device_cc1101_ext->async_rx.capture_callback) {
if(subghz_device_cc1101_ext->async_mirror_pin != NULL)
furi_hal_gpio_write(subghz_device_cc1101_ext->async_mirror_pin, false);
subghz_device_cc1101_ext->async_rx.capture_callback(
true,
LL_TIM_GetCounter(TIM17),
(void*)subghz_device_cc1101_ext->async_rx.capture_callback_context);
}
} else {
if(subghz_device_cc1101_ext->async_rx.capture_callback) {
if(subghz_device_cc1101_ext->async_mirror_pin != NULL)
furi_hal_gpio_write(subghz_device_cc1101_ext->async_mirror_pin, true);
subghz_device_cc1101_ext->async_rx.capture_callback(
false,
LL_TIM_GetCounter(TIM17),
(void*)subghz_device_cc1101_ext->async_rx.capture_callback_context);
}
}
LL_TIM_SetCounter(TIM17, 6);
}
void subghz_device_cc1101_ext_start_async_rx(
SubGhzDeviceCC1101ExtCaptureCallback callback,
void* context) {
furi_assert(subghz_device_cc1101_ext->state == SubGhzDeviceCC1101ExtStateIdle);
subghz_device_cc1101_ext->state = SubGhzDeviceCC1101ExtStateAsyncRx;
subghz_device_cc1101_ext->async_rx.capture_callback = callback;
subghz_device_cc1101_ext->async_rx.capture_callback_context = context;
furi_hal_bus_enable(FuriHalBusTIM17);
// Configure TIM
LL_TIM_SetPrescaler(TIM17, 64 - 1);
LL_TIM_SetCounterMode(TIM17, LL_TIM_COUNTERMODE_UP);
LL_TIM_SetAutoReload(TIM17, 0xFFFF);
LL_TIM_SetClockDivision(TIM17, LL_TIM_CLOCKDIVISION_DIV1);
// Timer: advanced
LL_TIM_SetClockSource(TIM17, LL_TIM_CLOCKSOURCE_INTERNAL);
LL_TIM_DisableARRPreload(TIM17);
LL_TIM_DisableDMAReq_TRIG(TIM17);
LL_TIM_DisableIT_TRIG(TIM17);
furi_hal_gpio_init(
subghz_device_cc1101_ext->g0_pin, GpioModeInterruptRiseFall, GpioPullUp, GpioSpeedVeryHigh);
furi_hal_gpio_remove_int_callback(subghz_device_cc1101_ext->g0_pin);
furi_hal_gpio_add_int_callback(
subghz_device_cc1101_ext->g0_pin,
subghz_device_cc1101_ext_capture_ISR,
subghz_device_cc1101_ext->async_rx.capture_callback);
// Start timer
LL_TIM_SetCounter(TIM17, 0);
LL_TIM_EnableCounter(TIM17);
// Start debug
subghz_device_cc1101_ext_start_debug();
// Switch to RX
subghz_device_cc1101_ext_rx();
//Clear the variable after the end of the session
subghz_device_cc1101_ext->async_rx.capture_delta_duration = 0;
}
void subghz_device_cc1101_ext_stop_async_rx() {
furi_assert(subghz_device_cc1101_ext->state == SubGhzDeviceCC1101ExtStateAsyncRx);
subghz_device_cc1101_ext->state = SubGhzDeviceCC1101ExtStateIdle;
// Shutdown radio
subghz_device_cc1101_ext_idle();
FURI_CRITICAL_ENTER();
furi_hal_bus_disable(FuriHalBusTIM17);
// Stop debug
subghz_device_cc1101_ext_stop_debug();
FURI_CRITICAL_EXIT();
furi_hal_gpio_remove_int_callback(subghz_device_cc1101_ext->g0_pin);
furi_hal_gpio_init(subghz_device_cc1101_ext->g0_pin, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
}
static void subghz_device_cc1101_ext_async_tx_refill(uint32_t* buffer, size_t samples) {
furi_assert(subghz_device_cc1101_ext->state == SubGhzDeviceCC1101ExtStateAsyncTx);
while(samples > 0) {
bool is_odd = samples % 2;
LevelDuration ld;
if(level_duration_is_reset(subghz_device_cc1101_ext->async_tx.carry_ld)) {
ld = subghz_device_cc1101_ext->async_tx.callback(
subghz_device_cc1101_ext->async_tx.callback_context);
} else {
ld = subghz_device_cc1101_ext->async_tx.carry_ld;
subghz_device_cc1101_ext->async_tx.carry_ld = level_duration_reset();
}
if(level_duration_is_wait(ld)) {
*buffer = SUBGHZ_DEVICE_CC1101_EXT_ASYNC_TX_GUARD_TIME;
buffer++;
samples--;
} else if(level_duration_is_reset(ld)) {
*buffer = 0;
buffer++;
samples--;
LL_DMA_DisableIT_HT(SUBGHZ_DEVICE_CC1101_EXT_DMA_CH3_DEF);
LL_DMA_DisableIT_TC(SUBGHZ_DEVICE_CC1101_EXT_DMA_CH3_DEF);
LL_TIM_EnableIT_UPDATE(TIM17);
break;
} else {
bool level = level_duration_get_level(ld);
// Inject guard time if level is incorrect
if(is_odd != level) {
*buffer = SUBGHZ_DEVICE_CC1101_EXT_ASYNC_TX_GUARD_TIME;
buffer++;
samples--;
// Special case: prevent buffer overflow if sample is last
if(samples == 0) {
subghz_device_cc1101_ext->async_tx.carry_ld = ld;
break;
}
}
uint32_t duration = level_duration_get_duration(ld);
furi_assert(duration > 0);
*buffer = duration - 1;
buffer++;
samples--;
}
}
}
static void subghz_device_cc1101_ext_async_tx_dma_isr() {
furi_assert(subghz_device_cc1101_ext->state == SubGhzDeviceCC1101ExtStateAsyncTx);
#if SUBGHZ_DEVICE_CC1101_EXT_DMA_CH3_CHANNEL == LL_DMA_CHANNEL_3
if(LL_DMA_IsActiveFlag_HT3(SUBGHZ_DEVICE_CC1101_EXT_DMA)) {
LL_DMA_ClearFlag_HT3(SUBGHZ_DEVICE_CC1101_EXT_DMA);
subghz_device_cc1101_ext_async_tx_refill(
subghz_device_cc1101_ext->async_tx.buffer,
SUBGHZ_DEVICE_CC1101_EXT_ASYNC_TX_BUFFER_HALF);
}
if(LL_DMA_IsActiveFlag_TC3(SUBGHZ_DEVICE_CC1101_EXT_DMA)) {
LL_DMA_ClearFlag_TC3(SUBGHZ_DEVICE_CC1101_EXT_DMA);
subghz_device_cc1101_ext_async_tx_refill(
subghz_device_cc1101_ext->async_tx.buffer +
SUBGHZ_DEVICE_CC1101_EXT_ASYNC_TX_BUFFER_HALF,
SUBGHZ_DEVICE_CC1101_EXT_ASYNC_TX_BUFFER_HALF);
}
#else
#error Update this code. Would you kindly?
#endif
}
static void subghz_device_cc1101_ext_async_tx_timer_isr() {
if(LL_TIM_IsActiveFlag_UPDATE(TIM17)) {
if(LL_TIM_GetAutoReload(TIM17) == 0) {
LL_DMA_DisableChannel(SUBGHZ_DEVICE_CC1101_EXT_DMA_CH3_DEF);
furi_hal_gpio_write(subghz_device_cc1101_ext->g0_pin, false);
if(subghz_device_cc1101_ext->async_mirror_pin != NULL)
furi_hal_gpio_write(subghz_device_cc1101_ext->async_mirror_pin, false);
LL_TIM_DisableCounter(TIM17);
subghz_device_cc1101_ext->state = SubGhzDeviceCC1101ExtStateAsyncTxEnd;
}
LL_TIM_ClearFlag_UPDATE(TIM17);
}
}
bool subghz_device_cc1101_ext_start_async_tx(SubGhzDeviceCC1101ExtCallback callback, void* context) {
furi_assert(subghz_device_cc1101_ext->state == SubGhzDeviceCC1101ExtStateIdle);
furi_assert(callback);
//If transmission is prohibited by regional settings
if(subghz_device_cc1101_ext->regulation != SubGhzDeviceCC1101ExtRegulationTxRx) return false;
subghz_device_cc1101_ext->async_tx.callback = callback;
subghz_device_cc1101_ext->async_tx.callback_context = context;
subghz_device_cc1101_ext->state = SubGhzDeviceCC1101ExtStateAsyncTx;
subghz_device_cc1101_ext->async_tx.buffer =
malloc(SUBGHZ_DEVICE_CC1101_EXT_ASYNC_TX_BUFFER_FULL * sizeof(uint32_t));
//Signal generation with mem-to-mem DMA
furi_hal_gpio_write(subghz_device_cc1101_ext->g0_pin, false);
furi_hal_gpio_init(
subghz_device_cc1101_ext->g0_pin, GpioModeOutputPushPull, GpioPullNo, GpioSpeedVeryHigh);
// Configure DMA update timer
LL_DMA_SetMemoryAddress(
SUBGHZ_DEVICE_CC1101_EXT_DMA_CH3_DEF, (uint32_t)subghz_device_cc1101_ext->async_tx.buffer);
LL_DMA_SetPeriphAddress(SUBGHZ_DEVICE_CC1101_EXT_DMA_CH3_DEF, (uint32_t) & (TIM17->ARR));
LL_DMA_ConfigTransfer(
SUBGHZ_DEVICE_CC1101_EXT_DMA_CH3_DEF,
LL_DMA_DIRECTION_MEMORY_TO_PERIPH | LL_DMA_MODE_CIRCULAR | LL_DMA_PERIPH_NOINCREMENT |
LL_DMA_MEMORY_INCREMENT | LL_DMA_PDATAALIGN_WORD | LL_DMA_MDATAALIGN_WORD |
LL_DMA_MODE_NORMAL);
LL_DMA_SetDataLength(
SUBGHZ_DEVICE_CC1101_EXT_DMA_CH3_DEF, SUBGHZ_DEVICE_CC1101_EXT_ASYNC_TX_BUFFER_FULL);
LL_DMA_SetPeriphRequest(SUBGHZ_DEVICE_CC1101_EXT_DMA_CH3_DEF, LL_DMAMUX_REQ_TIM17_UP);
LL_DMA_EnableIT_TC(SUBGHZ_DEVICE_CC1101_EXT_DMA_CH3_DEF);
LL_DMA_EnableIT_HT(SUBGHZ_DEVICE_CC1101_EXT_DMA_CH3_DEF);
LL_DMA_EnableChannel(SUBGHZ_DEVICE_CC1101_EXT_DMA_CH3_DEF);
furi_hal_interrupt_set_isr(
SUBGHZ_DEVICE_CC1101_EXT_DMA_CH3_IRQ, subghz_device_cc1101_ext_async_tx_dma_isr, NULL);
furi_hal_bus_enable(FuriHalBusTIM17);
// Configure TIM
LL_TIM_SetPrescaler(TIM17, 64 - 1);
LL_TIM_SetCounterMode(TIM17, LL_TIM_COUNTERMODE_UP);
LL_TIM_SetAutoReload(TIM17, 0xFFFF);
LL_TIM_SetClockDivision(TIM17, LL_TIM_CLOCKDIVISION_DIV1);
LL_TIM_SetClockSource(TIM17, LL_TIM_CLOCKSOURCE_INTERNAL);
LL_TIM_DisableARRPreload(TIM17);
furi_hal_interrupt_set_isr(
FuriHalInterruptIdTim1TrgComTim17, subghz_device_cc1101_ext_async_tx_timer_isr, NULL);
subghz_device_cc1101_ext_async_tx_refill(
subghz_device_cc1101_ext->async_tx.buffer, SUBGHZ_DEVICE_CC1101_EXT_ASYNC_TX_BUFFER_FULL);
// Configure tx gpio dma
const GpioPin* gpio = subghz_device_cc1101_ext->g0_pin;
subghz_device_cc1101_ext->async_tx.gpio_tx_buff[0] = (uint32_t)gpio->pin << GPIO_NUMBER;
subghz_device_cc1101_ext->async_tx.gpio_tx_buff[1] = gpio->pin;
LL_DMA_SetMemoryAddress(
SUBGHZ_DEVICE_CC1101_EXT_DMA_CH4_DEF,
(uint32_t)subghz_device_cc1101_ext->async_tx.gpio_tx_buff);
LL_DMA_SetPeriphAddress(SUBGHZ_DEVICE_CC1101_EXT_DMA_CH4_DEF, (uint32_t) & (gpio->port->BSRR));
LL_DMA_ConfigTransfer(
SUBGHZ_DEVICE_CC1101_EXT_DMA_CH4_DEF,
LL_DMA_DIRECTION_MEMORY_TO_PERIPH | LL_DMA_MODE_CIRCULAR | LL_DMA_PERIPH_NOINCREMENT |
LL_DMA_MEMORY_INCREMENT | LL_DMA_PDATAALIGN_WORD | LL_DMA_MDATAALIGN_WORD |
LL_DMA_PRIORITY_HIGH);
LL_DMA_SetDataLength(SUBGHZ_DEVICE_CC1101_EXT_DMA_CH4_DEF, 2);
LL_DMA_SetPeriphRequest(SUBGHZ_DEVICE_CC1101_EXT_DMA_CH4_DEF, LL_DMAMUX_REQ_TIM17_UP);
LL_DMA_EnableChannel(SUBGHZ_DEVICE_CC1101_EXT_DMA_CH4_DEF);
// Start debug
if(subghz_device_cc1101_ext_start_debug()) {
gpio = subghz_device_cc1101_ext->async_mirror_pin;
subghz_device_cc1101_ext->async_tx.debug_gpio_buff[0] = (uint32_t)gpio->pin << GPIO_NUMBER;
subghz_device_cc1101_ext->async_tx.debug_gpio_buff[1] = gpio->pin;
LL_DMA_SetMemoryAddress(
SUBGHZ_DEVICE_CC1101_EXT_DMA_CH5_DEF,
(uint32_t)subghz_device_cc1101_ext->async_tx.debug_gpio_buff);
LL_DMA_SetPeriphAddress(
SUBGHZ_DEVICE_CC1101_EXT_DMA_CH5_DEF, (uint32_t) & (gpio->port->BSRR));
LL_DMA_ConfigTransfer(
SUBGHZ_DEVICE_CC1101_EXT_DMA_CH5_DEF,
LL_DMA_DIRECTION_MEMORY_TO_PERIPH | LL_DMA_MODE_CIRCULAR | LL_DMA_PERIPH_NOINCREMENT |
LL_DMA_MEMORY_INCREMENT | LL_DMA_PDATAALIGN_WORD | LL_DMA_MDATAALIGN_WORD |
LL_DMA_PRIORITY_LOW);
LL_DMA_SetDataLength(SUBGHZ_DEVICE_CC1101_EXT_DMA_CH5_DEF, 2);
LL_DMA_SetPeriphRequest(SUBGHZ_DEVICE_CC1101_EXT_DMA_CH5_DEF, LL_DMAMUX_REQ_TIM17_UP);
LL_DMA_EnableChannel(SUBGHZ_DEVICE_CC1101_EXT_DMA_CH5_DEF);
}
// Start counter
LL_TIM_EnableDMAReq_UPDATE(TIM17);
LL_TIM_GenerateEvent_UPDATE(TIM17);
subghz_device_cc1101_ext_tx();
LL_TIM_SetCounter(TIM17, 0);
LL_TIM_EnableCounter(TIM17);
return true;
}
bool subghz_device_cc1101_ext_is_async_tx_complete() {
return subghz_device_cc1101_ext->state == SubGhzDeviceCC1101ExtStateAsyncTxEnd;
}
void subghz_device_cc1101_ext_stop_async_tx() {
furi_assert(
subghz_device_cc1101_ext->state == SubGhzDeviceCC1101ExtStateAsyncTx ||
subghz_device_cc1101_ext->state == SubGhzDeviceCC1101ExtStateAsyncTxEnd);
// Shutdown radio
subghz_device_cc1101_ext_idle();
// Deinitialize Timer
FURI_CRITICAL_ENTER();
furi_hal_bus_disable(FuriHalBusTIM17);
furi_hal_interrupt_set_isr(FuriHalInterruptIdTim1TrgComTim17, NULL, NULL);
// Deinitialize DMA
LL_DMA_DeInit(SUBGHZ_DEVICE_CC1101_EXT_DMA_CH3_DEF);
LL_DMA_DisableChannel(SUBGHZ_DEVICE_CC1101_EXT_DMA_CH4_DEF);
furi_hal_interrupt_set_isr(SUBGHZ_DEVICE_CC1101_EXT_DMA_CH3_IRQ, NULL, NULL);
// Deinitialize GPIO
furi_hal_gpio_write(subghz_device_cc1101_ext->g0_pin, false);
furi_hal_gpio_init(subghz_device_cc1101_ext->g0_pin, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
// Stop debug
if(subghz_device_cc1101_ext_stop_debug()) {
LL_DMA_DisableChannel(SUBGHZ_DEVICE_CC1101_EXT_DMA_CH5_DEF);
}
FURI_CRITICAL_EXIT();
free(subghz_device_cc1101_ext->async_tx.buffer);
subghz_device_cc1101_ext->state = SubGhzDeviceCC1101ExtStateIdle;
}

View File

@@ -5,7 +5,6 @@
#include <input/input.h>
#include <notification/notification.h>
#include <notification/notification_messages.h>
#include <gui/canvas_i.h>
#include "bomberduck_icons.h"
int max(int a, int b) {

View File

@@ -0,0 +1,16 @@
App(
appid="camerasuite",
apptype=FlipperAppType.EXTERNAL,
cdefines=["APP_CAMERA_SUITE"],
entry_point="camera_suite_app",
fap_author="Cody Tolene",
fap_category="GPIO",
fap_description="A camera suite application for the Flipper Zero ESP32-CAM module.",
fap_icon="icons/camera_suite.png",
fap_libs=["assets"],
fap_weburl="https://github.com/CodyTolene/Flipper-Zero-Cam",
name="[ESP32] Camera Suite",
order=1,
requires=["gui", "storage"],
stack_size=8 * 1024,
)

View File

@@ -0,0 +1,139 @@
#include "camera_suite.h"
#include <stdlib.h>
bool camera_suite_custom_event_callback(void* context, uint32_t event) {
furi_assert(context);
CameraSuite* app = context;
return scene_manager_handle_custom_event(app->scene_manager, event);
}
void camera_suite_tick_event_callback(void* context) {
furi_assert(context);
CameraSuite* app = context;
scene_manager_handle_tick_event(app->scene_manager);
}
//leave app if back button pressed
bool camera_suite_navigation_event_callback(void* context) {
furi_assert(context);
CameraSuite* app = context;
return scene_manager_handle_back_event(app->scene_manager);
}
CameraSuite* camera_suite_app_alloc() {
CameraSuite* app = malloc(sizeof(CameraSuite));
app->gui = furi_record_open(RECORD_GUI);
app->notification = furi_record_open(RECORD_NOTIFICATION);
//Turn backlight on, believe me this makes testing your app easier
notification_message(app->notification, &sequence_display_backlight_on);
//Scene additions
app->view_dispatcher = view_dispatcher_alloc();
view_dispatcher_enable_queue(app->view_dispatcher);
app->scene_manager = scene_manager_alloc(&camera_suite_scene_handlers, app);
view_dispatcher_set_event_callback_context(app->view_dispatcher, app);
view_dispatcher_set_navigation_event_callback(
app->view_dispatcher, camera_suite_navigation_event_callback);
view_dispatcher_set_tick_event_callback(
app->view_dispatcher, camera_suite_tick_event_callback, 100);
view_dispatcher_set_custom_event_callback(
app->view_dispatcher, camera_suite_custom_event_callback);
app->submenu = submenu_alloc();
// Set defaults, in case no config loaded
app->orientation = 0; // Orientation is "portrait", zero degrees by default.
app->haptic = 1; // Haptic is on by default
app->speaker = 1; // Speaker is on by default
app->led = 1; // LED is on by default
// Load configs
camera_suite_read_settings(app);
view_dispatcher_add_view(
app->view_dispatcher, CameraSuiteViewIdMenu, submenu_get_view(app->submenu));
app->camera_suite_view_start = camera_suite_view_start_alloc();
view_dispatcher_add_view(
app->view_dispatcher,
CameraSuiteViewIdStartscreen,
camera_suite_view_start_get_view(app->camera_suite_view_start));
app->camera_suite_view_style_1 = camera_suite_view_style_1_alloc();
view_dispatcher_add_view(
app->view_dispatcher,
CameraSuiteViewIdScene1,
camera_suite_view_style_1_get_view(app->camera_suite_view_style_1));
app->camera_suite_view_style_2 = camera_suite_view_style_2_alloc();
view_dispatcher_add_view(
app->view_dispatcher,
CameraSuiteViewIdScene2,
camera_suite_view_style_2_get_view(app->camera_suite_view_style_2));
app->camera_suite_view_guide = camera_suite_view_guide_alloc();
view_dispatcher_add_view(
app->view_dispatcher,
CameraSuiteViewIdGuide,
camera_suite_view_guide_get_view(app->camera_suite_view_guide));
app->button_menu = button_menu_alloc();
app->variable_item_list = variable_item_list_alloc();
view_dispatcher_add_view(
app->view_dispatcher,
CameraSuiteViewIdSettings,
variable_item_list_get_view(app->variable_item_list));
//End Scene Additions
return app;
}
void camera_suite_app_free(CameraSuite* app) {
furi_assert(app);
// Scene manager
scene_manager_free(app->scene_manager);
// View Dispatcher
view_dispatcher_remove_view(app->view_dispatcher, CameraSuiteViewIdMenu);
view_dispatcher_remove_view(app->view_dispatcher, CameraSuiteViewIdScene1);
view_dispatcher_remove_view(app->view_dispatcher, CameraSuiteViewIdScene2);
view_dispatcher_remove_view(app->view_dispatcher, CameraSuiteViewIdGuide);
view_dispatcher_remove_view(app->view_dispatcher, CameraSuiteViewIdSettings);
submenu_free(app->submenu);
view_dispatcher_free(app->view_dispatcher);
furi_record_close(RECORD_GUI);
// Free remaining resources
camera_suite_view_start_free(app->camera_suite_view_start);
camera_suite_view_style_1_free(app->camera_suite_view_style_1);
camera_suite_view_style_2_free(app->camera_suite_view_style_2);
camera_suite_view_guide_free(app->camera_suite_view_guide);
button_menu_free(app->button_menu);
variable_item_list_free(app->variable_item_list);
app->gui = NULL;
app->notification = NULL;
//Remove whatever is left
free(app);
}
/** Main entry point for initialization. */
int32_t camera_suite_app(void* p) {
UNUSED(p);
CameraSuite* app = camera_suite_app_alloc();
view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
// Init with start scene.
scene_manager_next_scene(app->scene_manager, CameraSuiteSceneStart);
furi_hal_power_suppress_charge_enter();
view_dispatcher_run(app->view_dispatcher);
camera_suite_save_settings(app);
furi_hal_power_suppress_charge_exit();
camera_suite_app_free(app);
return 0;
}

View File

@@ -0,0 +1,71 @@
#pragma once
#include "helpers/camera_suite_storage.h"
#include "scenes/camera_suite_scene.h"
#include "views/camera_suite_view_guide.h"
#include "views/camera_suite_view_start.h"
#include "views/camera_suite_view_style_1.h"
#include "views/camera_suite_view_style_2.h"
#include <assets_icons.h>
#include <furi.h>
#include <furi_hal.h>
#include <gui/gui.h>
#include <gui/modules/button_menu.h>
#include <gui/modules/submenu.h>
#include <gui/modules/variable_item_list.h>
#include <gui/scene_manager.h>
#include <gui/view_dispatcher.h>
#include <input/input.h>
#include <notification/notification_messages.h>
#include <stdlib.h>
#define TAG "Camera Suite"
typedef struct {
Gui* gui;
NotificationApp* notification;
ViewDispatcher* view_dispatcher;
Submenu* submenu;
SceneManager* scene_manager;
VariableItemList* variable_item_list;
CameraSuiteViewStart* camera_suite_view_start;
CameraSuiteViewStyle1* camera_suite_view_style_1;
CameraSuiteViewStyle2* camera_suite_view_style_2;
CameraSuiteViewGuide* camera_suite_view_guide;
uint32_t orientation;
uint32_t haptic;
uint32_t speaker;
uint32_t led;
ButtonMenu* button_menu;
} CameraSuite;
typedef enum {
CameraSuiteViewIdStartscreen,
CameraSuiteViewIdMenu,
CameraSuiteViewIdScene1,
CameraSuiteViewIdScene2,
CameraSuiteViewIdGuide,
CameraSuiteViewIdSettings,
} CameraSuiteViewId;
typedef enum {
CameraSuiteOrientation0,
CameraSuiteOrientation90,
CameraSuiteOrientation180,
CameraSuiteOrientation270,
} CameraSuiteOrientationState;
typedef enum {
CameraSuiteHapticOff,
CameraSuiteHapticOn,
} CameraSuiteHapticState;
typedef enum {
CameraSuiteSpeakerOff,
CameraSuiteSpeakerOn,
} CameraSuiteSpeakerState;
typedef enum {
CameraSuiteLedOff,
CameraSuiteLedOn,
} CameraSuiteLedState;

View File

@@ -0,0 +1,74 @@
#pragma once
typedef enum {
// Scene events: Start menu
CameraSuiteCustomEventStartUp,
CameraSuiteCustomEventStartDown,
CameraSuiteCustomEventStartLeft,
CameraSuiteCustomEventStartRight,
CameraSuiteCustomEventStartOk,
CameraSuiteCustomEventStartBack,
// Scene events: Camera style 1
CameraSuiteCustomEventSceneStyle1Up,
CameraSuiteCustomEventSceneStyle1Down,
CameraSuiteCustomEventSceneStyle1Left,
CameraSuiteCustomEventSceneStyle1Right,
CameraSuiteCustomEventSceneStyle1Ok,
CameraSuiteCustomEventSceneStyle1Back,
// Scene events: Camera style 2
CameraSuiteCustomEventSceneStyle2Up,
CameraSuiteCustomEventSceneStyle2Down,
CameraSuiteCustomEventSceneStyle2Left,
CameraSuiteCustomEventSceneStyle2Right,
CameraSuiteCustomEventSceneStyle2Ok,
CameraSuiteCustomEventSceneStyle2Back,
// Scene events: Guide
CameraSuiteCustomEventSceneGuideUp,
CameraSuiteCustomEventSceneGuideDown,
CameraSuiteCustomEventSceneGuideLeft,
CameraSuiteCustomEventSceneGuideRight,
CameraSuiteCustomEventSceneGuideOk,
CameraSuiteCustomEventSceneGuideBack,
} CameraSuiteCustomEvent;
enum CameraSuiteCustomEventType {
// Reserve first 100 events for button types and indexes, starting from 0.
CameraSuiteCustomEventMenuVoid,
CameraSuiteCustomEventMenuSelected,
};
#pragma pack(push, 1)
typedef union {
uint32_t packed_value;
struct {
uint16_t type;
int16_t value;
} content;
} CameraSuiteCustomEventMenu;
#pragma pack(pop)
static inline uint32_t camera_suite_custom_menu_event_pack(uint16_t type, int16_t value) {
CameraSuiteCustomEventMenu event = {.content = {.type = type, .value = value}};
return event.packed_value;
}
static inline void
camera_suite_custom_menu_event_unpack(uint32_t packed_value, uint16_t* type, int16_t* value) {
CameraSuiteCustomEventMenu event = {.packed_value = packed_value};
if(type) *type = event.content.type;
if(value) *value = event.content.value;
}
static inline uint16_t camera_suite_custom_menu_event_get_type(uint32_t packed_value) {
uint16_t type;
camera_suite_custom_menu_event_unpack(packed_value, &type, NULL);
return type;
}
static inline int16_t camera_suite_custom_menu_event_get_value(uint32_t packed_value) {
int16_t value;
camera_suite_custom_menu_event_unpack(packed_value, NULL, &value);
return value;
}

View File

@@ -0,0 +1,35 @@
#include "camera_suite_haptic.h"
#include "../camera_suite.h"
void camera_suite_play_happy_bump(void* context) {
CameraSuite* app = context;
if(app->haptic != 1) {
return;
}
notification_message(app->notification, &sequence_set_vibro_on);
furi_thread_flags_wait(0, FuriFlagWaitAny, 20);
notification_message(app->notification, &sequence_reset_vibro);
}
void camera_suite_play_bad_bump(void* context) {
CameraSuite* app = context;
if(app->haptic != 1) {
return;
}
notification_message(app->notification, &sequence_set_vibro_on);
furi_thread_flags_wait(0, FuriFlagWaitAny, 100);
notification_message(app->notification, &sequence_reset_vibro);
}
void camera_suite_play_long_bump(void* context) {
CameraSuite* app = context;
if(app->haptic != 1) {
return;
}
for(int i = 0; i < 4; i++) {
notification_message(app->notification, &sequence_set_vibro_on);
furi_thread_flags_wait(0, FuriFlagWaitAny, 50);
notification_message(app->notification, &sequence_reset_vibro);
furi_thread_flags_wait(0, FuriFlagWaitAny, 100);
}
}

View File

@@ -0,0 +1,7 @@
#include <notification/notification_messages.h>
void camera_suite_play_happy_bump(void* context);
void camera_suite_play_bad_bump(void* context);
void camera_suite_play_long_bump(void* context);

View File

@@ -0,0 +1,38 @@
#include "camera_suite_led.h"
#include "../camera_suite.h"
void camera_suite_led_set_rgb(void* context, int red, int green, int blue) {
CameraSuite* app = context;
if(app->led != 1) {
return;
}
NotificationMessage notification_led_message_1;
notification_led_message_1.type = NotificationMessageTypeLedRed;
NotificationMessage notification_led_message_2;
notification_led_message_2.type = NotificationMessageTypeLedGreen;
NotificationMessage notification_led_message_3;
notification_led_message_3.type = NotificationMessageTypeLedBlue;
notification_led_message_1.data.led.value = red;
notification_led_message_2.data.led.value = green;
notification_led_message_3.data.led.value = blue;
const NotificationSequence notification_sequence = {
&notification_led_message_1,
&notification_led_message_2,
&notification_led_message_3,
&message_do_not_reset,
NULL,
};
notification_message(app->notification, &notification_sequence);
//Delay, prevent removal from RAM before LED value set.
furi_thread_flags_wait(0, FuriFlagWaitAny, 10);
}
void camera_suite_led_reset(void* context) {
CameraSuite* app = context;
notification_message(app->notification, &sequence_reset_red);
notification_message(app->notification, &sequence_reset_green);
notification_message(app->notification, &sequence_reset_blue);
//Delay, prevent removal from RAM before LED value set.
furi_thread_flags_wait(0, FuriFlagWaitAny, 300);
}

View File

@@ -0,0 +1,3 @@
void camera_suite_led_set_rgb(void* context, int red, int green, int blue);
void camera_suite_led_reset(void* context);

View File

@@ -0,0 +1,26 @@
#include "camera_suite_speaker.h"
#include "../camera_suite.h"
#define NOTE_INPUT 587.33f
void camera_suite_play_input_sound(void* context) {
CameraSuite* app = context;
if(app->speaker != 1) {
return;
}
float volume = 1.0f;
if(furi_hal_speaker_is_mine() || furi_hal_speaker_acquire(30)) {
furi_hal_speaker_start(NOTE_INPUT, volume);
}
}
void camera_suite_stop_all_sound(void* context) {
CameraSuite* app = context;
if(app->speaker != 1) {
return;
}
if(furi_hal_speaker_is_mine()) {
furi_hal_speaker_stop();
furi_hal_speaker_release();
}
}

View File

@@ -0,0 +1,5 @@
#define NOTE_INPUT 587.33f
void camera_suite_play_input_sound(void* context);
void camera_suite_stop_all_sound(void* context);

View File

@@ -0,0 +1,113 @@
#include "camera_suite_storage.h"
static Storage* camera_suite_open_storage() {
return furi_record_open(RECORD_STORAGE);
}
static void camera_suite_close_storage() {
furi_record_close(RECORD_STORAGE);
}
static void camera_suite_close_config_file(FlipperFormat* file) {
if(file == NULL) return;
flipper_format_file_close(file);
flipper_format_free(file);
}
void camera_suite_save_settings(void* context) {
CameraSuite* app = context;
FURI_LOG_D(TAG, "Saving Settings");
Storage* storage = camera_suite_open_storage();
FlipperFormat* fff_file = flipper_format_file_alloc(storage);
// Overwrite wont work, so delete first
if(storage_file_exists(storage, BOILERPLATE_SETTINGS_SAVE_PATH)) {
storage_simply_remove(storage, BOILERPLATE_SETTINGS_SAVE_PATH);
}
// Open File, create if not exists
if(!storage_common_stat(storage, BOILERPLATE_SETTINGS_SAVE_PATH, NULL) == FSE_OK) {
FURI_LOG_D(
TAG, "Config file %s is not found. Will create new.", BOILERPLATE_SETTINGS_SAVE_PATH);
if(storage_common_stat(storage, CONFIG_FILE_DIRECTORY_PATH, NULL) == FSE_NOT_EXIST) {
FURI_LOG_D(
TAG, "Directory %s doesn't exist. Will create new.", CONFIG_FILE_DIRECTORY_PATH);
if(!storage_simply_mkdir(storage, CONFIG_FILE_DIRECTORY_PATH)) {
FURI_LOG_E(TAG, "Error creating directory %s", CONFIG_FILE_DIRECTORY_PATH);
}
}
}
if(!flipper_format_file_open_new(fff_file, BOILERPLATE_SETTINGS_SAVE_PATH)) {
//totp_close_config_file(fff_file);
FURI_LOG_E(TAG, "Error creating new file %s", BOILERPLATE_SETTINGS_SAVE_PATH);
camera_suite_close_storage();
return;
}
// Store Settings
flipper_format_write_header_cstr(
fff_file, BOILERPLATE_SETTINGS_HEADER, BOILERPLATE_SETTINGS_FILE_VERSION);
flipper_format_write_uint32(
fff_file, BOILERPLATE_SETTINGS_KEY_ORIENTATION, &app->orientation, 1);
flipper_format_write_uint32(fff_file, BOILERPLATE_SETTINGS_KEY_HAPTIC, &app->haptic, 1);
flipper_format_write_uint32(fff_file, BOILERPLATE_SETTINGS_KEY_SPEAKER, &app->speaker, 1);
flipper_format_write_uint32(fff_file, BOILERPLATE_SETTINGS_KEY_LED, &app->led, 1);
if(!flipper_format_rewind(fff_file)) {
camera_suite_close_config_file(fff_file);
FURI_LOG_E(TAG, "Rewind error");
camera_suite_close_storage();
return;
}
camera_suite_close_config_file(fff_file);
camera_suite_close_storage();
}
void camera_suite_read_settings(void* context) {
CameraSuite* app = context;
Storage* storage = camera_suite_open_storage();
FlipperFormat* fff_file = flipper_format_file_alloc(storage);
if(storage_common_stat(storage, BOILERPLATE_SETTINGS_SAVE_PATH, NULL) != FSE_OK) {
camera_suite_close_config_file(fff_file);
camera_suite_close_storage();
return;
}
uint32_t file_version;
FuriString* temp_str = furi_string_alloc();
if(!flipper_format_file_open_existing(fff_file, BOILERPLATE_SETTINGS_SAVE_PATH)) {
FURI_LOG_E(TAG, "Cannot open file %s", BOILERPLATE_SETTINGS_SAVE_PATH);
camera_suite_close_config_file(fff_file);
camera_suite_close_storage();
return;
}
if(!flipper_format_read_header(fff_file, temp_str, &file_version)) {
FURI_LOG_E(TAG, "Missing Header Data");
camera_suite_close_config_file(fff_file);
camera_suite_close_storage();
return;
}
if(file_version < BOILERPLATE_SETTINGS_FILE_VERSION) {
FURI_LOG_I(TAG, "old config version, will be removed.");
camera_suite_close_config_file(fff_file);
camera_suite_close_storage();
return;
}
flipper_format_read_uint32(
fff_file, BOILERPLATE_SETTINGS_KEY_ORIENTATION, &app->orientation, 1);
flipper_format_read_uint32(fff_file, BOILERPLATE_SETTINGS_KEY_HAPTIC, &app->haptic, 1);
flipper_format_read_uint32(fff_file, BOILERPLATE_SETTINGS_KEY_SPEAKER, &app->speaker, 1);
flipper_format_read_uint32(fff_file, BOILERPLATE_SETTINGS_KEY_LED, &app->led, 1);
flipper_format_rewind(fff_file);
camera_suite_close_config_file(fff_file);
camera_suite_close_storage();
}

View File

@@ -0,0 +1,20 @@
#include <stdlib.h>
#include <string.h>
#include <storage/storage.h>
#include <flipper_format/flipper_format_i.h>
#include "../camera_suite.h"
#define BOILERPLATE_SETTINGS_FILE_VERSION 1
#define CONFIG_FILE_DIRECTORY_PATH EXT_PATH("apps_data/camera_suite")
#define BOILERPLATE_SETTINGS_SAVE_PATH CONFIG_FILE_DIRECTORY_PATH "/camera_suite.conf"
#define BOILERPLATE_SETTINGS_SAVE_PATH_TMP BOILERPLATE_SETTINGS_SAVE_PATH ".tmp"
#define BOILERPLATE_SETTINGS_HEADER "Camera Suite Config File"
#define BOILERPLATE_SETTINGS_KEY_ORIENTATION "Orientation"
#define BOILERPLATE_SETTINGS_KEY_HAPTIC "Haptic"
#define BOILERPLATE_SETTINGS_KEY_LED "Led"
#define BOILERPLATE_SETTINGS_KEY_SPEAKER "Speaker"
#define BOILERPLATE_SETTINGS_KEY_SAVE_SETTINGS "SaveSettings"
void camera_suite_save_settings(void* context);
void camera_suite_read_settings(void* context);

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

View File

@@ -0,0 +1,30 @@
#include "camera_suite_scene.h"
// Generate scene on_enter handlers array
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_enter,
void (*const camera_suite_on_enter_handlers[])(void*) = {
#include "camera_suite_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 camera_suite_on_event_handlers[])(void* context, SceneManagerEvent event) = {
#include "camera_suite_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 camera_suite_on_exit_handlers[])(void* context) = {
#include "camera_suite_scene_config.h"
};
#undef ADD_SCENE
// Initialize scene handlers configuration structure
const SceneManagerHandlers camera_suite_scene_handlers = {
.on_enter_handlers = camera_suite_on_enter_handlers,
.on_event_handlers = camera_suite_on_event_handlers,
.on_exit_handlers = camera_suite_on_exit_handlers,
.scene_num = CameraSuiteSceneNum,
};

View File

@@ -0,0 +1,29 @@
#pragma once
#include <gui/scene_manager.h>
// Generate scene id and total number
#define ADD_SCENE(prefix, name, id) CameraSuiteScene##id,
typedef enum {
#include "camera_suite_scene_config.h"
CameraSuiteSceneNum,
} CameraSuiteScene;
#undef ADD_SCENE
extern const SceneManagerHandlers camera_suite_scene_handlers;
// Generate scene on_enter handlers declaration
#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_enter(void*);
#include "camera_suite_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 "camera_suite_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 "camera_suite_scene_config.h"
#undef ADD_SCENE

View File

@@ -0,0 +1,6 @@
ADD_SCENE(camera_suite, start, Start)
ADD_SCENE(camera_suite, menu, Menu)
ADD_SCENE(camera_suite, style_1, Style_1)
ADD_SCENE(camera_suite, style_2, Style_2)
ADD_SCENE(camera_suite, guide, Guide)
ADD_SCENE(camera_suite, settings, Settings)

View File

@@ -0,0 +1,51 @@
#include "../camera_suite.h"
#include "../helpers/camera_suite_custom_event.h"
#include "../views/camera_suite_view_guide.h"
void camera_suite_view_guide_callback(CameraSuiteCustomEvent event, void* context) {
furi_assert(context);
CameraSuite* app = context;
view_dispatcher_send_custom_event(app->view_dispatcher, event);
}
void camera_suite_scene_guide_on_enter(void* context) {
furi_assert(context);
CameraSuite* app = context;
camera_suite_view_guide_set_callback(
app->camera_suite_view_guide, camera_suite_view_guide_callback, app);
view_dispatcher_switch_to_view(app->view_dispatcher, CameraSuiteViewIdGuide);
}
bool camera_suite_scene_guide_on_event(void* context, SceneManagerEvent event) {
CameraSuite* app = context;
bool consumed = false;
if(event.type == SceneManagerEventTypeCustom) {
switch(event.event) {
case CameraSuiteCustomEventSceneGuideLeft:
case CameraSuiteCustomEventSceneGuideRight:
case CameraSuiteCustomEventSceneGuideUp:
case CameraSuiteCustomEventSceneGuideDown:
// Do nothing.
break;
case CameraSuiteCustomEventSceneGuideBack:
notification_message(app->notification, &sequence_reset_red);
notification_message(app->notification, &sequence_reset_green);
notification_message(app->notification, &sequence_reset_blue);
if(!scene_manager_search_and_switch_to_previous_scene(
app->scene_manager, CameraSuiteSceneMenu)) {
scene_manager_stop(app->scene_manager);
view_dispatcher_stop(app->view_dispatcher);
}
consumed = true;
break;
}
}
return consumed;
}
void camera_suite_scene_guide_on_exit(void* context) {
CameraSuite* app = context;
UNUSED(app);
}

View File

@@ -0,0 +1,87 @@
#include "../camera_suite.h"
enum SubmenuIndex {
/** Atkinson Dithering Algorithm. */
SubmenuIndexSceneStyle1 = 10,
/** Floyd-Steinberg Dithering Algorithm. */
SubmenuIndexSceneStyle2,
/** Guide/how-to. */
SubmenuIndexGuide,
/** Settings menu. */
SubmenuIndexSettings,
};
void camera_suite_scene_menu_submenu_callback(void* context, uint32_t index) {
CameraSuite* app = context;
view_dispatcher_send_custom_event(app->view_dispatcher, index);
}
void camera_suite_scene_menu_on_enter(void* context) {
CameraSuite* app = context;
submenu_add_item(
app->submenu,
"Open Camera",
SubmenuIndexSceneStyle1,
camera_suite_scene_menu_submenu_callback,
app);
// Staged view for the future.
// submenu_add_item(
// app->submenu,
// "Test",
// SubmenuIndexSceneStyle2,
// camera_suite_scene_menu_submenu_callback,
// app);
submenu_add_item(
app->submenu, "Guide", SubmenuIndexGuide, camera_suite_scene_menu_submenu_callback, app);
submenu_add_item(
app->submenu,
"Settings",
SubmenuIndexSettings,
camera_suite_scene_menu_submenu_callback,
app);
submenu_set_selected_item(
app->submenu, scene_manager_get_scene_state(app->scene_manager, CameraSuiteSceneMenu));
view_dispatcher_switch_to_view(app->view_dispatcher, CameraSuiteViewIdMenu);
}
bool camera_suite_scene_menu_on_event(void* context, SceneManagerEvent event) {
CameraSuite* app = context;
UNUSED(app);
if(event.type == SceneManagerEventTypeBack) {
// Exit application.
scene_manager_stop(app->scene_manager);
view_dispatcher_stop(app->view_dispatcher);
return true;
} else if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SubmenuIndexSceneStyle1) {
scene_manager_set_scene_state(
app->scene_manager, CameraSuiteSceneMenu, SubmenuIndexSceneStyle1);
scene_manager_next_scene(app->scene_manager, CameraSuiteSceneStyle_1);
return true;
} else if(event.event == SubmenuIndexSceneStyle2) {
scene_manager_set_scene_state(
app->scene_manager, CameraSuiteSceneMenu, SubmenuIndexSceneStyle2);
scene_manager_next_scene(app->scene_manager, CameraSuiteSceneStyle_2);
return true;
} else if(event.event == SubmenuIndexGuide) {
scene_manager_set_scene_state(
app->scene_manager, CameraSuiteSceneMenu, SubmenuIndexGuide);
scene_manager_next_scene(app->scene_manager, CameraSuiteSceneGuide);
return true;
} else if(event.event == SubmenuIndexSettings) {
scene_manager_set_scene_state(
app->scene_manager, CameraSuiteSceneMenu, SubmenuIndexSettings);
scene_manager_next_scene(app->scene_manager, CameraSuiteSceneSettings);
return true;
}
}
return false;
}
void camera_suite_scene_menu_on_exit(void* context) {
CameraSuite* app = context;
submenu_reset(app->submenu);
}

View File

@@ -0,0 +1,137 @@
#include "../camera_suite.h"
#include <lib/toolbox/value_index.h>
// Camera orientation, in degrees.
const char* const orientation_text[4] = {
"0",
"90",
"180",
"270",
};
const uint32_t orientation_value[4] = {
CameraSuiteOrientation0,
CameraSuiteOrientation90,
CameraSuiteOrientation180,
CameraSuiteOrientation270,
};
const char* const haptic_text[2] = {
"OFF",
"ON",
};
const uint32_t haptic_value[2] = {
CameraSuiteHapticOff,
CameraSuiteHapticOn,
};
const char* const speaker_text[2] = {
"OFF",
"ON",
};
const uint32_t speaker_value[2] = {
CameraSuiteSpeakerOff,
CameraSuiteSpeakerOn,
};
const char* const led_text[2] = {
"OFF",
"ON",
};
const uint32_t led_value[2] = {
CameraSuiteLedOff,
CameraSuiteLedOn,
};
static void camera_suite_scene_settings_set_camera_orientation(VariableItem* item) {
CameraSuite* app = variable_item_get_context(item);
uint8_t index = variable_item_get_current_value_index(item);
variable_item_set_current_value_text(item, orientation_text[index]);
app->orientation = orientation_value[index];
}
static void camera_suite_scene_settings_set_haptic(VariableItem* item) {
CameraSuite* app = variable_item_get_context(item);
uint8_t index = variable_item_get_current_value_index(item);
variable_item_set_current_value_text(item, haptic_text[index]);
app->haptic = haptic_value[index];
}
static void camera_suite_scene_settings_set_speaker(VariableItem* item) {
CameraSuite* app = variable_item_get_context(item);
uint8_t index = variable_item_get_current_value_index(item);
variable_item_set_current_value_text(item, speaker_text[index]);
app->speaker = speaker_value[index];
}
static void camera_suite_scene_settings_set_led(VariableItem* item) {
CameraSuite* app = variable_item_get_context(item);
uint8_t index = variable_item_get_current_value_index(item);
variable_item_set_current_value_text(item, led_text[index]);
app->led = led_value[index];
}
void camera_suite_scene_settings_submenu_callback(void* context, uint32_t index) {
CameraSuite* app = context;
view_dispatcher_send_custom_event(app->view_dispatcher, index);
}
void camera_suite_scene_settings_on_enter(void* context) {
CameraSuite* app = context;
VariableItem* item;
uint8_t value_index;
// Camera Orientation
item = variable_item_list_add(
app->variable_item_list,
"Orientation:",
4,
camera_suite_scene_settings_set_camera_orientation,
app);
value_index = value_index_uint32(app->orientation, orientation_value, 4);
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, orientation_text[value_index]);
// Haptic FX ON/OFF
item = variable_item_list_add(
app->variable_item_list, "Haptic FX:", 2, camera_suite_scene_settings_set_haptic, app);
value_index = value_index_uint32(app->haptic, haptic_value, 2);
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, haptic_text[value_index]);
// Sound FX ON/OFF
item = variable_item_list_add(
app->variable_item_list, "Sound FX:", 2, camera_suite_scene_settings_set_speaker, app);
value_index = value_index_uint32(app->speaker, speaker_value, 2);
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, speaker_text[value_index]);
// LED FX ON/OFF
item = variable_item_list_add(
app->variable_item_list, "LED FX:", 2, camera_suite_scene_settings_set_led, app);
value_index = value_index_uint32(app->led, led_value, 2);
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, led_text[value_index]);
view_dispatcher_switch_to_view(app->view_dispatcher, CameraSuiteViewIdSettings);
}
bool camera_suite_scene_settings_on_event(void* context, SceneManagerEvent event) {
CameraSuite* app = context;
UNUSED(app);
bool consumed = false;
if(event.type == SceneManagerEventTypeCustom) {
}
return consumed;
}
void camera_suite_scene_settings_on_exit(void* context) {
CameraSuite* app = context;
variable_item_list_set_selected_item(app->variable_item_list, 0);
variable_item_list_reset(app->variable_item_list);
}

View File

@@ -0,0 +1,55 @@
#include "../camera_suite.h"
#include "../helpers/camera_suite_custom_event.h"
#include "../views/camera_suite_view_start.h"
void camera_suite_scene_start_callback(CameraSuiteCustomEvent event, void* context) {
furi_assert(context);
CameraSuite* app = context;
view_dispatcher_send_custom_event(app->view_dispatcher, event);
}
void camera_suite_scene_start_on_enter(void* context) {
furi_assert(context);
CameraSuite* app = context;
camera_suite_view_start_set_callback(
app->camera_suite_view_start, camera_suite_scene_start_callback, app);
view_dispatcher_switch_to_view(app->view_dispatcher, CameraSuiteViewIdStartscreen);
}
bool camera_suite_scene_start_on_event(void* context, SceneManagerEvent event) {
CameraSuite* app = context;
bool consumed = false;
if(event.type == SceneManagerEventTypeCustom) {
switch(event.event) {
case CameraSuiteCustomEventStartLeft:
case CameraSuiteCustomEventStartRight:
break;
case CameraSuiteCustomEventStartUp:
case CameraSuiteCustomEventStartDown:
break;
case CameraSuiteCustomEventStartOk:
scene_manager_next_scene(app->scene_manager, CameraSuiteSceneMenu);
consumed = true;
break;
case CameraSuiteCustomEventStartBack:
notification_message(app->notification, &sequence_reset_red);
notification_message(app->notification, &sequence_reset_green);
notification_message(app->notification, &sequence_reset_blue);
if(!scene_manager_search_and_switch_to_previous_scene(
app->scene_manager, CameraSuiteSceneStart)) {
scene_manager_stop(app->scene_manager);
view_dispatcher_stop(app->view_dispatcher);
}
consumed = true;
break;
}
}
return consumed;
}
void camera_suite_scene_start_on_exit(void* context) {
CameraSuite* app = context;
UNUSED(app);
}

View File

@@ -0,0 +1,52 @@
#include "../camera_suite.h"
#include "../helpers/camera_suite_custom_event.h"
#include "../views/camera_suite_view_style_1.h"
static void camera_suite_view_style_1_callback(CameraSuiteCustomEvent event, void* context) {
furi_assert(context);
CameraSuite* app = context;
view_dispatcher_send_custom_event(app->view_dispatcher, event);
}
void camera_suite_scene_style_1_on_enter(void* context) {
furi_assert(context);
CameraSuite* app = context;
camera_suite_view_style_1_set_callback(
app->camera_suite_view_style_1, camera_suite_view_style_1_callback, app);
view_dispatcher_switch_to_view(app->view_dispatcher, CameraSuiteViewIdScene1);
}
bool camera_suite_scene_style_1_on_event(void* context, SceneManagerEvent event) {
CameraSuite* app = context;
bool consumed = false;
if(event.type == SceneManagerEventTypeCustom) {
switch(event.event) {
case CameraSuiteCustomEventSceneStyle1Left:
case CameraSuiteCustomEventSceneStyle1Right:
case CameraSuiteCustomEventSceneStyle1Up:
case CameraSuiteCustomEventSceneStyle1Down:
case CameraSuiteCustomEventSceneStyle1Ok:
// Do nothing.
break;
case CameraSuiteCustomEventSceneStyle1Back:
notification_message(app->notification, &sequence_reset_red);
notification_message(app->notification, &sequence_reset_green);
notification_message(app->notification, &sequence_reset_blue);
if(!scene_manager_search_and_switch_to_previous_scene(
app->scene_manager, CameraSuiteSceneMenu)) {
scene_manager_stop(app->scene_manager);
view_dispatcher_stop(app->view_dispatcher);
}
consumed = true;
break;
}
}
return consumed;
}
void camera_suite_scene_style_1_on_exit(void* context) {
CameraSuite* app = context;
UNUSED(app);
}

View File

@@ -0,0 +1,54 @@
#include "../camera_suite.h"
#include "../helpers/camera_suite_custom_event.h"
#include "../helpers/camera_suite_haptic.h"
#include "../helpers/camera_suite_led.h"
#include "../views/camera_suite_view_style_2.h"
void camera_suite_view_style_2_callback(CameraSuiteCustomEvent event, void* context) {
furi_assert(context);
CameraSuite* app = context;
view_dispatcher_send_custom_event(app->view_dispatcher, event);
}
void camera_suite_scene_style_2_on_enter(void* context) {
furi_assert(context);
CameraSuite* app = context;
camera_suite_view_style_2_set_callback(
app->camera_suite_view_style_2, camera_suite_view_style_2_callback, app);
view_dispatcher_switch_to_view(app->view_dispatcher, CameraSuiteViewIdScene2);
}
bool camera_suite_scene_style_2_on_event(void* context, SceneManagerEvent event) {
CameraSuite* app = context;
bool consumed = false;
if(event.type == SceneManagerEventTypeCustom) {
switch(event.event) {
case CameraSuiteCustomEventSceneStyle2Left:
case CameraSuiteCustomEventSceneStyle2Right:
case CameraSuiteCustomEventSceneStyle2Up:
case CameraSuiteCustomEventSceneStyle2Down:
case CameraSuiteCustomEventSceneStyle2Ok:
// Do nothing.
break;
case CameraSuiteCustomEventSceneStyle2Back:
notification_message(app->notification, &sequence_reset_red);
notification_message(app->notification, &sequence_reset_green);
notification_message(app->notification, &sequence_reset_blue);
if(!scene_manager_search_and_switch_to_previous_scene(
app->scene_manager, CameraSuiteSceneMenu)) {
scene_manager_stop(app->scene_manager);
view_dispatcher_stop(app->view_dispatcher);
}
consumed = true;
break;
}
}
return consumed;
}
void camera_suite_scene_style_2_on_exit(void* context) {
CameraSuite* app = context;
UNUSED(app);
}

View File

@@ -0,0 +1,120 @@
#include "../camera_suite.h"
#include <furi.h>
#include <furi_hal.h>
#include <input/input.h>
#include <gui/elements.h>
#include <dolphin/dolphin.h>
struct CameraSuiteViewGuide {
View* view;
CameraSuiteViewGuideCallback callback;
void* context;
};
typedef struct {
int some_value;
} CameraSuiteViewGuideModel;
void camera_suite_view_guide_set_callback(
CameraSuiteViewGuide* instance,
CameraSuiteViewGuideCallback callback,
void* context) {
furi_assert(instance);
furi_assert(callback);
instance->callback = callback;
instance->context = context;
}
void camera_suite_view_guide_draw(Canvas* canvas, CameraSuiteViewGuideModel* model) {
UNUSED(model);
canvas_clear(canvas);
canvas_set_color(canvas, ColorBlack);
canvas_set_font(canvas, FontPrimary);
canvas_draw_str_aligned(canvas, 0, 0, AlignLeft, AlignTop, "Guide");
canvas_set_font(canvas, FontSecondary);
canvas_draw_str_aligned(canvas, 0, 12, AlignLeft, AlignTop, "Left = Toggle Invert");
canvas_draw_str_aligned(canvas, 0, 22, AlignLeft, AlignTop, "Right = Toggle Dithering");
canvas_draw_str_aligned(canvas, 0, 32, AlignLeft, AlignTop, "Up = Contrast Up");
canvas_draw_str_aligned(canvas, 0, 42, AlignLeft, AlignTop, "Down = Contrast Down");
// TODO: Possibly update to take picture instead.
canvas_draw_str_aligned(canvas, 0, 52, AlignLeft, AlignTop, "Center = Toggle Dither Type");
}
static void camera_suite_view_guide_model_init(CameraSuiteViewGuideModel* const model) {
model->some_value = 1;
}
bool camera_suite_view_guide_input(InputEvent* event, void* context) {
furi_assert(context);
CameraSuiteViewGuide* instance = context;
if(event->type == InputTypeRelease) {
switch(event->key) {
case InputKeyBack:
with_view_model(
instance->view,
CameraSuiteViewGuideModel * model,
{
UNUSED(model);
instance->callback(CameraSuiteCustomEventSceneGuideBack, instance->context);
},
true);
break;
case InputKeyLeft:
case InputKeyRight:
case InputKeyUp:
case InputKeyDown:
case InputKeyOk:
case InputKeyMAX:
// Do nothing.
break;
}
}
return true;
}
void camera_suite_view_guide_exit(void* context) {
furi_assert(context);
}
void camera_suite_view_guide_enter(void* context) {
furi_assert(context);
CameraSuiteViewGuide* instance = (CameraSuiteViewGuide*)context;
with_view_model(
instance->view,
CameraSuiteViewGuideModel * model,
{ camera_suite_view_guide_model_init(model); },
true);
}
CameraSuiteViewGuide* camera_suite_view_guide_alloc() {
CameraSuiteViewGuide* instance = malloc(sizeof(CameraSuiteViewGuide));
instance->view = view_alloc();
view_allocate_model(instance->view, ViewModelTypeLocking, sizeof(CameraSuiteViewGuideModel));
view_set_context(instance->view, instance); // furi_assert crashes in events without this
view_set_draw_callback(instance->view, (ViewDrawCallback)camera_suite_view_guide_draw);
view_set_input_callback(instance->view, camera_suite_view_guide_input);
view_set_enter_callback(instance->view, camera_suite_view_guide_enter);
view_set_exit_callback(instance->view, camera_suite_view_guide_exit);
with_view_model(
instance->view,
CameraSuiteViewGuideModel * model,
{ camera_suite_view_guide_model_init(model); },
true);
return instance;
}
void camera_suite_view_guide_free(CameraSuiteViewGuide* instance) {
furi_assert(instance);
with_view_model(
instance->view, CameraSuiteViewGuideModel * model, { UNUSED(model); }, true);
view_free(instance->view);
free(instance);
}
View* camera_suite_view_guide_get_view(CameraSuiteViewGuide* instance) {
furi_assert(instance);
return instance->view;
}

View File

@@ -0,0 +1,19 @@
#pragma once
#include <gui/view.h>
#include "../helpers/camera_suite_custom_event.h"
typedef struct CameraSuiteViewGuide CameraSuiteViewGuide;
typedef void (*CameraSuiteViewGuideCallback)(CameraSuiteCustomEvent event, void* context);
void camera_suite_view_guide_set_callback(
CameraSuiteViewGuide* camera_suite_view_guide,
CameraSuiteViewGuideCallback callback,
void* context);
View* camera_suite_view_guide_get_view(CameraSuiteViewGuide* camera_suite_static);
CameraSuiteViewGuide* camera_suite_view_guide_alloc();
void camera_suite_view_guide_free(CameraSuiteViewGuide* camera_suite_static);

View File

@@ -0,0 +1,126 @@
#include "../camera_suite.h"
#include <furi.h>
#include <furi_hal.h>
#include <input/input.h>
#include <gui/elements.h>
struct CameraSuiteViewStart {
View* view;
CameraSuiteViewStartCallback callback;
void* context;
};
typedef struct {
int some_value;
} CameraSuiteViewStartModel;
void camera_suite_view_start_set_callback(
CameraSuiteViewStart* instance,
CameraSuiteViewStartCallback callback,
void* context) {
furi_assert(instance);
furi_assert(callback);
instance->callback = callback;
instance->context = context;
}
void camera_suite_view_start_draw(Canvas* canvas, CameraSuiteViewStartModel* model) {
UNUSED(model);
canvas_clear(canvas);
canvas_set_color(canvas, ColorBlack);
canvas_set_font(canvas, FontPrimary);
canvas_draw_str_aligned(canvas, 64, 10, AlignCenter, AlignTop, "Camera Suite");
canvas_set_font(canvas, FontSecondary);
canvas_draw_str_aligned(canvas, 64, 22, AlignCenter, AlignTop, "Flipper Zero");
canvas_draw_str_aligned(canvas, 64, 32, AlignCenter, AlignTop, "ESP32 CAM");
elements_button_center(canvas, "Start");
}
static void camera_suite_view_start_model_init(CameraSuiteViewStartModel* const model) {
model->some_value = 1;
}
bool camera_suite_view_start_input(InputEvent* event, void* context) {
furi_assert(context);
CameraSuiteViewStart* instance = context;
if(event->type == InputTypeRelease) {
switch(event->key) {
case InputKeyBack:
// Exit application.
with_view_model(
instance->view,
CameraSuiteViewStartModel * model,
{
UNUSED(model);
instance->callback(CameraSuiteCustomEventStartBack, instance->context);
},
true);
break;
case InputKeyOk:
// Start the application.
with_view_model(
instance->view,
CameraSuiteViewStartModel * model,
{
UNUSED(model);
instance->callback(CameraSuiteCustomEventStartOk, instance->context);
},
true);
break;
case InputKeyMAX:
case InputKeyLeft:
case InputKeyRight:
case InputKeyUp:
case InputKeyDown:
// Do nothing.
break;
}
}
return true;
}
void camera_suite_view_start_exit(void* context) {
furi_assert(context);
}
void camera_suite_view_start_enter(void* context) {
furi_assert(context);
CameraSuiteViewStart* instance = (CameraSuiteViewStart*)context;
with_view_model(
instance->view,
CameraSuiteViewStartModel * model,
{ camera_suite_view_start_model_init(model); },
true);
}
CameraSuiteViewStart* camera_suite_view_start_alloc() {
CameraSuiteViewStart* instance = malloc(sizeof(CameraSuiteViewStart));
instance->view = view_alloc();
view_allocate_model(instance->view, ViewModelTypeLocking, sizeof(CameraSuiteViewStartModel));
// furi_assert crashes in events without this
view_set_context(instance->view, instance);
view_set_draw_callback(instance->view, (ViewDrawCallback)camera_suite_view_start_draw);
view_set_input_callback(instance->view, camera_suite_view_start_input);
with_view_model(
instance->view,
CameraSuiteViewStartModel * model,
{ camera_suite_view_start_model_init(model); },
true);
return instance;
}
void camera_suite_view_start_free(CameraSuiteViewStart* instance) {
furi_assert(instance);
with_view_model(
instance->view, CameraSuiteViewStartModel * model, { UNUSED(model); }, true);
view_free(instance->view);
free(instance);
}
View* camera_suite_view_start_get_view(CameraSuiteViewStart* instance) {
furi_assert(instance);
return instance->view;
}

View File

@@ -0,0 +1,19 @@
#pragma once
#include <gui/view.h>
#include "../helpers/camera_suite_custom_event.h"
typedef struct CameraSuiteViewStart CameraSuiteViewStart;
typedef void (*CameraSuiteViewStartCallback)(CameraSuiteCustomEvent event, void* context);
void camera_suite_view_start_set_callback(
CameraSuiteViewStart* camera_suite_view_start,
CameraSuiteViewStartCallback callback,
void* context);
View* camera_suite_view_start_get_view(CameraSuiteViewStart* camera_suite_static);
CameraSuiteViewStart* camera_suite_view_start_alloc();
void camera_suite_view_start_free(CameraSuiteViewStart* camera_suite_static);

View File

@@ -0,0 +1,401 @@
#include "../camera_suite.h"
#include <furi.h>
#include <furi_hal.h>
#include <input/input.h>
#include <gui/elements.h>
#include <dolphin/dolphin.h>
#include "../helpers/camera_suite_haptic.h"
#include "../helpers/camera_suite_speaker.h"
#include "../helpers/camera_suite_led.h"
static CameraSuiteViewStyle1* current_instance = NULL;
// Dithering type:
// 0 = Floyd Steinberg (default)
// 1 = Atkinson
static int current_dithering = 0;
struct CameraSuiteViewStyle1 {
CameraSuiteViewStyle1Callback callback;
FuriStreamBuffer* rx_stream;
FuriThread* worker_thread;
View* view;
void* context;
};
void camera_suite_view_style_1_set_callback(
CameraSuiteViewStyle1* instance,
CameraSuiteViewStyle1Callback callback,
void* context) {
furi_assert(instance);
furi_assert(callback);
instance->callback = callback;
instance->context = context;
}
static void camera_suite_view_style_1_draw(Canvas* canvas, UartDumpModel* model) {
// Clear the screen.
canvas_set_color(canvas, ColorBlack);
// Draw the frame.
canvas_draw_frame(canvas, 0, 0, FRAME_WIDTH, FRAME_HEIGHT);
CameraSuite* app = current_instance->context;
// Draw the pixels with rotation.
for(size_t p = 0; p < FRAME_BUFFER_LENGTH; ++p) {
uint8_t x = p % ROW_BUFFER_LENGTH; // 0 .. 15
uint8_t y = p / ROW_BUFFER_LENGTH; // 0 .. 63
// Apply rotation
int16_t rotated_x, rotated_y;
switch(app->orientation) {
case 1: // 90 degrees
rotated_x = y;
rotated_y = FRAME_WIDTH - 1 - x;
break;
case 2: // 180 degrees
rotated_x = FRAME_WIDTH - 1 - x;
rotated_y = FRAME_HEIGHT - 1 - y;
break;
case 3: // 270 degrees
rotated_x = FRAME_HEIGHT - 1 - y;
rotated_y = x;
break;
case 0: // 0 degrees
default:
rotated_x = x;
rotated_y = y;
break;
}
for(uint8_t i = 0; i < 8; ++i) {
if((model->pixels[p] & (1 << i)) != 0) {
// Adjust the coordinates based on the new screen dimensions
uint16_t screen_x, screen_y;
switch(app->orientation) {
case 1: // 90 degrees
screen_x = rotated_x;
screen_y = FRAME_HEIGHT - 8 + (rotated_y * 8) + i;
break;
case 2: // 180 degrees
screen_x = FRAME_WIDTH - 8 + (rotated_x * 8) + i;
screen_y = FRAME_HEIGHT - 1 - rotated_y;
break;
case 3: // 270 degrees
screen_x = FRAME_WIDTH - 1 - rotated_x;
screen_y = rotated_y * 8 + i;
break;
case 0: // 0 degrees
default:
screen_x = rotated_x * 8 + i;
screen_y = rotated_y;
break;
}
canvas_draw_dot(canvas, screen_x, screen_y);
}
}
}
// Draw the guide if the camera is not initialized.
if(!model->initialized) {
canvas_draw_icon(canvas, 74, 16, &I_DolphinCommon_56x48);
canvas_set_font(canvas, FontSecondary);
canvas_draw_str(canvas, 8, 12, "Connect the ESP32-CAM");
canvas_draw_str(canvas, 20, 24, "VCC - 3V3");
canvas_draw_str(canvas, 20, 34, "GND - GND");
canvas_draw_str(canvas, 20, 44, "U0R - TX");
canvas_draw_str(canvas, 20, 54, "U0T - RX");
}
}
static void camera_suite_view_style_1_model_init(UartDumpModel* const model) {
for(size_t i = 0; i < FRAME_BUFFER_LENGTH; i++) {
model->pixels[i] = 0;
}
}
static bool camera_suite_view_style_1_input(InputEvent* event, void* context) {
furi_assert(context);
CameraSuiteViewStyle1* instance = context;
if(event->type == InputTypeRelease) {
switch(event->key) {
default: // Stop all sounds, reset the LED.
with_view_model(
instance->view,
UartDumpModel * model,
{
UNUSED(model);
camera_suite_play_bad_bump(instance->context);
camera_suite_stop_all_sound(instance->context);
camera_suite_led_set_rgb(instance->context, 0, 0, 0);
},
true);
break;
}
// Send `data` to the ESP32-CAM
} else if(event->type == InputTypePress) {
uint8_t data[1];
switch(event->key) {
case InputKeyBack:
// Stop the camera stream.
data[0] = 's';
// Go back to the main menu.
with_view_model(
instance->view,
UartDumpModel * model,
{
UNUSED(model);
instance->callback(CameraSuiteCustomEventSceneStyle1Back, instance->context);
},
true);
break;
case InputKeyLeft:
// Camera: Invert.
data[0] = '<';
with_view_model(
instance->view,
UartDumpModel * model,
{
UNUSED(model);
camera_suite_play_happy_bump(instance->context);
camera_suite_play_input_sound(instance->context);
camera_suite_led_set_rgb(instance->context, 0, 0, 255);
instance->callback(CameraSuiteCustomEventSceneStyle1Left, instance->context);
},
true);
break;
case InputKeyRight:
// Camera: Enable/disable dithering.
data[0] = '>';
with_view_model(
instance->view,
UartDumpModel * model,
{
UNUSED(model);
camera_suite_play_happy_bump(instance->context);
camera_suite_play_input_sound(instance->context);
camera_suite_led_set_rgb(instance->context, 0, 0, 255);
instance->callback(CameraSuiteCustomEventSceneStyle1Right, instance->context);
},
true);
break;
case InputKeyUp:
// Camera: Increase contrast.
data[0] = 'C';
with_view_model(
instance->view,
UartDumpModel * model,
{
UNUSED(model);
camera_suite_play_happy_bump(instance->context);
camera_suite_play_input_sound(instance->context);
camera_suite_led_set_rgb(instance->context, 0, 0, 255);
instance->callback(CameraSuiteCustomEventSceneStyle1Up, instance->context);
},
true);
break;
case InputKeyDown:
// Camera: Reduce contrast.
data[0] = 'c';
with_view_model(
instance->view,
UartDumpModel * model,
{
UNUSED(model);
camera_suite_play_happy_bump(instance->context);
camera_suite_play_input_sound(instance->context);
camera_suite_led_set_rgb(instance->context, 0, 0, 255);
instance->callback(CameraSuiteCustomEventSceneStyle1Down, instance->context);
},
true);
break;
case InputKeyOk:
if(current_dithering == 0) {
data[0] = 'd'; // Update to Floyd Steinberg dithering.
current_dithering = 1;
} else {
data[0] = 'D'; // Update to Atkinson dithering.
current_dithering = 0;
}
with_view_model(
instance->view,
UartDumpModel * model,
{
UNUSED(model);
camera_suite_play_happy_bump(instance->context);
camera_suite_play_input_sound(instance->context);
camera_suite_led_set_rgb(instance->context, 0, 0, 255);
instance->callback(CameraSuiteCustomEventSceneStyle1Ok, instance->context);
},
true);
break;
case InputKeyMAX:
break;
}
// Send `data` to the ESP32-CAM
furi_hal_uart_tx(FuriHalUartIdUSART1, data, 1);
}
return true;
}
static void camera_suite_view_style_1_exit(void* context) {
furi_assert(context);
}
static void camera_suite_view_style_1_enter(void* context) {
// Check `context` for null. If it is null, abort program, else continue.
furi_assert(context);
// Cast `context` to `CameraSuiteViewStyle1*` and store it in `instance`.
CameraSuiteViewStyle1* instance = (CameraSuiteViewStyle1*)context;
// Assign the current instance to the global variable
current_instance = instance;
uint8_t data[1];
data[0] = 'S'; // Uppercase `S` to start the camera
// Send `data` to the ESP32-CAM
furi_hal_uart_tx(FuriHalUartIdUSART1, data, 1);
with_view_model(
instance->view,
UartDumpModel * model,
{ camera_suite_view_style_1_model_init(model); },
true);
}
static void camera_on_irq_cb(UartIrqEvent uartIrqEvent, uint8_t data, void* context) {
// Check `context` for null. If it is null, abort program, else continue.
furi_assert(context);
// Cast `context` to `CameraSuiteViewStyle1*` and store it in `instance`.
CameraSuiteViewStyle1* instance = context;
// If `uartIrqEvent` is `UartIrqEventRXNE`, send the data to the
// `rx_stream` and set the `WorkerEventRx` flag.
if(uartIrqEvent == UartIrqEventRXNE) {
furi_stream_buffer_send(instance->rx_stream, &data, 1, 0);
furi_thread_flags_set(furi_thread_get_id(instance->worker_thread), WorkerEventRx);
}
}
static void process_ringbuffer(UartDumpModel* model, uint8_t byte) {
// First char has to be 'Y' in the buffer.
if(model->ringbuffer_index == 0 && byte != 'Y') {
return;
}
// Second char has to be ':' in the buffer or reset.
if(model->ringbuffer_index == 1 && byte != ':') {
model->ringbuffer_index = 0;
process_ringbuffer(model, byte);
return;
}
// Assign current byte to the ringbuffer.
model->row_ringbuffer[model->ringbuffer_index] = byte;
// Increment the ringbuffer index.
++model->ringbuffer_index;
// Let's wait 'till the buffer fills.
if(model->ringbuffer_index < RING_BUFFER_LENGTH) {
return;
}
// Flush the ringbuffer to the framebuffer.
model->ringbuffer_index = 0; // Reset the ringbuffer
model->initialized = true; // Established the connection successfully.
size_t row_start_index =
model->row_ringbuffer[2] * ROW_BUFFER_LENGTH; // Third char will determine the row number
if(row_start_index > LAST_ROW_INDEX) { // Failsafe
row_start_index = 0;
}
for(size_t i = 0; i < ROW_BUFFER_LENGTH; ++i) {
model->pixels[row_start_index + i] =
model->row_ringbuffer[i + 3]; // Writing the remaining 16 bytes into the frame buffer
}
}
static int32_t camera_worker(void* context) {
furi_assert(context);
CameraSuiteViewStyle1* instance = context;
while(1) {
uint32_t events =
furi_thread_flags_wait(WORKER_EVENTS_MASK, FuriFlagWaitAny, FuriWaitForever);
furi_check((events & FuriFlagError) == 0);
if(events & WorkerEventStop) {
break;
} else if(events & WorkerEventRx) {
size_t length = 0;
do {
size_t intended_data_size = 64;
uint8_t data[intended_data_size];
length =
furi_stream_buffer_receive(instance->rx_stream, data, intended_data_size, 0);
if(length > 0) {
with_view_model(
instance->view,
UartDumpModel * model,
{
for(size_t i = 0; i < length; i++) {
process_ringbuffer(model, data[i]);
}
},
false);
}
} while(length > 0);
}
}
return 0;
}
CameraSuiteViewStyle1* camera_suite_view_style_1_alloc() {
CameraSuiteViewStyle1* instance = malloc(sizeof(CameraSuiteViewStyle1));
instance->view = view_alloc();
instance->rx_stream = furi_stream_buffer_alloc(2048, 1);
// Set up views
view_allocate_model(instance->view, ViewModelTypeLocking, sizeof(UartDumpModel));
view_set_context(instance->view, instance); // furi_assert crashes in events without this
view_set_draw_callback(instance->view, (ViewDrawCallback)camera_suite_view_style_1_draw);
view_set_input_callback(instance->view, camera_suite_view_style_1_input);
view_set_enter_callback(instance->view, camera_suite_view_style_1_enter);
view_set_exit_callback(instance->view, camera_suite_view_style_1_exit);
with_view_model(
instance->view,
UartDumpModel * model,
{ camera_suite_view_style_1_model_init(model); },
true);
instance->worker_thread = furi_thread_alloc_ex("UsbUartWorker", 2048, camera_worker, instance);
furi_thread_start(instance->worker_thread);
// Enable uart listener
furi_hal_console_disable();
furi_hal_uart_set_br(FuriHalUartIdUSART1, 230400);
furi_hal_uart_set_irq_cb(FuriHalUartIdUSART1, camera_on_irq_cb, instance);
return instance;
}
void camera_suite_view_style_1_free(CameraSuiteViewStyle1* instance) {
furi_assert(instance);
with_view_model(
instance->view, UartDumpModel * model, { UNUSED(model); }, true);
view_free(instance->view);
free(instance);
}
View* camera_suite_view_style_1_get_view(CameraSuiteViewStyle1* instance) {
furi_assert(instance);
return instance->view;
}

View File

@@ -0,0 +1,60 @@
#include "../helpers/camera_suite_custom_event.h"
#include <furi.h>
#include <furi_hal.h>
#include <furi_hal_console.h>
#include <furi_hal_uart.h>
#include <gui/elements.h>
#include <gui/gui.h>
#include <gui/icon_i.h>
#include <gui/modules/dialog_ex.h>
#include <gui/view.h>
#include <gui/view_dispatcher.h>
#include <notification/notification.h>
#include <notification/notification_messages.h>
#include <storage/filesystem_api_defines.h>
#include <storage/storage.h>
#pragma once
#define FRAME_WIDTH 128
#define FRAME_HEIGHT 64
#define FRAME_BIT_DEPTH 1
#define FRAME_BUFFER_LENGTH \
(FRAME_WIDTH * FRAME_HEIGHT * FRAME_BIT_DEPTH / 8) // 128*64*1 / 8 = 1024
#define ROW_BUFFER_LENGTH (FRAME_WIDTH / 8) // 128/8 = 16
#define RING_BUFFER_LENGTH (ROW_BUFFER_LENGTH + 3) // ROW_BUFFER_LENGTH + Header => 16 + 3 = 19
#define LAST_ROW_INDEX (FRAME_BUFFER_LENGTH - ROW_BUFFER_LENGTH) // 1024 - 16 = 1008
typedef struct UartDumpModel UartDumpModel;
struct UartDumpModel {
bool initialized;
int rotation_angle;
uint8_t pixels[FRAME_BUFFER_LENGTH];
uint8_t ringbuffer_index;
uint8_t row_ringbuffer[RING_BUFFER_LENGTH];
};
typedef struct CameraSuiteViewStyle1 CameraSuiteViewStyle1;
typedef void (*CameraSuiteViewStyle1Callback)(CameraSuiteCustomEvent event, void* context);
void camera_suite_view_style_1_set_callback(
CameraSuiteViewStyle1* camera_suite_view_style_1,
CameraSuiteViewStyle1Callback callback,
void* context);
CameraSuiteViewStyle1* camera_suite_view_style_1_alloc();
void camera_suite_view_style_1_free(CameraSuiteViewStyle1* camera_suite_static);
View* camera_suite_view_style_1_get_view(CameraSuiteViewStyle1* camera_suite_static);
typedef enum {
// Reserved for StreamBuffer internal event
WorkerEventReserved = (1 << 0),
WorkerEventStop = (1 << 1),
WorkerEventRx = (1 << 2),
} WorkerEventFlags;
#define WORKER_EVENTS_MASK (WorkerEventStop | WorkerEventRx)

View File

@@ -0,0 +1,249 @@
#include "../camera_suite.h"
#include <furi.h>
#include <furi_hal.h>
#include <input/input.h>
#include <gui/elements.h>
#include <dolphin/dolphin.h>
#include "../helpers/camera_suite_haptic.h"
#include "../helpers/camera_suite_speaker.h"
#include "../helpers/camera_suite_led.h"
struct CameraSuiteViewStyle2 {
View* view;
CameraSuiteViewStyle2Callback callback;
void* context;
};
typedef struct {
int screen_text;
} CameraSuiteViewStyle2Model;
char buttonText[11][14] = {
"",
"Press Up",
"Press Down",
"Press Left",
"Press Right",
"Press Ok",
"Release Up",
"Release Down",
"Release Left",
"Release Right",
"Release Ok",
};
void camera_suite_view_style_2_set_callback(
CameraSuiteViewStyle2* instance,
CameraSuiteViewStyle2Callback callback,
void* context) {
furi_assert(instance);
furi_assert(callback);
instance->callback = callback;
instance->context = context;
}
void camera_suite_view_style_2_draw(Canvas* canvas, CameraSuiteViewStyle2Model* model) {
canvas_clear(canvas);
canvas_set_color(canvas, ColorBlack);
canvas_set_font(canvas, FontPrimary);
canvas_draw_str_aligned(canvas, 0, 10, AlignLeft, AlignTop, "Scene 2: Input Examples");
canvas_set_font(canvas, FontSecondary);
char* strInput = malloc(15);
strcpy(strInput, buttonText[model->screen_text]);
canvas_draw_str_aligned(canvas, 0, 22, AlignLeft, AlignTop, strInput);
free(strInput);
}
static void camera_suite_view_style_2_model_init(CameraSuiteViewStyle2Model* const model) {
model->screen_text = 0;
}
bool camera_suite_view_style_2_input(InputEvent* event, void* context) {
furi_assert(context);
CameraSuiteViewStyle2* instance = context;
if(event->type == InputTypeRelease) {
switch(event->key) {
case InputKeyBack:
with_view_model(
instance->view,
CameraSuiteViewStyle2Model * model,
{
UNUSED(model);
camera_suite_stop_all_sound(instance->context);
instance->callback(CameraSuiteCustomEventSceneStyle2Back, instance->context);
camera_suite_play_long_bump(instance->context);
},
true);
break;
case InputKeyUp:
with_view_model(
instance->view,
CameraSuiteViewStyle2Model * model,
{
model->screen_text = 6;
camera_suite_play_bad_bump(instance->context);
camera_suite_stop_all_sound(instance->context);
camera_suite_led_set_rgb(instance->context, 255, 0, 255);
},
true);
break;
case InputKeyDown:
with_view_model(
instance->view,
CameraSuiteViewStyle2Model * model,
{
model->screen_text = 7;
camera_suite_play_bad_bump(instance->context);
camera_suite_stop_all_sound(instance->context);
camera_suite_led_set_rgb(instance->context, 255, 255, 0);
},
true);
break;
case InputKeyLeft:
with_view_model(
instance->view,
CameraSuiteViewStyle2Model * model,
{
model->screen_text = 8;
camera_suite_play_bad_bump(instance->context);
camera_suite_stop_all_sound(instance->context);
camera_suite_led_set_rgb(instance->context, 0, 255, 255);
},
true);
break;
case InputKeyRight:
with_view_model(
instance->view,
CameraSuiteViewStyle2Model * model,
{
model->screen_text = 9;
camera_suite_play_bad_bump(instance->context);
camera_suite_stop_all_sound(instance->context);
camera_suite_led_set_rgb(instance->context, 255, 0, 0);
},
true);
break;
case InputKeyOk:
with_view_model(
instance->view,
CameraSuiteViewStyle2Model * model,
{
model->screen_text = 10;
camera_suite_play_bad_bump(instance->context);
camera_suite_stop_all_sound(instance->context);
camera_suite_led_set_rgb(instance->context, 255, 255, 255);
},
true);
break;
case InputKeyMAX:
break;
}
} else if(event->type == InputTypePress) {
switch(event->key) {
case InputKeyUp:
with_view_model(
instance->view,
CameraSuiteViewStyle2Model * model,
{
model->screen_text = 1;
camera_suite_play_happy_bump(instance->context);
camera_suite_play_input_sound(instance->context);
},
true);
break;
case InputKeyDown:
with_view_model(
instance->view,
CameraSuiteViewStyle2Model * model,
{
model->screen_text = 2;
camera_suite_play_happy_bump(instance->context);
camera_suite_play_input_sound(instance->context);
},
true);
break;
case InputKeyLeft:
with_view_model(
instance->view,
CameraSuiteViewStyle2Model * model,
{
model->screen_text = 3;
camera_suite_play_happy_bump(instance->context);
camera_suite_play_input_sound(instance->context);
},
true);
break;
case InputKeyRight:
with_view_model(
instance->view,
CameraSuiteViewStyle2Model * model,
{
model->screen_text = 4;
camera_suite_play_happy_bump(instance->context);
camera_suite_play_input_sound(instance->context);
},
true);
break;
case InputKeyOk:
with_view_model(
instance->view,
CameraSuiteViewStyle2Model * model,
{
model->screen_text = 5;
camera_suite_play_happy_bump(instance->context);
camera_suite_play_input_sound(instance->context);
},
true);
break;
case InputKeyBack:
case InputKeyMAX:
break;
}
}
return true;
}
void camera_suite_view_style_2_exit(void* context) {
furi_assert(context);
CameraSuite* app = context;
camera_suite_stop_all_sound(app);
//camera_suite_led_reset(app);
}
void camera_suite_view_style_2_enter(void* context) {
furi_assert(context);
dolphin_deed(DolphinDeedPluginStart);
}
CameraSuiteViewStyle2* camera_suite_view_style_2_alloc() {
CameraSuiteViewStyle2* instance = malloc(sizeof(CameraSuiteViewStyle2));
instance->view = view_alloc();
view_allocate_model(instance->view, ViewModelTypeLocking, sizeof(CameraSuiteViewStyle2Model));
view_set_context(instance->view, instance);
view_set_draw_callback(instance->view, (ViewDrawCallback)camera_suite_view_style_2_draw);
view_set_input_callback(instance->view, camera_suite_view_style_2_input);
//view_set_enter_callback(instance->view, camera_suite_view_style_2_enter);
view_set_exit_callback(instance->view, camera_suite_view_style_2_exit);
with_view_model(
instance->view,
CameraSuiteViewStyle2Model * model,
{ camera_suite_view_style_2_model_init(model); },
true);
return instance;
}
void camera_suite_view_style_2_free(CameraSuiteViewStyle2* instance) {
furi_assert(instance);
view_free(instance->view);
free(instance);
}
View* camera_suite_view_style_2_get_view(CameraSuiteViewStyle2* instance) {
furi_assert(instance);
return instance->view;
}

View File

@@ -0,0 +1,19 @@
#pragma once
#include <gui/view.h>
#include "../helpers/camera_suite_custom_event.h"
typedef struct CameraSuiteViewStyle2 CameraSuiteViewStyle2;
typedef void (*CameraSuiteViewStyle2Callback)(CameraSuiteCustomEvent event, void* context);
void camera_suite_view_style_2_set_callback(
CameraSuiteViewStyle2* instance,
CameraSuiteViewStyle2Callback callback,
void* context);
CameraSuiteViewStyle2* camera_suite_view_style_2_alloc();
void camera_suite_view_style_2_free(CameraSuiteViewStyle2* camera_suite_static);
View* camera_suite_view_style_2_get_view(CameraSuiteViewStyle2* boilerpate_static);

View File

@@ -1 +0,0 @@
3

View File

Before

Width:  |  Height:  |  Size: 113 B

After

Width:  |  Height:  |  Size: 113 B

View File

Before

Width:  |  Height:  |  Size: 116 B

After

Width:  |  Height:  |  Size: 116 B

View File

Before

Width:  |  Height:  |  Size: 116 B

After

Width:  |  Height:  |  Size: 116 B

View File

@@ -3,7 +3,6 @@
#include <flappy_bird_icons.h>
#include <furi.h>
#include <gui/gui.h>
#include <gui/icon_animation_i.h>
#include <input/input.h>
#define TAG "Flappy"
@@ -29,6 +28,14 @@ typedef enum {
EventTypeKey,
} EventType;
typedef enum { BirdState0 = 0, BirdState1, BirdState2, BirdStateMAX } BirdState;
const Icon* bird_states[BirdStateMAX] = {
&I_bird_01,
&I_bird_02,
&I_bird_03,
};
typedef struct {
int x;
int y;
@@ -37,7 +44,6 @@ typedef struct {
typedef struct {
float gravity;
POINT point;
IconAnimation* sprite;
} BIRD;
typedef struct {
@@ -92,7 +98,6 @@ static void flappy_game_state_init(GameState* const game_state) {
bird.gravity = 0.0f;
bird.point.x = 15;
bird.point.y = 32;
bird.sprite = icon_animation_alloc(&A_bird);
game_state->debug = DEBUG;
game_state->bird = bird;
@@ -105,7 +110,6 @@ static void flappy_game_state_init(GameState* const game_state) {
}
static void flappy_game_state_free(GameState* const game_state) {
icon_animation_free(game_state->bird.sprite);
free(game_state);
}
@@ -223,14 +227,14 @@ static void flappy_game_render_callback(Canvas* const canvas, void* ctx) {
}
// Switch animation
game_state->bird.sprite->frame = 1;
BirdState bird_state = BirdState1;
if(game_state->bird.gravity < -0.5)
game_state->bird.sprite->frame = 0;
bird_state = BirdState0;
else if(game_state->bird.gravity > 0.5)
game_state->bird.sprite->frame = 2;
bird_state = BirdState2;
canvas_draw_icon_animation(
canvas, game_state->bird.point.x, game_state->bird.point.y, game_state->bird.sprite);
canvas_draw_icon(
canvas, game_state->bird.point.x, game_state->bird.point.y, bird_states[bird_state]);
canvas_set_font(canvas, FontSecondary);
char buffer[12];

View File

@@ -0,0 +1,674 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<https://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<https://www.gnu.org/licenses/why-not-lgpl.html>.

View File

@@ -1,5 +1,5 @@
App(
appid="i2c_tools",
appid="i2ctools",
name="[I2C] Tools",
apptype=FlipperAppType.EXTERNAL,
entry_point="i2ctools_app",
@@ -10,6 +10,6 @@ App(
fap_category="GPIO",
fap_icon_assets="images",
fap_author="@NaejEL",
fap_version="1.0",
fap_version="1.1",
fap_description="Set of i2c tools",
)

View File

@@ -22,6 +22,10 @@ void i2ctools_draw_callback(Canvas* canvas, void* ctx) {
draw_sender_view(canvas, i2ctools->sender);
break;
case INFOS_VIEW:
draw_infos_view(canvas);
break;
default:
break;
}

View File

@@ -10,6 +10,7 @@
#include "views/sniffer_view.h"
#include "views/scanner_view.h"
#include "views/sender_view.h"
#include "views/infos_view.h"
// App datas
typedef struct {

Binary file not shown.

After

Width:  |  Height:  |  Size: 294 B

View File

@@ -0,0 +1,15 @@
#include "infos_view.h"
void draw_infos_view(Canvas* canvas) {
canvas_clear(canvas);
canvas_set_color(canvas, ColorBlack);
canvas_draw_rframe(canvas, 0, 0, 128, 64, 3);
canvas_set_font(canvas, FontSecondary);
canvas_draw_str_aligned(canvas, 3, 3, AlignLeft, AlignTop, "Wiring: ");
canvas_draw_str_aligned(canvas, 43, 3, AlignLeft, AlignTop, "C0->SCL");
canvas_draw_str_aligned(canvas, 43, 13, AlignLeft, AlignTop, "C1->SDA");
canvas_draw_str_aligned(canvas, 43, 23, AlignLeft, AlignTop, "GND->GND");
canvas_draw_icon(canvas, 15, 33, &I_Voltage_16x16);
canvas_draw_str_aligned(canvas, 30, 38, AlignLeft, AlignTop, "Only use 3v3 levels");
}

View File

@@ -0,0 +1,8 @@
#include <furi.h>
#include <furi_hal.h>
#include <gui/gui.h>
#include <i2ctools_icons.h>
#define INFOS_TEXT "INFOS"
void draw_infos_view(Canvas* canvas);

View File

@@ -14,6 +14,8 @@ void draw_main_view(Canvas* canvas, i2cMainView* main_view) {
canvas, SNIFF_MENU_X, SNIFF_MENU_Y, AlignLeft, AlignTop, SNIFF_MENU_TEXT);
canvas_draw_str_aligned(
canvas, SEND_MENU_X, SEND_MENU_Y, AlignLeft, AlignTop, SEND_MENU_TEXT);
canvas_draw_str_aligned(
canvas, INFOS_MENU_X, INFOS_MENU_Y, AlignLeft, AlignTop, INFOS_MENU_TEXT);
canvas_draw_rbox(canvas, 80, SCAN_MENU_Y - 2, 43, 13, 3);
canvas_set_color(canvas, ColorWhite);
canvas_draw_str_aligned(
@@ -26,6 +28,8 @@ void draw_main_view(Canvas* canvas, i2cMainView* main_view) {
canvas, SCAN_MENU_X, SCAN_MENU_Y, AlignLeft, AlignTop, SCAN_MENU_TEXT);
canvas_draw_str_aligned(
canvas, SEND_MENU_X, SEND_MENU_Y, AlignLeft, AlignTop, SEND_MENU_TEXT);
canvas_draw_str_aligned(
canvas, INFOS_MENU_X, INFOS_MENU_Y, AlignLeft, AlignTop, INFOS_MENU_TEXT);
canvas_draw_rbox(canvas, 80, SNIFF_MENU_Y - 2, 43, 13, 3);
canvas_set_color(canvas, ColorWhite);
canvas_draw_str_aligned(
@@ -38,12 +42,28 @@ void draw_main_view(Canvas* canvas, i2cMainView* main_view) {
canvas, SCAN_MENU_X, SCAN_MENU_Y, AlignLeft, AlignTop, SCAN_MENU_TEXT);
canvas_draw_str_aligned(
canvas, SNIFF_MENU_X, SNIFF_MENU_Y, AlignLeft, AlignTop, SNIFF_MENU_TEXT);
canvas_draw_str_aligned(
canvas, INFOS_MENU_X, INFOS_MENU_Y, AlignLeft, AlignTop, INFOS_MENU_TEXT);
canvas_draw_rbox(canvas, 80, SEND_MENU_Y - 2, 43, 13, 3);
canvas_set_color(canvas, ColorWhite);
canvas_draw_str_aligned(
canvas, SEND_MENU_X, SEND_MENU_Y, AlignLeft, AlignTop, SEND_MENU_TEXT);
break;
case INFOS_VIEW:
canvas_set_color(canvas, ColorBlack);
canvas_draw_str_aligned(
canvas, SCAN_MENU_X, SCAN_MENU_Y, AlignLeft, AlignTop, SCAN_MENU_TEXT);
canvas_draw_str_aligned(
canvas, SNIFF_MENU_X, SNIFF_MENU_Y, AlignLeft, AlignTop, SNIFF_MENU_TEXT);
canvas_draw_str_aligned(
canvas, SEND_MENU_X, SEND_MENU_Y, AlignLeft, AlignTop, SEND_MENU_TEXT);
canvas_draw_rbox(canvas, 80, INFOS_MENU_Y - 2, 43, 13, 3);
canvas_set_color(canvas, ColorWhite);
canvas_draw_str_aligned(
canvas, INFOS_MENU_X, INFOS_MENU_Y, AlignLeft, AlignTop, INFOS_MENU_TEXT);
break;
default:
break;
}

View File

@@ -1,21 +1,25 @@
#include <furi.h>
#include <furi_hal.h>
#include <gui/gui.h>
#include <i2c_tools_icons.h>
#include <i2ctools_icons.h>
#include <assets_icons.h>
#define APP_NAME "I2C Tools"
#define SCAN_MENU_TEXT "Scan"
#define SCAN_MENU_X 90
#define SCAN_MENU_Y 13
#define SCAN_MENU_Y 7
#define SNIFF_MENU_TEXT "Sniff"
#define SNIFF_MENU_X 90
#define SNIFF_MENU_Y 27
#define SNIFF_MENU_Y 21
#define SEND_MENU_TEXT "Send"
#define SEND_MENU_X 90
#define SEND_MENU_Y 41
#define SEND_MENU_Y 35
#define INFOS_MENU_TEXT "Infos"
#define INFOS_MENU_X 90
#define INFOS_MENU_Y 49
// Menu
typedef enum {
@@ -23,6 +27,7 @@ typedef enum {
SCAN_VIEW,
SNIFF_VIEW,
SEND_VIEW,
INFOS_VIEW,
/* Know menu Size*/
MENU_SIZE

View File

@@ -1,7 +1,7 @@
#include <furi.h>
#include <furi_hal.h>
#include <gui/gui.h>
#include <i2c_tools_icons.h>
#include <i2ctools_icons.h>
#include <assets_icons.h>
#include "../i2cscanner.h"

View File

@@ -1,7 +1,7 @@
#include <furi.h>
#include <furi_hal.h>
#include <gui/gui.h>
#include <i2c_tools_icons.h>
#include <i2ctools_icons.h>
#include <assets_icons.h>
#include "../i2csender.h"

View File

@@ -1,7 +1,7 @@
#include <furi.h>
#include <furi_hal.h>
#include <gui/gui.h>
#include <i2c_tools_icons.h>
#include <i2ctools_icons.h>
#include <assets_icons.h>
#include "../i2csniffer.h"

View File

@@ -14,7 +14,6 @@
#include <input/input.h>
#include <notification/notification.h>
#include <notification/notification_messages.h>
#include <gui/canvas_i.h>
#define Y_FIELD_SIZE 6
#define Y_LAST (Y_FIELD_SIZE - 1)

View File

@@ -10,7 +10,7 @@ App(
stack_size=2 * 1024,
order=20,
fap_icon="icons/hex_10px.png",
fap_category="Misc",
fap_category="Tools",
fap_icon_assets="icons",
fap_author="@QtRoS",
fap_version="1.0",

View File

@@ -4,7 +4,7 @@ App(
apptype=FlipperAppType.EXTERNAL,
entry_point="hid_usb_app",
stack_size=1 * 1024,
fap_category="Tools",
fap_category="USB",
fap_icon="hid_usb_10px.png",
fap_icon_assets="assets",
fap_icon_assets_symbol="hid",
@@ -17,7 +17,7 @@ App(
apptype=FlipperAppType.EXTERNAL,
entry_point="hid_ble_app",
stack_size=1 * 1024,
fap_category="Tools",
fap_category="Bluetooth",
fap_icon="hid_ble_10px.png",
fap_icon_assets="assets",
fap_icon_assets_symbol="hid",

View File

@@ -7,7 +7,7 @@ App(
requires=["gui"],
stack_size=2 * 1024,
fap_icon="ir_scope.png",
fap_category="Tools",
fap_category="Infrared",
fap_author="@kallanreed",
fap_version="1.0",
fap_description="App allows to see incoming IR signals.",

View File

@@ -13,5 +13,5 @@ App(
fap_author="AloneLiberty",
fap_description="Recover Mifare Classic keys",
fap_weburl="https://github.com/AloneLiberty/FlipperNested",
fap_version="1.5.0",
fap_version="1.5.2",
)

View File

@@ -21,7 +21,7 @@
#include <gui/modules/variable_item_list.h>
#include "mifare_nested_icons.h"
#define NESTED_VERSION_APP "1.5.0"
#define NESTED_VERSION_APP "1.5.2"
#define NESTED_GITHUB_LINK "https://github.com/AloneLiberty/FlipperNested"
#define NESTED_RECOVER_KEYS_GITHUB_LINK "https://github.com/AloneLiberty/FlipperNestedRecovery"
#define NESTED_NONCE_FORMAT_VERSION "3"

View File

@@ -478,9 +478,13 @@ SaveNoncesResult_t* mifare_nested_worker_write_nonces(
for(uint8_t sector = 0; sector < sector_count; sector++) {
for(uint8_t key_type = 0; key_type < 2; key_type++) {
if(nonces->nonces[sector][key_type][tries]->invalid) {
if(tries == 0) {
result->invalid++;
}
} else if(nonces->nonces[sector][key_type][tries]->skipped) {
if(tries == 0) {
result->skipped++;
}
} else if(nonces->nonces[sector][key_type][tries]->collected) {
if(nonces->nonces[sector][key_type][tries]->hardnested) {
FuriString* hardnested_path = furi_string_alloc();
@@ -574,6 +578,7 @@ bool mifare_nested_worker_check_initial_keys(
info->block = mifare_nested_worker_get_block_by_sector(sector);
info->collected = false;
info->skipped = true;
info->from_start = false;
nonces->nonces[sector][key_type][tries] = info;
}
@@ -591,6 +596,7 @@ bool mifare_nested_worker_check_initial_keys(
Nonces* info = nonces->nonces[sector][0][tries];
info->collected = true;
info->skipped = true;
info->from_start = true;
nonces->nonces[sector][0][tries] = info;
}
@@ -612,6 +618,7 @@ bool mifare_nested_worker_check_initial_keys(
Nonces* info = nonces->nonces[sector][1][tries];
info->collected = true;
info->skipped = true;
info->from_start = true;
nonces->nonces[sector][1][tries] = info;
}

View File

@@ -66,6 +66,7 @@ typedef struct {
uint32_t target_ks[2];
uint8_t parity[2][4];
bool skipped;
bool from_start;
bool invalid;
bool collected;
bool hardnested;

View File

@@ -18,12 +18,15 @@ bool mifare_nested_collecting_worker_callback(MifareNestedWorkerEvent event, voi
mifare_nested_blink_nonce_collection_start(mifare_nested);
uint8_t collected = 0;
uint8_t skip = 0;
NonceList_t* nonces = mifare_nested->nonces;
for(uint8_t tries = 0; tries < nonces->tries; tries++) {
for(uint8_t sector = 0; sector < nonces->sector_count; sector++) {
for(uint8_t keyType = 0; keyType < 2; keyType++) {
Nonces* info = nonces->nonces[sector][keyType][tries];
if(info->collected) {
if(info->from_start) {
skip++;
} else if(info->collected) {
collected++;
}
}
@@ -37,7 +40,7 @@ bool mifare_nested_collecting_worker_callback(MifareNestedWorkerEvent event, voi
model->calibrating = false;
model->lost_tag = false;
model->nonces_collected = collected;
model->keys_count = nonces->sector_count * nonces->tries * 2;
model->keys_count = (nonces->sector_count * nonces->tries * 2) - skip;
},
true);
} else if(event == MifareNestedWorkerEventNoTagDetected) {

View File

@@ -6,7 +6,6 @@
#include <notification/notification_messages.h>
#include <dialogs/dialogs.h>
#include <m-string.h>
#include "assets.h"

View File

@@ -7,7 +7,7 @@ App(
stack_size=1 * 1024,
order=160,
fap_icon="converter_10px.png",
fap_category="Misc",
fap_category="Tools",
fap_author="@theisolinearchip",
fap_version="1.0",
fap_description="A multi-unit converter written with an easy and expandable system for adding new units and conversion methods",

View File

@@ -12,7 +12,7 @@ App(
],
stack_size=2 * 1024,
fap_icon="ibutt_10px.png",
fap_category="Tools",
fap_category="iButton",
fap_private_libs=[
Lib(
name="worker",
@@ -37,7 +37,7 @@ App(
],
stack_size=2 * 1024,
fap_icon="icons/rfid_10px.png",
fap_category="Tools",
fap_category="RFID",
fap_private_libs=[
Lib(
name="worker",

View File

@@ -16,6 +16,7 @@ PicopassDevice* picopass_device_alloc() {
PicopassDevice* picopass_dev = malloc(sizeof(PicopassDevice));
picopass_dev->dev_data.pacs.legacy = false;
picopass_dev->dev_data.pacs.se_enabled = false;
picopass_dev->dev_data.pacs.elite_kdf = false;
picopass_dev->dev_data.pacs.pin_length = 0;
picopass_dev->storage = furi_record_open(RECORD_STORAGE);
picopass_dev->dialogs = furi_record_open(RECORD_DIALOGS);
@@ -78,6 +79,7 @@ static bool picopass_device_save_file(
break;
}
}
// TODO: Add elite
if(!flipper_format_write_comment_cstr(file, "Picopass blocks")) break;
bool block_saved = true;
@@ -260,6 +262,7 @@ void picopass_device_data_clear(PicopassDeviceData* dev_data) {
}
dev_data->pacs.legacy = false;
dev_data->pacs.se_enabled = false;
dev_data->pacs.elite_kdf = false;
dev_data->pacs.pin_length = 0;
}

View File

@@ -84,6 +84,7 @@ typedef struct {
bool sio;
bool biometrics;
uint8_t key[8];
bool elite_kdf;
uint8_t pin_length;
PicopassEncryption encryption;
uint8_t credential[8];

View File

@@ -581,6 +581,7 @@ void picopass_worker_elite_dict_attack(PicopassWorker* picopass_worker) {
if(err == ERR_NONE) {
FURI_LOG_I(TAG, "Found key");
memcpy(pacs->key, key, RFAL_PICOPASS_BLOCK_LEN);
pacs->elite_kdf = elite;
err = picopass_read_card(AA1);
if(err != ERR_NONE) {
FURI_LOG_E(TAG, "picopass_read_card error %d", err);
@@ -758,7 +759,7 @@ void picopass_worker_write_key(PicopassWorker* picopass_worker) {
uint8_t* oldKey = AA1[PICOPASS_SECURE_KD_BLOCK_INDEX].data;
uint8_t newKey[RFAL_PICOPASS_BLOCK_LEN] = {0};
loclass_iclass_calc_div_key(csn, pacs->key, newKey, false);
loclass_iclass_calc_div_key(csn, pacs->key, newKey, pacs->elite_kdf);
if((fuses & 0x80) == 0x80) {
FURI_LOG_D(TAG, "Plain write for personalized mode key change");

View File

@@ -60,24 +60,28 @@ bool picopass_scene_key_menu_on_event(void* context, SceneManagerEvent event) {
scene_manager_set_scene_state(
picopass->scene_manager, PicopassSceneKeyMenu, SubmenuIndexWriteStandard);
memcpy(picopass->dev->dev_data.pacs.key, picopass_iclass_key, RFAL_PICOPASS_BLOCK_LEN);
picopass->dev->dev_data.pacs.elite_kdf = false;
scene_manager_next_scene(picopass->scene_manager, PicopassSceneWriteKey);
consumed = true;
} else if(event.event == SubmenuIndexWriteiCE) {
scene_manager_set_scene_state(
picopass->scene_manager, PicopassSceneKeyMenu, SubmenuIndexWriteiCE);
memcpy(picopass->dev->dev_data.pacs.key, picopass_xice_key, RFAL_PICOPASS_BLOCK_LEN);
picopass->dev->dev_data.pacs.elite_kdf = true;
scene_manager_next_scene(picopass->scene_manager, PicopassSceneWriteKey);
consumed = true;
} else if(event.event == SubmenuIndexWriteiCL) {
scene_manager_set_scene_state(
picopass->scene_manager, PicopassSceneKeyMenu, SubmenuIndexWriteiCE);
picopass->scene_manager, PicopassSceneKeyMenu, SubmenuIndexWriteiCL);
memcpy(picopass->dev->dev_data.pacs.key, picopass_xicl_key, RFAL_PICOPASS_BLOCK_LEN);
picopass->dev->dev_data.pacs.elite_kdf = false;
scene_manager_next_scene(picopass->scene_manager, PicopassSceneWriteKey);
consumed = true;
} else if(event.event == SubmenuIndexWriteiCS) {
scene_manager_set_scene_state(
picopass->scene_manager, PicopassSceneKeyMenu, SubmenuIndexWriteiCE);
picopass->scene_manager, PicopassSceneKeyMenu, SubmenuIndexWriteiCS);
memcpy(picopass->dev->dev_data.pacs.key, picopass_xics_key, RFAL_PICOPASS_BLOCK_LEN);
picopass->dev->dev_data.pacs.elite_kdf = false;
scene_manager_next_scene(picopass->scene_manager, PicopassSceneWriteKey);
consumed = true;
}

View File

@@ -0,0 +1,66 @@
#include "radio_device_loader.h"
#include <applications/drivers/subghz/cc1101_ext/cc1101_ext_interconnect.h>
#include <lib/subghz/devices/cc1101_int/cc1101_int_interconnect.h>
static void radio_device_loader_power_on() {
uint8_t attempts = 0;
while(!furi_hal_power_is_otg_enabled() && attempts++ < 5) {
furi_hal_power_enable_otg();
//CC1101 power-up time
furi_delay_ms(10);
}
}
static void radio_device_loader_power_off() {
if(furi_hal_power_is_otg_enabled()) furi_hal_power_disable_otg();
}
bool radio_device_loader_is_connect_external(const char* name) {
bool is_connect = false;
bool is_otg_enabled = furi_hal_power_is_otg_enabled();
if(!is_otg_enabled) {
radio_device_loader_power_on();
}
is_connect = subghz_devices_is_connect(subghz_devices_get_by_name(name));
if(!is_otg_enabled) {
radio_device_loader_power_off();
}
return is_connect;
}
const SubGhzDevice* radio_device_loader_set(
const SubGhzDevice* current_radio_device,
SubGhzRadioDeviceType radio_device_type) {
const SubGhzDevice* radio_device;
if(radio_device_type == SubGhzRadioDeviceTypeExternalCC1101 &&
radio_device_loader_is_connect_external(SUBGHZ_DEVICE_CC1101_EXT_NAME)) {
radio_device_loader_power_on();
radio_device = subghz_devices_get_by_name(SUBGHZ_DEVICE_CC1101_EXT_NAME);
subghz_devices_begin(radio_device);
} else if(current_radio_device == NULL) {
radio_device = subghz_devices_get_by_name(SUBGHZ_DEVICE_CC1101_INT_NAME);
} else {
radio_device_loader_end(current_radio_device);
radio_device = subghz_devices_get_by_name(SUBGHZ_DEVICE_CC1101_INT_NAME);
}
return radio_device;
}
bool radio_device_loader_is_external(const SubGhzDevice* radio_device) {
furi_assert(radio_device);
return (radio_device != subghz_devices_get_by_name(SUBGHZ_DEVICE_CC1101_INT_NAME));
}
void radio_device_loader_end(const SubGhzDevice* radio_device) {
furi_assert(radio_device);
radio_device_loader_power_off();
if(radio_device != subghz_devices_get_by_name(SUBGHZ_DEVICE_CC1101_INT_NAME)) {
subghz_devices_end(radio_device);
}
}

View File

@@ -0,0 +1,17 @@
#pragma once
#include <lib/subghz/devices/devices.h>
/** SubGhzRadioDeviceType */
typedef enum {
SubGhzRadioDeviceTypeInternal,
SubGhzRadioDeviceTypeExternalCC1101,
} SubGhzRadioDeviceType;
const SubGhzDevice* radio_device_loader_set(
const SubGhzDevice* current_radio_device,
SubGhzRadioDeviceType radio_device_type);
bool radio_device_loader_is_external(const SubGhzDevice* radio_device);
void radio_device_loader_end(const SubGhzDevice* radio_device);

View File

@@ -92,6 +92,16 @@ POCSAGPagerApp* pocsag_pager_app_alloc() {
app->txrx->preset = malloc(sizeof(SubGhzRadioPreset));
app->txrx->preset->name = furi_string_alloc();
furi_hal_power_suppress_charge_enter();
// Radio Devices init & load
subghz_devices_init();
app->txrx->radio_device =
radio_device_loader_set(app->txrx->radio_device, SubGhzRadioDeviceTypeExternalCC1101);
subghz_devices_reset(app->txrx->radio_device);
subghz_devices_idle(app->txrx->radio_device);
// Custom Presets load without using config file
FlipperFormat* temp_fm_preset = flipper_format_string_alloc();
@@ -123,17 +133,6 @@ POCSAGPagerApp* pocsag_pager_app_alloc() {
app->txrx->worker, (SubGhzWorkerPairCallback)subghz_receiver_decode);
subghz_worker_set_context(app->txrx->worker, app->txrx->receiver);
// Enable power for External CC1101 if it is connected
furi_hal_subghz_enable_ext_power();
// Auto switch to internal radio if external radio is not available
furi_delay_ms(15);
if(!furi_hal_subghz_check_radio()) {
furi_hal_subghz_select_radio_type(SubGhzRadioInternal);
furi_hal_subghz_init_radio_type(SubGhzRadioInternal);
}
furi_hal_power_suppress_charge_enter();
scene_manager_next_scene(app->scene_manager, POCSAGPagerSceneStart);
return app;
@@ -142,13 +141,11 @@ POCSAGPagerApp* pocsag_pager_app_alloc() {
void pocsag_pager_app_free(POCSAGPagerApp* app) {
furi_assert(app);
//CC1101 off
// Radio Devices sleep & off
pcsg_sleep(app);
radio_device_loader_end(app->txrx->radio_device);
// Disable power for External CC1101 if it was enabled and module is connected
furi_hal_subghz_disable_ext_power();
// Reinit SPI handles for internal radio / nfc
furi_hal_subghz_init_radio_type(SubGhzRadioInternal);
subghz_devices_deinit();
// Submenu
view_dispatcher_remove_view(app->view_dispatcher, POCSAGPagerViewSubmenu);

View File

@@ -36,29 +36,34 @@ void pcsg_get_frequency_modulation(
void pcsg_begin(POCSAGPagerApp* app, uint8_t* preset_data) {
furi_assert(app);
UNUSED(preset_data);
furi_hal_subghz_reset();
furi_hal_subghz_idle();
furi_hal_subghz_load_custom_preset(preset_data);
furi_hal_gpio_init(furi_hal_subghz.cc1101_g0_pin, GpioModeInput, GpioPullNo, GpioSpeedLow);
subghz_devices_reset(app->txrx->radio_device);
subghz_devices_idle(app->txrx->radio_device);
subghz_devices_load_preset(app->txrx->radio_device, FuriHalSubGhzPresetCustom, preset_data);
// furi_hal_gpio_init(furi_hal_subghz.cc1101_g0_pin, GpioModeInput, GpioPullNo, GpioSpeedLow);
app->txrx->txrx_state = PCSGTxRxStateIDLE;
}
uint32_t pcsg_rx(POCSAGPagerApp* app, uint32_t frequency) {
furi_assert(app);
if(!furi_hal_subghz_is_frequency_valid(frequency)) {
if(!subghz_devices_is_frequency_valid(app->txrx->radio_device, frequency)) {
furi_crash("POCSAGPager: Incorrect RX frequency.");
}
furi_assert(
app->txrx->txrx_state != PCSGTxRxStateRx && app->txrx->txrx_state != PCSGTxRxStateSleep);
furi_hal_subghz_idle();
uint32_t value = furi_hal_subghz_set_frequency_and_path(frequency);
furi_hal_gpio_init(furi_hal_subghz.cc1101_g0_pin, GpioModeInput, GpioPullNo, GpioSpeedLow);
furi_hal_subghz_flush_rx();
furi_hal_subghz_rx();
subghz_devices_idle(app->txrx->radio_device);
uint32_t value = subghz_devices_set_frequency(app->txrx->radio_device, frequency);
furi_hal_subghz_start_async_rx(subghz_worker_rx_callback, app->txrx->worker);
// Not need. init in subghz_devices_start_async_tx
// furi_hal_gpio_init(furi_hal_subghz.cc1101_g0_pin, GpioModeInput, GpioPullNo, GpioSpeedLow);
subghz_devices_flush_rx(app->txrx->radio_device);
subghz_devices_set_rx(app->txrx->radio_device);
subghz_devices_start_async_rx(
app->txrx->radio_device, subghz_worker_rx_callback, app->txrx->worker);
subghz_worker_start(app->txrx->worker);
app->txrx->txrx_state = PCSGTxRxStateRx;
return value;
@@ -67,7 +72,7 @@ uint32_t pcsg_rx(POCSAGPagerApp* app, uint32_t frequency) {
void pcsg_idle(POCSAGPagerApp* app) {
furi_assert(app);
furi_assert(app->txrx->txrx_state != PCSGTxRxStateSleep);
furi_hal_subghz_idle();
subghz_devices_idle(app->txrx->radio_device);
app->txrx->txrx_state = PCSGTxRxStateIDLE;
}
@@ -76,15 +81,15 @@ void pcsg_rx_end(POCSAGPagerApp* app) {
furi_assert(app->txrx->txrx_state == PCSGTxRxStateRx);
if(subghz_worker_is_running(app->txrx->worker)) {
subghz_worker_stop(app->txrx->worker);
furi_hal_subghz_stop_async_rx();
subghz_devices_stop_async_rx(app->txrx->radio_device);
}
furi_hal_subghz_idle();
subghz_devices_idle(app->txrx->radio_device);
app->txrx->txrx_state = PCSGTxRxStateIDLE;
}
void pcsg_sleep(POCSAGPagerApp* app) {
furi_assert(app);
furi_hal_subghz_sleep();
subghz_devices_sleep(app->txrx->radio_device);
app->txrx->txrx_state = PCSGTxRxStateSleep;
}
@@ -110,7 +115,7 @@ void pcsg_hopper_update(POCSAGPagerApp* app) {
float rssi = -127.0f;
if(app->txrx->hopper_state != PCSGHopperStateRSSITimeOut) {
// See RSSI Calculation timings in CC1101 17.3 RSSI
rssi = furi_hal_subghz_get_rssi();
rssi = subghz_devices_get_rssi(app->txrx->radio_device);
// Stay if RSSI is high enough
if(rssi > -90.0f) {

Some files were not shown because too many files have changed in this diff Show More