unleashed-firmware/applications/main/subghz/views/subghz_test_static.c

195 lines
6.5 KiB
C
Raw Normal View History

#include "subghz_test_static.h"
#include "../subghz_i.h"
#include "../helpers/subghz_testing.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>
#define TAG "SubGhzTestStatic"
typedef enum {
SubGhzTestStaticStatusIDLE,
SubGhzTestStaticStatusTX,
} SubGhzTestStaticStatus;
static const uint32_t subghz_test_static_keys[] = {
2021-08-12 14:42:56 +00:00
0x0074BADE,
0x0074BADD,
0x0074BADB,
0x00E34A4E,
};
struct SubGhzTestStatic {
View* view;
SubGhzTestStaticStatus status_tx;
2021-08-12 14:42:56 +00:00
SubGhzEncoderPrinceton* encoder;
SubGhzTestStaticCallback callback;
void* context;
};
typedef struct {
uint8_t frequency;
uint32_t real_frequency;
uint8_t button;
} SubGhzTestStaticModel;
void subghz_test_static_set_callback(
SubGhzTestStatic* subghz_test_static,
SubGhzTestStaticCallback callback,
void* context) {
furi_assert(subghz_test_static);
furi_assert(callback);
subghz_test_static->callback = callback;
subghz_test_static->context = context;
}
void subghz_test_static_draw(Canvas* canvas, SubGhzTestStaticModel* model) {
char buffer[64];
canvas_set_color(canvas, ColorBlack);
canvas_set_font(canvas, FontPrimary);
canvas_draw_str(canvas, 0, 8, "CC1101 Static");
canvas_set_font(canvas, FontSecondary);
// Frequency
snprintf(
buffer,
sizeof(buffer),
"Freq: %03ld.%03ld.%03ld Hz",
model->real_frequency / 1000000 % 1000,
model->real_frequency / 1000 % 1000,
model->real_frequency % 1000);
canvas_draw_str(canvas, 0, 20, buffer);
snprintf(buffer, sizeof(buffer), "Key: %d", model->button);
canvas_draw_str(canvas, 0, 31, buffer);
}
bool subghz_test_static_input(InputEvent* event, void* context) {
furi_assert(context);
SubGhzTestStatic* instance = context;
if(event->key == InputKeyBack) {
return false;
}
with_view_model(
instance->view,
SubGhzTestStaticModel * model,
{
if(event->type == InputTypeShort) {
if(event->key == InputKeyLeft) {
if(model->frequency > 0) model->frequency--;
} else if(event->key == InputKeyRight) {
if(model->frequency < subghz_frequencies_count_testing - 1) model->frequency++;
} else if(event->key == InputKeyDown) {
if(model->button > 0) model->button--;
} else if(event->key == InputKeyUp) {
if(model->button < 3) model->button++;
}
}
model->real_frequency = subghz_frequencies_testing[model->frequency];
if(event->key == InputKeyOk) {
NotificationApp* notification = furi_record_open(RECORD_NOTIFICATION);
if(event->type == InputTypePress) {
furi_hal_subghz_idle();
furi_hal_subghz_set_frequency_and_path(
subghz_frequencies_testing[model->frequency]);
if(!furi_hal_subghz_tx()) {
instance->callback(SubGhzTestStaticEventOnlyRx, instance->context);
} else {
notification_message_block(notification, &sequence_set_red_255);
FURI_LOG_I(TAG, "TX Start");
subghz_encoder_princeton_for_testing_set(
instance->encoder,
subghz_test_static_keys[model->button],
10000,
subghz_frequencies_testing[model->frequency]);
2021-08-12 14:42:56 +00:00
furi_hal_subghz_start_async_tx(
subghz_encoder_princeton_for_testing_yield, instance->encoder);
instance->status_tx = SubGhzTestStaticStatusTX;
}
} else if(event->type == InputTypeRelease) {
if(instance->status_tx == SubGhzTestStaticStatusTX) {
FURI_LOG_I(TAG, "TX Stop");
subghz_encoder_princeton_for_testing_stop(
instance->encoder, furi_get_tick());
subghz_encoder_princeton_for_testing_print_log(instance->encoder);
furi_hal_subghz_stop_async_tx();
notification_message(notification, &sequence_reset_red);
}
instance->status_tx = SubGhzTestStaticStatusIDLE;
}
furi_record_close(RECORD_NOTIFICATION);
}
},
true);
return true;
}
void subghz_test_static_enter(void* context) {
furi_assert(context);
SubGhzTestStatic* instance = context;
2021-08-08 18:03:25 +00:00
furi_hal_subghz_reset();
Skorp subghz signal archive (#667) * SubGhz: Add millis() furi, add subghz history struct * SubGhz: Fix subghz history * Gubghz: Fix code repeat history, add clean history * SubGhz: reading and adding keys to history * Gui: Renaming Sub 1-Ghz -> SubGhz * Archive: Renaming Sub 1-Ghz -> SubGhz * SubGhz: Add menu history, modified button for sending a signal, changed output of data about accepted protocol * Archive: Fix name subghz * SubGhz: Menu navigation * Assets: Add assets/SubGHz/icon.png * Assets: add new icons for subghz * SubGhz: Fix name Add manually scene * SubGhz: Fix load icon Read scene. rename encoder struct, rename protocol function load from file, add load raw data protocol, add info pleasant signals all protocol * SubGhz: fix memory leak * SubGhz: change of receiving frequency for read scene * SubGhz: Add save/load frequency and preset, add automatic configuration of transmit/receive to the desired frequency and modulation, add button "save" config scene * SubGhz: Fix frequency and preset, fix frequency add manualli scene, fix re-executing the parser * Furi-hal-subghz: add 2-FSK config, fix ook config 650KHz BW Tx filter * Fix formatting and release build * SubGhz: Delete read scene * SubGhz: Fix frequency add manualli scene, refactoring code * SubGhz: 2 profiles for OOK, fix broken build. * SubGhz: Add passing static codes from read scene, add notification read scene, refactoring code * SubGhz: fix assert on worker double stop. Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2021-08-28 13:51:48 +00:00
furi_hal_subghz_load_preset(FuriHalSubGhzPresetOok650Async);
2023-02-02 19:47:50 +00:00
furi_hal_gpio_init(
furi_hal_subghz.cc1101_g0_pin, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_write(furi_hal_subghz.cc1101_g0_pin, false);
instance->status_tx = SubGhzTestStaticStatusIDLE;
with_view_model(
instance->view,
SubGhzTestStaticModel * model,
{
model->frequency = subghz_frequencies_433_92_testing;
model->real_frequency = subghz_frequencies_testing[model->frequency];
model->button = 0;
},
true);
}
void subghz_test_static_exit(void* context) {
furi_assert(context);
2021-08-08 18:03:25 +00:00
furi_hal_subghz_sleep();
}
SubGhzTestStatic* subghz_test_static_alloc() {
SubGhzTestStatic* instance = malloc(sizeof(SubGhzTestStatic));
// View allocation and configuration
2021-08-12 14:42:56 +00:00
instance->view = view_alloc();
view_allocate_model(instance->view, ViewModelTypeLocking, sizeof(SubGhzTestStaticModel));
2021-08-12 14:42:56 +00:00
view_set_context(instance->view, instance);
view_set_draw_callback(instance->view, (ViewDrawCallback)subghz_test_static_draw);
view_set_input_callback(instance->view, subghz_test_static_input);
view_set_enter_callback(instance->view, subghz_test_static_enter);
view_set_exit_callback(instance->view, subghz_test_static_exit);
2021-08-12 14:42:56 +00:00
instance->encoder = subghz_encoder_princeton_for_testing_alloc();
2021-08-12 14:42:56 +00:00
return instance;
}
void subghz_test_static_free(SubGhzTestStatic* instance) {
2021-08-12 14:42:56 +00:00
furi_assert(instance);
subghz_encoder_princeton_for_testing_free(instance->encoder);
2021-08-12 14:42:56 +00:00
view_free(instance->view);
free(instance);
}
View* subghz_test_static_get_view(SubGhzTestStatic* instance) {
2021-08-12 14:42:56 +00:00
furi_assert(instance);
return instance->view;
[FL-2274] Inventing streams and moving FFF to them (#981) * Streams: string stream * String stream: updated insert/delete api * Streams: generic stream interface and string stream implementation * Streams: helpers for insert and delete_and_insert * FFF: now compatible with streams * MinUnit: introduced tests with arguments * FFF: stream access violation * Streams: copy data between streams * Streams: file stream * FFF: documentation * FFStream: documentation * FFF: alloc as file * MinUnit: support for nested tests * Streams: changed delete_and_insert, now it returns success flag. Added ability dump stream inner parameters and data to cout. * FFF: simplified file open function * Streams: unit tests * FFF: tests * Streams: declare cache_size constant as define, to allow variable modified arrays * FFF: lib moved to a separate folder * iButton: new FFF * RFID: new FFF * Animations: new FFF * IR: new FFF * NFC: new FFF * Flipper file format: delete lib * U2F: new FFF * Subghz: new FFF and streams * Streams: read line * Streams: split * FuriCore: implement memset with extra asserts * FuriCore: implement extra heap asserts without inventing memset * Scene manager: protected access to the scene id stack with a size check * NFC worker: dirty fix for issue where hal_nfc was busy on app start * Furi: update allocator to erase memory on allocation. Replace furi_alloc with malloc. * FuriCore: cleanup memmgr code. * Furi HAL: furi_hal_init is split into critical and non-critical parts. The critical part is currently clock and console. * Memmgr: added ability to track allocations and deallocations through console. * FFStream: some speedup * Streams, FF: minor fixes * Tests: restore * File stream: a slightly more thread-safe version of file_stream_delete_and_insert Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2022-02-18 19:53:46 +00:00
}