mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-23 05:24:46 -07:00
formatted
This commit is contained in:
@@ -34,7 +34,8 @@ static void bad_usb_draw_callback(Canvas* canvas, void* _model) {
|
||||
elements_button_center(canvas, "Stop");
|
||||
}
|
||||
|
||||
if((model->state.state == BadUsbStateNotConnected) || (model->state.state == BadUsbStateIdle) || (model->state.state == BadUsbStateDone)) {
|
||||
if((model->state.state == BadUsbStateNotConnected) ||
|
||||
(model->state.state == BadUsbStateIdle) || (model->state.state == BadUsbStateDone)) {
|
||||
elements_button_left(canvas, "Config");
|
||||
}
|
||||
|
||||
|
||||
@@ -34,41 +34,35 @@
|
||||
#define ENABLE_MODULE_DETECTION 1
|
||||
|
||||
typedef enum EEventType // app internally defined event types
|
||||
{
|
||||
EventTypeKey // flipper input.h type
|
||||
{ EventTypeKey // flipper input.h type
|
||||
} EEventType;
|
||||
|
||||
typedef struct SPluginEvent
|
||||
{
|
||||
typedef struct SPluginEvent {
|
||||
EEventType m_type;
|
||||
InputEvent m_input;
|
||||
} SPluginEvent;
|
||||
|
||||
typedef enum EAppContext
|
||||
{
|
||||
typedef enum EAppContext {
|
||||
Undefined,
|
||||
WaitingForModule,
|
||||
Initializing,
|
||||
ModuleActive,
|
||||
} EAppContext;
|
||||
|
||||
typedef enum EWorkerEventFlags
|
||||
{
|
||||
typedef enum EWorkerEventFlags {
|
||||
WorkerEventReserved = (1 << 0), // Reserved for StreamBuffer internal event
|
||||
WorkerEventStop = (1 << 1),
|
||||
WorkerEventRx = (1 << 2),
|
||||
} EWorkerEventFlags;
|
||||
|
||||
typedef struct SGpioButtons
|
||||
{
|
||||
typedef struct SGpioButtons {
|
||||
GpioPin const* pinButtonUp;
|
||||
GpioPin const* pinButtonDown;
|
||||
GpioPin const* pinButtonOK;
|
||||
GpioPin const* pinButtonBack;
|
||||
} SGpioButtons;
|
||||
|
||||
typedef struct SWiFiDeauthApp
|
||||
{
|
||||
typedef struct SWiFiDeauthApp {
|
||||
Gui* m_gui;
|
||||
FuriThread* m_worker_thread;
|
||||
//NotificationApp* m_notification;
|
||||
@@ -94,8 +88,7 @@ typedef struct SWiFiDeauthApp
|
||||
} SWiFiDeauthApp;
|
||||
|
||||
/////// INIT STATE ///////
|
||||
static void esp8266_deauth_app_init(SWiFiDeauthApp* const app)
|
||||
{
|
||||
static void esp8266_deauth_app_init(SWiFiDeauthApp* const app) {
|
||||
app->m_context = Undefined;
|
||||
|
||||
app->m_canvasSize = 128 * 8 * 8;
|
||||
@@ -128,11 +121,9 @@ static void esp8266_deauth_app_init(SWiFiDeauthApp* const app)
|
||||
#endif
|
||||
}
|
||||
|
||||
static void esp8266_deauth_module_render_callback(Canvas* const canvas, void* ctx)
|
||||
{
|
||||
static void esp8266_deauth_module_render_callback(Canvas* const canvas, void* ctx) {
|
||||
SWiFiDeauthApp* app = acquire_mutex((ValueMutex*)ctx, 25);
|
||||
if (app == NULL)
|
||||
{
|
||||
if(app == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -156,27 +147,35 @@ static void esp8266_deauth_module_render_callback(Canvas* const canvas, void* ct
|
||||
// app->m_needUpdateGUI = false;
|
||||
//}
|
||||
|
||||
switch (app->m_context)
|
||||
{
|
||||
case Undefined:
|
||||
{
|
||||
switch(app->m_context) {
|
||||
case Undefined: {
|
||||
canvas_clear(canvas);
|
||||
canvas_set_font(canvas, FontPrimary);
|
||||
|
||||
const char* strInitializing = "Something wrong";
|
||||
canvas_draw_str(canvas, (u8g2_GetDisplayWidth(&canvas->fb) / 2) - (canvas_string_width(canvas, strInitializing) / 2), (u8g2_GetDisplayHeight(&canvas->fb) / 2)/* - (u8g2_GetMaxCharHeight(&canvas->fb) / 2)*/, strInitializing);
|
||||
}
|
||||
break;
|
||||
canvas_draw_str(
|
||||
canvas,
|
||||
(u8g2_GetDisplayWidth(&canvas->fb) / 2) -
|
||||
(canvas_string_width(canvas, strInitializing) / 2),
|
||||
(u8g2_GetDisplayHeight(&canvas->fb) /
|
||||
2) /* - (u8g2_GetMaxCharHeight(&canvas->fb) / 2)*/,
|
||||
strInitializing);
|
||||
} break;
|
||||
case WaitingForModule:
|
||||
#if ENABLE_MODULE_DETECTION
|
||||
furi_assert(!app->m_wifiDeauthModuleAttached);
|
||||
if (!app->m_wifiDeauthModuleAttached)
|
||||
{
|
||||
if(!app->m_wifiDeauthModuleAttached) {
|
||||
canvas_clear(canvas);
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
|
||||
const char* strInitializing = "Attach WiFi scanner module";
|
||||
canvas_draw_str(canvas, (u8g2_GetDisplayWidth(&canvas->fb) / 2) - (canvas_string_width(canvas, strInitializing) / 2), (u8g2_GetDisplayHeight(&canvas->fb) / 2)/* - (u8g2_GetMaxCharHeight(&canvas->fb) / 2)*/, strInitializing);
|
||||
canvas_draw_str(
|
||||
canvas,
|
||||
(u8g2_GetDisplayWidth(&canvas->fb) / 2) -
|
||||
(canvas_string_width(canvas, strInitializing) / 2),
|
||||
(u8g2_GetDisplayHeight(&canvas->fb) /
|
||||
2) /* - (u8g2_GetMaxCharHeight(&canvas->fb) / 2)*/,
|
||||
strInitializing);
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
@@ -184,23 +183,26 @@ static void esp8266_deauth_module_render_callback(Canvas* const canvas, void* ct
|
||||
#if ENABLE_MODULE_POWER
|
||||
{
|
||||
furi_assert(!app->m_wifiDeauthModuleInitialized);
|
||||
if (!app->m_wifiDeauthModuleInitialized)
|
||||
{
|
||||
if(!app->m_wifiDeauthModuleInitialized) {
|
||||
canvas_set_font(canvas, FontPrimary);
|
||||
|
||||
const char* strInitializing = "Initializing...";
|
||||
canvas_draw_str(canvas, (u8g2_GetDisplayWidth(&canvas->fb) / 2) - (canvas_string_width(canvas, strInitializing) / 2), (u8g2_GetDisplayHeight(&canvas->fb) / 2) - (u8g2_GetMaxCharHeight(&canvas->fb) / 2), strInitializing);
|
||||
canvas_draw_str(
|
||||
canvas,
|
||||
(u8g2_GetDisplayWidth(&canvas->fb) / 2) -
|
||||
(canvas_string_width(canvas, strInitializing) / 2),
|
||||
(u8g2_GetDisplayHeight(&canvas->fb) / 2) -
|
||||
(u8g2_GetMaxCharHeight(&canvas->fb) / 2),
|
||||
strInitializing);
|
||||
}
|
||||
}
|
||||
#endif // ENABLE_MODULE_POWER
|
||||
break;
|
||||
case ModuleActive:
|
||||
{
|
||||
case ModuleActive: {
|
||||
uint8_t* buffer = canvas_get_buffer(canvas);
|
||||
app->m_canvasSize = canvas_get_buffer_size(canvas);
|
||||
memcpy(buffer, app->m_backBuffer, app->m_canvasSize);
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -208,7 +210,8 @@ static void esp8266_deauth_module_render_callback(Canvas* const canvas, void* ct
|
||||
release_mutex((ValueMutex*)ctx, app);
|
||||
}
|
||||
|
||||
static void esp8266_deauth_module_input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) {
|
||||
static void
|
||||
esp8266_deauth_module_input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) {
|
||||
furi_assert(event_queue);
|
||||
|
||||
SPluginEvent event = {.m_type = EventTypeKey, .m_input = *input_event};
|
||||
@@ -229,8 +232,6 @@ static void uart_on_irq_cb(UartIrqEvent ev, uint8_t data, void* context) {
|
||||
furi_thread_flags_set(furi_thread_get_id(app->m_worker_thread), WorkerEventRx);
|
||||
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
static int32_t uart_worker(void* context) {
|
||||
@@ -238,8 +239,7 @@ static int32_t uart_worker(void* context) {
|
||||
DEAUTH_APP_LOG_I("[UART] Worker thread init");
|
||||
|
||||
SWiFiDeauthApp* app = acquire_mutex((ValueMutex*)context, 25);
|
||||
if (app == NULL)
|
||||
{
|
||||
if(app == NULL) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -254,43 +254,36 @@ static int32_t uart_worker(void* context) {
|
||||
string_init(receivedString);
|
||||
#endif // ENABLE_MODULE_POWER
|
||||
|
||||
while(true)
|
||||
{
|
||||
uint32_t events = furi_thread_flags_wait(WorkerEventStop | WorkerEventRx, FuriFlagWaitAny, FuriWaitForever);
|
||||
while(true) {
|
||||
uint32_t events = furi_thread_flags_wait(
|
||||
WorkerEventStop | WorkerEventRx, FuriFlagWaitAny, FuriWaitForever);
|
||||
furi_check((events & FuriFlagError) == 0);
|
||||
|
||||
if(events & WorkerEventStop) break;
|
||||
if(events & WorkerEventRx)
|
||||
{
|
||||
if(events & WorkerEventRx) {
|
||||
DEAUTH_APP_LOG_I("[UART] Received data");
|
||||
SWiFiDeauthApp* app = acquire_mutex((ValueMutex*)context, 25);
|
||||
if (app == NULL)
|
||||
{
|
||||
if(app == NULL) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
size_t dataReceivedLength = 0;
|
||||
int index = 0;
|
||||
do
|
||||
{
|
||||
do {
|
||||
const uint8_t dataBufferSize = 64;
|
||||
uint8_t dataBuffer[dataBufferSize];
|
||||
dataReceivedLength = xStreamBufferReceive(rx_stream, dataBuffer, dataBufferSize, 25);
|
||||
if (dataReceivedLength > 0)
|
||||
{
|
||||
dataReceivedLength =
|
||||
xStreamBufferReceive(rx_stream, dataBuffer, dataBufferSize, 25);
|
||||
if(dataReceivedLength > 0) {
|
||||
#if ENABLE_MODULE_POWER
|
||||
if (!initialized)
|
||||
{
|
||||
if(!(dataReceivedLength > strlen(MODULE_CONTEXT_INITIALIZATION)))
|
||||
{
|
||||
if(!initialized) {
|
||||
if(!(dataReceivedLength > strlen(MODULE_CONTEXT_INITIALIZATION))) {
|
||||
DEAUTH_APP_LOG_I("[UART] Found possible init candidate");
|
||||
for (uint16_t i = 0; i < dataReceivedLength; i++)
|
||||
{
|
||||
for(uint16_t i = 0; i < dataReceivedLength; i++) {
|
||||
string_push_back(receivedString, dataBuffer[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
} else
|
||||
#endif // ENABLE_MODULE_POWER
|
||||
{
|
||||
DEAUTH_APP_LOG_I("[UART] Data copied to backbuffer");
|
||||
@@ -303,18 +296,14 @@ static int32_t uart_worker(void* context) {
|
||||
} while(dataReceivedLength > 0);
|
||||
|
||||
#if ENABLE_MODULE_POWER
|
||||
if (!app->m_wifiDeauthModuleInitialized)
|
||||
{
|
||||
if (string_cmp_str(receivedString, MODULE_CONTEXT_INITIALIZATION) == 0)
|
||||
{
|
||||
if(!app->m_wifiDeauthModuleInitialized) {
|
||||
if(string_cmp_str(receivedString, MODULE_CONTEXT_INITIALIZATION) == 0) {
|
||||
DEAUTH_APP_LOG_I("[UART] Initialized");
|
||||
initialized = true;
|
||||
app->m_wifiDeauthModuleInitialized = true;
|
||||
app->m_context = ModuleActive;
|
||||
string_clear(receivedString);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
DEAUTH_APP_LOG_I("[UART] Not an initialization command");
|
||||
string_reset(receivedString);
|
||||
}
|
||||
@@ -328,8 +317,7 @@ static int32_t uart_worker(void* context) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t esp8266_deauth_app(void* p)
|
||||
{
|
||||
int32_t esp8266_deauth_app(void* p) {
|
||||
UNUSED(p);
|
||||
|
||||
DEAUTH_APP_LOG_I("Init");
|
||||
@@ -351,10 +339,15 @@ int32_t esp8266_deauth_app(void* p)
|
||||
furi_hal_gpio_write(app->m_GpioButtons.pinButtonUp, true);
|
||||
furi_hal_gpio_write(app->m_GpioButtons.pinButtonDown, true);
|
||||
furi_hal_gpio_write(app->m_GpioButtons.pinButtonOK, true);
|
||||
furi_hal_gpio_write(app->m_GpioButtons.pinButtonBack, false); // GPIO15 - Boot fails if pulled HIGH
|
||||
furi_hal_gpio_write(
|
||||
app->m_GpioButtons.pinButtonBack, false); // GPIO15 - Boot fails if pulled HIGH
|
||||
|
||||
#if ENABLE_MODULE_DETECTION
|
||||
furi_hal_gpio_init(&gpio_ext_pc0, GpioModeInput, GpioPullUp, GpioSpeedLow); // Connect to the Flipper's ground just to be sure
|
||||
furi_hal_gpio_init(
|
||||
&gpio_ext_pc0,
|
||||
GpioModeInput,
|
||||
GpioPullUp,
|
||||
GpioSpeedLow); // Connect to the Flipper's ground just to be sure
|
||||
//furi_hal_gpio_add_int_callback(pinD0, input_isr_d0, this);
|
||||
app->m_context = WaitingForModule;
|
||||
#else
|
||||
@@ -367,7 +360,7 @@ int32_t esp8266_deauth_app(void* p)
|
||||
#endif // ENABLE_MODULE_DETECTION
|
||||
|
||||
ValueMutex app_data_mutex;
|
||||
if (!init_mutex(&app_data_mutex, app, sizeof(SWiFiDeauthApp))) {
|
||||
if(!init_mutex(&app_data_mutex, app, sizeof(SWiFiDeauthApp))) {
|
||||
DEAUTH_APP_LOG_E("cannot create mutex\r\n");
|
||||
free(app);
|
||||
return 255;
|
||||
@@ -406,16 +399,13 @@ int32_t esp8266_deauth_app(void* p)
|
||||
DEAUTH_APP_LOG_I("UART thread allocated");
|
||||
|
||||
SPluginEvent event;
|
||||
for(bool processing = true; processing;)
|
||||
{
|
||||
for(bool processing = true; processing;) {
|
||||
FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100);
|
||||
SWiFiDeauthApp* app = (SWiFiDeauthApp*)acquire_mutex_block(&app_data_mutex);
|
||||
|
||||
#if ENABLE_MODULE_DETECTION
|
||||
if(!app->m_wifiDeauthModuleAttached)
|
||||
{
|
||||
if(furi_hal_gpio_read(&gpio_ext_pc0) == false)
|
||||
{
|
||||
if(!app->m_wifiDeauthModuleAttached) {
|
||||
if(furi_hal_gpio_read(&gpio_ext_pc0) == false) {
|
||||
DEAUTH_APP_LOG_I("Module Attached");
|
||||
app->m_wifiDeauthModuleAttached = true;
|
||||
#if ENABLE_MODULE_POWER
|
||||
@@ -428,65 +418,46 @@ int32_t esp8266_deauth_app(void* p)
|
||||
}
|
||||
#endif // ENABLE_MODULE_DETECTION
|
||||
|
||||
if(event_status == FuriStatusOk)
|
||||
{
|
||||
if(event.m_type == EventTypeKey)
|
||||
{
|
||||
if (app->m_wifiDeauthModuleInitialized)
|
||||
{
|
||||
if (app->m_context == ModuleActive)
|
||||
{
|
||||
switch (event.m_input.key)
|
||||
{
|
||||
if(event_status == FuriStatusOk) {
|
||||
if(event.m_type == EventTypeKey) {
|
||||
if(app->m_wifiDeauthModuleInitialized) {
|
||||
if(app->m_context == ModuleActive) {
|
||||
switch(event.m_input.key) {
|
||||
case InputKeyUp:
|
||||
if (event.m_input.type == InputTypePress)
|
||||
{
|
||||
if(event.m_input.type == InputTypePress) {
|
||||
DEAUTH_APP_LOG_I("Up Press");
|
||||
furi_hal_gpio_write(app->m_GpioButtons.pinButtonUp, false);
|
||||
}
|
||||
else if (event.m_input.type == InputTypeRelease)
|
||||
{
|
||||
} else if(event.m_input.type == InputTypeRelease) {
|
||||
DEAUTH_APP_LOG_I("Up Release");
|
||||
furi_hal_gpio_write(app->m_GpioButtons.pinButtonUp, true);
|
||||
}
|
||||
break;
|
||||
case InputKeyDown:
|
||||
if (event.m_input.type == InputTypePress)
|
||||
{
|
||||
if(event.m_input.type == InputTypePress) {
|
||||
DEAUTH_APP_LOG_I("Down Press");
|
||||
furi_hal_gpio_write(app->m_GpioButtons.pinButtonDown, false);
|
||||
}
|
||||
else if (event.m_input.type == InputTypeRelease)
|
||||
{
|
||||
} else if(event.m_input.type == InputTypeRelease) {
|
||||
DEAUTH_APP_LOG_I("Down Release");
|
||||
furi_hal_gpio_write(app->m_GpioButtons.pinButtonDown, true);
|
||||
}
|
||||
break;
|
||||
case InputKeyOk:
|
||||
if (event.m_input.type == InputTypePress)
|
||||
{
|
||||
if(event.m_input.type == InputTypePress) {
|
||||
DEAUTH_APP_LOG_I("OK Press");
|
||||
furi_hal_gpio_write(app->m_GpioButtons.pinButtonOK, false);
|
||||
}
|
||||
else if (event.m_input.type == InputTypeRelease)
|
||||
{
|
||||
} else if(event.m_input.type == InputTypeRelease) {
|
||||
DEAUTH_APP_LOG_I("OK Release");
|
||||
furi_hal_gpio_write(app->m_GpioButtons.pinButtonOK, true);
|
||||
}
|
||||
break;
|
||||
case InputKeyBack:
|
||||
if (event.m_input.type == InputTypePress)
|
||||
{
|
||||
if(event.m_input.type == InputTypePress) {
|
||||
DEAUTH_APP_LOG_I("Back Press");
|
||||
furi_hal_gpio_write(app->m_GpioButtons.pinButtonBack, false);
|
||||
}
|
||||
else if (event.m_input.type == InputTypeRelease)
|
||||
{
|
||||
} else if(event.m_input.type == InputTypeRelease) {
|
||||
DEAUTH_APP_LOG_I("Back Release");
|
||||
furi_hal_gpio_write(app->m_GpioButtons.pinButtonBack, true);
|
||||
}
|
||||
else if (event.m_input.type == InputTypeLong)
|
||||
{
|
||||
} else if(event.m_input.type == InputTypeLong) {
|
||||
DEAUTH_APP_LOG_I("Back Long");
|
||||
processing = false;
|
||||
}
|
||||
@@ -495,27 +466,21 @@ int32_t esp8266_deauth_app(void* p)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(event.m_input.key == InputKeyBack)
|
||||
{
|
||||
if(event.m_input.type == InputTypeShort || event.m_input.type == InputTypeLong)
|
||||
{
|
||||
} else {
|
||||
if(event.m_input.key == InputKeyBack) {
|
||||
if(event.m_input.type == InputTypeShort ||
|
||||
event.m_input.type == InputTypeLong) {
|
||||
processing = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
DEAUTH_APP_LOG_D("osMessageQueue: event timeout");
|
||||
}
|
||||
|
||||
#if ENABLE_MODULE_DETECTION
|
||||
if(app->m_wifiDeauthModuleAttached && furi_hal_gpio_read(&gpio_ext_pc0) == true)
|
||||
{
|
||||
if(app->m_wifiDeauthModuleAttached && furi_hal_gpio_read(&gpio_ext_pc0) == true) {
|
||||
DEAUTH_APP_LOG_D("Module Disconnected - Exit");
|
||||
processing = false;
|
||||
app->m_wifiDeauthModuleAttached = false;
|
||||
@@ -558,8 +523,6 @@ int32_t esp8266_deauth_app(void* p)
|
||||
|
||||
delete_mutex(&app_data_mutex);
|
||||
|
||||
|
||||
|
||||
// Free rest
|
||||
free(app);
|
||||
|
||||
|
||||
@@ -136,7 +136,7 @@ static void tetris_game_render_callback(Canvas* const canvas, void* ctx) {
|
||||
if(tetris_state->gameState == GameStatePlaying) {
|
||||
char buffer2[6];
|
||||
snprintf(buffer2, sizeof(buffer2), "%u", tetris_state->numLines);
|
||||
canvas_draw_str_aligned(canvas, 58,10, AlignRight, AlignBottom, buffer2);
|
||||
canvas_draw_str_aligned(canvas, 58, 10, AlignRight, AlignBottom, buffer2);
|
||||
}
|
||||
|
||||
if(tetris_state->gameState == GameStateGameOver) {
|
||||
|
||||
Reference in New Issue
Block a user