SubGhz: increase output power and. Dolphin scene: refactor. (#411)

* SubGhz: increase output power to max
* Dolphin scene: refactor code.
This commit is contained in:
あく 2021-04-15 19:39:15 +03:00 committed by GitHub
parent 3e281175da
commit e0bc80cd8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 67 additions and 70 deletions

View File

@ -71,13 +71,10 @@ typedef struct {
} Vec2; } Vec2;
typedef struct { typedef struct {
osMessageQueueId_t mqueue;
Gui* gui; Gui* gui;
ViewPort* view_port; ViewPort* view_port;
ValueMutex* vm;
osTimerId_t* timer; osTimerId_t* timer;
osMessageQueueId_t mqueue;
FuriThread* scene_app_thread;
} SceneAppGui; } SceneAppGui;
typedef struct { typedef struct {
@ -92,7 +89,6 @@ typedef struct {
} Item; } Item;
typedef struct { typedef struct {
SceneAppGui ui;
/// ///
Vec2 player; Vec2 player;
Vec2 player_global; Vec2 player_global;
@ -126,6 +122,8 @@ typedef struct {
int8_t zoom_v; int8_t zoom_v;
uint8_t scene_zoom; uint8_t scene_zoom;
uint8_t dialog_progress; uint8_t dialog_progress;
FuriThread* scene_app_thread;
} SceneState; } SceneState;
void dolphin_scene_render(SceneState* state, Canvas* canvas, uint32_t t); void dolphin_scene_render(SceneState* state, Canvas* canvas, uint32_t t);

View File

@ -1,115 +1,114 @@
#include <furi.h> #include <furi.h>
#include <api-hal.h>
#include "dolphin_scene/dolphin_scene.h" #include "dolphin_scene/dolphin_scene.h"
void dolphin_engine_tick_cb(void* p) { static SceneAppGui* scene_app_gui = NULL;
static ValueMutex* scene_state_mutex = NULL;
static void dolphin_engine_tick_callback(void* p) {
osMessageQueueId_t event_queue = p; osMessageQueueId_t event_queue = p;
AppEvent tick_event; AppEvent event;
tick_event.type = EventTypeTick; event.type = EventTypeTick;
osMessageQueuePut(event_queue, (void*)&tick_event, 0, 0); osMessageQueuePut(event_queue, (void*)&event, 0, 0);
} }
static void dolphin_engine_event_cb(InputEvent* input_event, void* ctx) { static void dolphin_engine_input_callback(InputEvent* input_event, void* ctx) {
osMessageQueueId_t event_queue = ctx; osMessageQueueId_t event_queue = ctx;
AppEvent event; AppEvent event;
event.type = EventTypeKey; event.type = EventTypeKey;
event.value.input = *input_event; event.value.input = *input_event;
osMessageQueuePut(event_queue, (void*)&event, 0, osWaitForever); osMessageQueuePut(event_queue, (void*)&event, 0, osWaitForever);
} }
ValueMutex* scene_init() { void scene_alloc() {
SceneState* scene_state = furi_alloc(sizeof(SceneState)); printf("scene_alloc: start\r\n");
scene_state->ui.mqueue = osMessageQueueNew(2, sizeof(AppEvent), NULL); furi_assert(scene_app_gui == NULL);
furi_assert(scene_state_mutex == NULL);
// SceneAppGui
scene_app_gui = furi_alloc(sizeof(SceneAppGui));
scene_app_gui->mqueue = osMessageQueueNew(2, sizeof(AppEvent), NULL);
scene_app_gui->gui = furi_record_open("gui");
scene_app_gui->view_port = view_port_alloc();
scene_app_gui->timer =
osTimerNew(dolphin_engine_tick_callback, osTimerPeriodic, scene_app_gui->mqueue, NULL);
printf("scene_alloc: timer %p\r\n", scene_app_gui->timer);
// Scene State
SceneState* scene_state = furi_alloc(sizeof(SceneState));
scene_state->player.y = DOLPHIN_DEFAULT_Y; scene_state->player.y = DOLPHIN_DEFAULT_Y;
scene_state->player.x = DOLPHIN_CENTER; scene_state->player.x = DOLPHIN_CENTER;
//randomize position
scene_state->player_global.x = random() % WORLD_WIDTH / 4; scene_state->player_global.x = random() % WORLD_WIDTH / 4;
scene_state->screen.x = scene_state->player.x; scene_state->screen.x = scene_state->player.x;
scene_state->screen.y = scene_state->player.y; scene_state->screen.y = scene_state->player.y;
ValueMutex* scene_state_mutex = furi_alloc(sizeof(ValueMutex)); scene_state_mutex = furi_alloc(sizeof(ValueMutex));
if(scene_state_mutex == NULL || furi_check(init_mutex(scene_state_mutex, scene_state, sizeof(SceneState)));
!init_mutex(scene_state_mutex, scene_state, sizeof(SceneState))) {
printf("[menu_task] cannot create menu mutex\r\n");
furi_check(0);
}
// Open GUI and register view_port
scene_state->ui.gui = furi_record_open("gui");
// Allocate and configure view_port
scene_state->ui.view_port = view_port_alloc();
// Open GUI and register fullscreen view_port // Open GUI and register fullscreen view_port
gui_add_view_port(scene_state->ui.gui, scene_state->ui.view_port, GuiLayerMain); view_port_draw_callback_set(scene_app_gui->view_port, dolphin_scene_redraw, scene_state_mutex);
view_port_draw_callback_set(
scene_state->ui.view_port, dolphin_scene_redraw, scene_state_mutex);
view_port_input_callback_set( view_port_input_callback_set(
scene_state->ui.view_port, dolphin_engine_event_cb, scene_state->ui.mqueue); scene_app_gui->view_port, dolphin_engine_input_callback, scene_app_gui->mqueue);
view_port_enabled_set(scene_state->ui.view_port, true); gui_add_view_port(scene_app_gui->gui, scene_app_gui->view_port, GuiLayerMain);
view_port_enabled_set(scene_app_gui->view_port, true);
scene_state->ui.timer = printf("scene_alloc: complete\r\n");
osTimerNew(dolphin_engine_tick_cb, osTimerPeriodic, scene_state->ui.mqueue, NULL);
return scene_state_mutex;
} }
void scene_free(ValueMutex* scene_state_mutex) { void scene_free() {
furi_assert(scene_state_mutex); printf("scene_free: start\r\n");
view_port_enabled_set(scene_app_gui->view_port, false);
gui_remove_view_port(scene_app_gui->gui, scene_app_gui->view_port);
SceneState* scene_state = (SceneState*)acquire_mutex_block(scene_state_mutex); SceneState* scene_state = (SceneState*)acquire_mutex_block(scene_state_mutex);
furi_assert(scene_state);
osTimerDelete(scene_state->ui.timer);
gui_remove_view_port(scene_state->ui.gui, scene_state->ui.view_port);
view_port_free(scene_state->ui.view_port);
furi_record_close("gui");
osMessageQueueDelete(scene_state->ui.mqueue);
free(scene_state); free(scene_state);
release_mutex(scene_state_mutex, scene_state); release_mutex(scene_state_mutex, scene_state);
delete_mutex(scene_state_mutex); delete_mutex(scene_state_mutex);
free(scene_state_mutex); free(scene_state_mutex);
scene_state_mutex = NULL;
furi_check(osTimerDelete(scene_app_gui->timer) == osOK);
furi_record_close("gui");
view_port_free(scene_app_gui->view_port);
furi_check(osMessageQueueDelete(scene_app_gui->mqueue) == osOK);
free(scene_app_gui);
scene_app_gui = NULL;
printf("scene_free: complete\r\n");
} }
int32_t dolphin_scene(void* p) { int32_t dolphin_scene(void* p) {
ValueMutex* scene_state_mutex = scene_init(); api_hal_power_insomnia_enter();
scene_alloc();
furi_record_create("scene", scene_state_mutex); osTimerStart(scene_app_gui->timer, 40);
SceneState* _state = (SceneState*)acquire_mutex_block(scene_state_mutex);
osTimerStart(_state->ui.timer, 40);
uint32_t t = xTaskGetTickCount(); uint32_t t = xTaskGetTickCount();
uint32_t prev_t = 0; uint32_t prev_t = 0;
osMessageQueueId_t q = _state->ui.mqueue;
release_mutex(scene_state_mutex, _state);
while(1) { while(1) {
AppEvent event; AppEvent event;
if(osMessageQueueGet(q, &event, 0, osWaitForever) == osOK) { if(osMessageQueueGet(scene_app_gui->mqueue, &event, 0, osWaitForever) == osOK) {
SceneState* _state = (SceneState*)acquire_mutex_block(scene_state_mutex); SceneState* scene_state = (SceneState*)acquire_mutex_block(scene_state_mutex);
if(event.type == EventTypeTick) { if(event.type == EventTypeTick) {
t = xTaskGetTickCount(); t = xTaskGetTickCount();
dolphin_scene_tick_handler(_state, t, (t - prev_t) % 1024); dolphin_scene_tick_handler(scene_state, t, (t - prev_t) % 1024);
prev_t = t; prev_t = t;
} else if(event.type == EventTypeKey) { } else if(event.type == EventTypeKey) {
if(event.value.input.key == InputKeyBack && if(event.value.input.key == InputKeyBack &&
event.value.input.type == InputTypeShort) { event.value.input.type == InputTypeShort) {
release_mutex(scene_state_mutex, _state); release_mutex(scene_state_mutex, scene_state);
break; break;
} else { } else {
dolphin_scene_handle_input(_state, &event.value.input); dolphin_scene_handle_input(scene_state, &event.value.input);
} }
} }
release_mutex(scene_state_mutex, _state); release_mutex(scene_state_mutex, scene_state);
view_port_update(_state->ui.view_port); view_port_update(scene_app_gui->view_port);
} }
} }
scene_free(scene_state_mutex); osTimerStop(scene_app_gui->timer);
scene_free();
api_hal_power_insomnia_exit();
return 0; return 0;
} }

View File

@ -53,15 +53,15 @@ static void dolphin_scene_start_app(SceneState* state, const FlipperApplication*
furi_assert(state); furi_assert(state);
furi_assert(flipper_app); furi_assert(flipper_app);
state->ui.scene_app_thread = furi_thread_alloc(); state->scene_app_thread = furi_thread_alloc();
furi_assert(flipper_app->app); furi_assert(flipper_app->app);
furi_assert(flipper_app->name); furi_assert(flipper_app->name);
furi_thread_set_name(state->ui.scene_app_thread, flipper_app->name); furi_thread_set_name(state->scene_app_thread, flipper_app->name);
furi_thread_set_stack_size(state->ui.scene_app_thread, flipper_app->stack_size); furi_thread_set_stack_size(state->scene_app_thread, flipper_app->stack_size);
furi_thread_set_callback(state->ui.scene_app_thread, flipper_app->app); furi_thread_set_callback(state->scene_app_thread, flipper_app->app);
furi_thread_start(state->ui.scene_app_thread); furi_thread_start(state->scene_app_thread);
} }
const Item* is_nearby(SceneState* state) { const Item* is_nearby(SceneState* state) {

View File

@ -20,7 +20,7 @@ static const uint8_t api_hal_subghz_preset_ook_async_regs[][2] = {
}; };
static const uint8_t api_hal_subghz_preset_ook_async_patable[8] = { static const uint8_t api_hal_subghz_preset_ook_async_patable[8] = {
0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
}; };
static const uint8_t api_hal_subghz_preset_2fsk_packet_regs[][2] = { static const uint8_t api_hal_subghz_preset_2fsk_packet_regs[][2] = {
@ -33,7 +33,7 @@ static const uint8_t api_hal_subghz_preset_2fsk_packet_regs[][2] = {
}; };
static const uint8_t api_hal_subghz_preset_2fsk_packet_patable[8] = { static const uint8_t api_hal_subghz_preset_2fsk_packet_patable[8] = {
0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
}; };
void api_hal_subghz_init() { void api_hal_subghz_init() {