2020-12-18 20:15:29 +00:00
|
|
|
#include "dolphin_i.h"
|
|
|
|
|
2021-01-08 04:42:48 +00:00
|
|
|
bool dolphin_view_first_start_input(InputEvent* event, void* context) {
|
|
|
|
furi_assert(event);
|
|
|
|
furi_assert(context);
|
2020-12-18 20:15:29 +00:00
|
|
|
Dolphin* dolphin = context;
|
2021-01-08 04:42:48 +00:00
|
|
|
if(event->state) {
|
|
|
|
if(event->input == InputRight) {
|
|
|
|
uint32_t page;
|
|
|
|
with_view_model(
|
|
|
|
dolphin->idle_view_first_start,
|
|
|
|
(DolphinViewFirstStartModel * model) { page = ++model->page; });
|
|
|
|
if(page > 8) {
|
|
|
|
dolphin_save(dolphin);
|
|
|
|
view_dispatcher_switch_to_view(dolphin->idle_view_dispatcher, DolphinViewIdleMain);
|
|
|
|
}
|
|
|
|
}
|
2020-12-18 20:15:29 +00:00
|
|
|
}
|
2021-01-08 04:42:48 +00:00
|
|
|
// All events consumed
|
|
|
|
return true;
|
2020-12-18 20:15:29 +00:00
|
|
|
}
|
|
|
|
|
2021-01-08 04:42:48 +00:00
|
|
|
bool dolphin_view_idle_main_input(InputEvent* event, void* context) {
|
|
|
|
furi_assert(event);
|
|
|
|
furi_assert(context);
|
|
|
|
Dolphin* dolphin = context;
|
2020-12-18 20:15:29 +00:00
|
|
|
|
2021-01-08 04:42:48 +00:00
|
|
|
if(event->state) {
|
|
|
|
if(event->input == InputOk) {
|
|
|
|
with_value_mutex(
|
|
|
|
dolphin->menu_vm, (Menu * menu) { menu_ok(menu); });
|
|
|
|
} else if(event->input == InputUp) {
|
|
|
|
view_dispatcher_switch_to_view(dolphin->idle_view_dispatcher, DolphinViewIdleStats);
|
|
|
|
} else if(event->input == InputDown) {
|
|
|
|
view_dispatcher_switch_to_view(dolphin->idle_view_dispatcher, DolphinViewIdleDebug);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// All events consumed
|
|
|
|
return true;
|
2020-12-18 20:15:29 +00:00
|
|
|
}
|
|
|
|
|
2021-01-08 04:42:48 +00:00
|
|
|
bool dolphin_view_idle_stats_input(InputEvent* event, void* context) {
|
|
|
|
furi_assert(event);
|
|
|
|
furi_assert(context);
|
2020-12-18 20:15:29 +00:00
|
|
|
Dolphin* dolphin = context;
|
|
|
|
|
2021-01-08 04:42:48 +00:00
|
|
|
if(!event->state) return false;
|
2020-12-18 20:15:29 +00:00
|
|
|
|
2021-01-08 04:42:48 +00:00
|
|
|
if(event->input == InputLeft) {
|
2020-12-18 20:15:29 +00:00
|
|
|
dolphin_deed(dolphin, DolphinDeedWrong);
|
2021-01-08 04:42:48 +00:00
|
|
|
} else if(event->input == InputRight) {
|
|
|
|
dolphin_deed(dolphin, DolphinDeedIButtonRead);
|
|
|
|
} else if(event->input == InputOk) {
|
|
|
|
dolphin_save(dolphin);
|
|
|
|
} else {
|
|
|
|
return false;
|
2020-12-18 20:15:29 +00:00
|
|
|
}
|
|
|
|
|
2021-01-08 04:42:48 +00:00
|
|
|
return true;
|
2020-12-18 20:15:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Dolphin* dolphin_alloc() {
|
|
|
|
Dolphin* dolphin = furi_alloc(sizeof(Dolphin));
|
2021-01-08 04:42:48 +00:00
|
|
|
// Message queue
|
|
|
|
dolphin->event_queue = osMessageQueueNew(8, sizeof(DolphinEvent), NULL);
|
|
|
|
furi_check(dolphin->event_queue);
|
|
|
|
// State
|
|
|
|
dolphin->state = dolphin_state_alloc();
|
|
|
|
// Menu
|
2020-12-18 20:15:29 +00:00
|
|
|
dolphin->menu_vm = furi_open("menu");
|
|
|
|
furi_check(dolphin->menu_vm);
|
2021-01-08 04:42:48 +00:00
|
|
|
// GUI
|
|
|
|
dolphin->idle_view_dispatcher = view_dispatcher_alloc();
|
|
|
|
// First start View
|
|
|
|
dolphin->idle_view_first_start = view_alloc();
|
|
|
|
view_allocate_model(
|
|
|
|
dolphin->idle_view_first_start, ViewModelTypeLockFree, sizeof(DolphinViewFirstStartModel));
|
|
|
|
view_set_context(dolphin->idle_view_first_start, dolphin);
|
|
|
|
view_set_draw_callback(dolphin->idle_view_first_start, dolphin_view_first_start_draw);
|
|
|
|
view_set_input_callback(dolphin->idle_view_first_start, dolphin_view_first_start_input);
|
|
|
|
view_dispatcher_add_view(
|
|
|
|
dolphin->idle_view_dispatcher, DolphinViewFirstStart, dolphin->idle_view_first_start);
|
|
|
|
// Main Idle View
|
|
|
|
dolphin->idle_view_main = view_alloc();
|
|
|
|
view_set_context(dolphin->idle_view_main, dolphin);
|
|
|
|
view_set_draw_callback(dolphin->idle_view_main, dolphin_view_idle_main_draw);
|
|
|
|
view_set_input_callback(dolphin->idle_view_main, dolphin_view_idle_main_input);
|
|
|
|
view_dispatcher_add_view(
|
|
|
|
dolphin->idle_view_dispatcher, DolphinViewIdleMain, dolphin->idle_view_main);
|
|
|
|
// Stats Idle View
|
|
|
|
dolphin->idle_view_stats = view_alloc();
|
|
|
|
view_set_context(dolphin->idle_view_stats, dolphin);
|
|
|
|
view_allocate_model(
|
|
|
|
dolphin->idle_view_stats, ViewModelTypeLockFree, sizeof(DolphinViewIdleStatsModel));
|
|
|
|
view_set_draw_callback(dolphin->idle_view_stats, dolphin_view_idle_stats_draw);
|
|
|
|
view_set_input_callback(dolphin->idle_view_stats, dolphin_view_idle_stats_input);
|
|
|
|
view_set_previous_callback(dolphin->idle_view_stats, dolphin_view_idle_back);
|
|
|
|
view_dispatcher_add_view(
|
|
|
|
dolphin->idle_view_dispatcher, DolphinViewIdleStats, dolphin->idle_view_stats);
|
|
|
|
// Debug Idle View
|
|
|
|
dolphin->idle_view_debug = view_alloc();
|
|
|
|
view_set_draw_callback(dolphin->idle_view_debug, dolphin_view_idle_debug_draw);
|
|
|
|
view_set_previous_callback(dolphin->idle_view_debug, dolphin_view_idle_back);
|
|
|
|
view_dispatcher_add_view(
|
|
|
|
dolphin->idle_view_dispatcher, DolphinViewIdleDebug, dolphin->idle_view_debug);
|
2020-12-18 20:15:29 +00:00
|
|
|
|
|
|
|
return dolphin;
|
|
|
|
}
|
|
|
|
|
2021-01-08 04:42:48 +00:00
|
|
|
void dolphin_save(Dolphin* dolphin) {
|
|
|
|
furi_assert(dolphin);
|
|
|
|
DolphinEvent event;
|
|
|
|
event.type = DolphinEventTypeSave;
|
|
|
|
furi_check(osMessageQueuePut(dolphin->event_queue, &event, 0, osWaitForever) == osOK);
|
|
|
|
}
|
|
|
|
|
2020-12-18 20:15:29 +00:00
|
|
|
void dolphin_deed(Dolphin* dolphin, DolphinDeed deed) {
|
2021-01-08 04:42:48 +00:00
|
|
|
furi_assert(dolphin);
|
2020-12-18 20:15:29 +00:00
|
|
|
DolphinEvent event;
|
|
|
|
event.type = DolphinEventTypeDeed;
|
|
|
|
event.deed = deed;
|
|
|
|
furi_check(osMessageQueuePut(dolphin->event_queue, &event, 0, osWaitForever) == osOK);
|
|
|
|
}
|
|
|
|
|
|
|
|
void dolphin_task() {
|
|
|
|
Dolphin* dolphin = dolphin_alloc();
|
|
|
|
|
|
|
|
Gui* gui = furi_open("gui");
|
2021-01-08 04:42:48 +00:00
|
|
|
view_dispatcher_attach_to_gui(dolphin->idle_view_dispatcher, gui, ViewDispatcherTypeWindow);
|
|
|
|
if(dolphin_state_load(dolphin->state)) {
|
|
|
|
view_dispatcher_switch_to_view(dolphin->idle_view_dispatcher, DolphinViewIdleMain);
|
|
|
|
} else {
|
|
|
|
view_dispatcher_switch_to_view(dolphin->idle_view_dispatcher, DolphinViewFirstStart);
|
|
|
|
}
|
FL-53: new NFC worker, A/B/F/V poll and display. (#283)
* GUI: view. Flooper-blooper fix compilation error.
* GUI: view and viewdispatcher bones
* GUI: view implementation, view models, view dispatcher
* GUI: view navigation, model refinement. Power: use view, view dispatcher.
* HAL Flash: proper page write. Dolphin: views. Power: views
* Dolphin: transition idle scree to Views
* Dolphin: input events on stats view. Format sources.
* HAL: flash erase. Dolphin: permanent state storage.
* Dolphin: first start welcome. HAL: flash operation status, errata 2.2.9 crutch.
* NFC: rewrite worker
* NFC: add support for B,F,V.
* NFC: replace rfal irq hanlder with realtime thread, more details about cards.
* Bootloader: LSE and RTS shenanigans, LED control, morse code for LSE failure error.
* F4: stop in Error_Handler
* BLE: handle working FUS, but empty radio stack.
* HAL: alive FUS is now sufficient for flash controller access
* Dolphin: update model after state load
* NFC: detect navigation
* RFAL: use osPriorityISR for isr thread
* NFC: emulation
* Bootloader: rollback incorrectly merged rename
* Dolphin: rollback incorrectly merged changes
* RFAL: remove volatile from thread attr
* RFAL: do not call platform ErrorHandler, error codes is enough
* NFC: improved error handling
* Format sources
* NFC: reset detect view model on start
* Format sources
* update codeowners
* NFC: hide last info if no card detected
2021-01-11 12:42:25 +00:00
|
|
|
with_view_model(
|
|
|
|
dolphin->idle_view_stats, (DolphinViewIdleStatsModel * model) {
|
|
|
|
model->icounter = dolphin_state_get_icounter(dolphin->state);
|
|
|
|
model->butthurt = dolphin_state_get_butthurt(dolphin->state);
|
|
|
|
});
|
2020-12-18 20:15:29 +00:00
|
|
|
|
|
|
|
if(!furi_create("dolphin", dolphin)) {
|
|
|
|
printf("[dolphin_task] cannot create the dolphin record\n");
|
|
|
|
furiac_exit(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
furiac_ready();
|
|
|
|
|
|
|
|
DolphinEvent event;
|
|
|
|
while(1) {
|
|
|
|
furi_check(osMessageQueueGet(dolphin->event_queue, &event, NULL, osWaitForever) == osOK);
|
|
|
|
if(event.type == DolphinEventTypeDeed) {
|
|
|
|
dolphin_state_on_deed(dolphin->state, event.deed);
|
2021-01-08 04:42:48 +00:00
|
|
|
with_view_model(
|
|
|
|
dolphin->idle_view_stats, (DolphinViewIdleStatsModel * model) {
|
|
|
|
model->icounter = dolphin_state_get_icounter(dolphin->state);
|
|
|
|
model->butthurt = dolphin_state_get_butthurt(dolphin->state);
|
|
|
|
});
|
|
|
|
} else if(event.type == DolphinEventTypeSave) {
|
|
|
|
dolphin_state_save(dolphin->state);
|
2020-12-18 20:15:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|