This commit is contained in:
RogueMaster
2022-10-17 00:14:38 -04:00
parent 325fbd32ef
commit 084e9aaf6e
21 changed files with 1021 additions and 1 deletions

View File

@@ -0,0 +1,154 @@
#include "module_view.h"
#include <furi.h>
#include <gui/elements.h>
#include <notification/notification.h>
#include <notification/notification_messages.h>
#include <furi_hal_uart.h>
#define MODULE_CONTROL_COMMAND_CONFIG_ON 'c'
#define MODULE_CONTROL_COMMAND_CONFIG_OFF 'd'
#define FLIPPERZERO_SERIAL_BAUD 115200
bool configState;
typedef enum ESerialCommand
{
ESerialCommand_Config_On,
ESerialCommand_Config_Off
} ESerialCommand;
struct ModuleView {
View* view;
};
typedef struct {
bool right_pressed;
bool connected;
} ModuleViewModel;
/*
static void Shake(void) {
NotificationApp* notification = furi_record_open(RECORD_NOTIFICATION);
notification_message(notification, &sequence_single_vibro);
furi_record_close(RECORD_NOTIFICATION);
}
*/
void send_serial_command_module(ESerialCommand command)
{
uint8_t data[1] = { 0 };
switch(command)
{
case ESerialCommand_Config_On:
data[0] = MODULE_CONTROL_COMMAND_CONFIG_ON;
break;
case ESerialCommand_Config_Off:
data[0] = MODULE_CONTROL_COMMAND_CONFIG_OFF;
break;
default:
return;
};
furi_hal_uart_tx(FuriHalUartIdUSART1, data, 1);
}
static void module_view_draw_callback(Canvas* canvas, void* context) {
furi_assert(context);
ModuleViewModel* model = context;
canvas_clear(canvas);
canvas_set_color(canvas, ColorBlack);
canvas_draw_str_aligned(canvas, 64, 0, AlignCenter, AlignTop, "CONFIGURE MODULE");
canvas_draw_line(canvas, 0, 10, 128, 10);
canvas_draw_str_aligned(canvas, 64, 15, AlignCenter, AlignTop, "Press right to start the");
canvas_draw_str_aligned(canvas, 64, 25, AlignCenter, AlignTop, "configurator and connect");
canvas_draw_str_aligned(canvas, 64, 35, AlignCenter, AlignTop, "to ip 192.168.4.1 or press");
canvas_draw_str_aligned(canvas, 64, 45, AlignCenter, AlignTop, "and hold back to return");
canvas_draw_str_aligned(canvas, 64, 55, AlignCenter, AlignTop, "to the menu");
if(configState == false){
send_serial_command_module(ESerialCommand_Config_On);
configState = true;
}
// Right
if(model->right_pressed) {
}
}
static void module_view_process(ModuleView* module_view, InputEvent* event) {
with_view_model(
module_view->view, (ModuleViewModel * model) {
if(event->type == InputTypePress) {
if(event->key == InputKeyUp) {
} else if(event->key == InputKeyDown) {
} else if(event->key == InputKeyLeft) {
} else if(event->key == InputKeyRight) {
model->right_pressed = true;
} else if(event->key == InputKeyOk) {
} else if(event->key == InputKeyBack) {
}
} else if(event->type == InputTypeRelease) {
if(event->key == InputKeyUp) {
} else if(event->key == InputKeyDown) {
} else if(event->key == InputKeyLeft) {
} else if(event->key == InputKeyRight) {
model->right_pressed = false;
} else if(event->key == InputKeyOk) {
} else if(event->key == InputKeyBack) {
}
} else if(event->type == InputTypeShort) {
if(event->key == InputKeyBack) {
}
}
return true;
});
}
static bool module_view_input_callback(InputEvent* event, void* context) {
furi_assert(context);
ModuleView* module_view = context;
bool consumed = false;
if(event->type == InputTypeLong && event->key == InputKeyBack) {
send_serial_command_module(ESerialCommand_Config_Off);
configState = false;
} else {
module_view_process(module_view, event);
consumed = true;
}
return consumed;
}
ModuleView* module_view_alloc() {
ModuleView* module_view = malloc(sizeof(ModuleView));
module_view->view = view_alloc();
view_set_context(module_view->view, module_view);
view_allocate_model(module_view->view, ViewModelTypeLocking, sizeof(ModuleViewModel));
view_set_draw_callback(module_view->view, module_view_draw_callback);
view_set_input_callback(module_view->view, module_view_input_callback);
furi_hal_uart_set_br(FuriHalUartIdUSART1, FLIPPERZERO_SERIAL_BAUD);
configState = false;
return module_view;
}
void module_view_free(ModuleView* module_view) {
furi_assert(module_view);
view_free(module_view->view);
free(module_view);
}
View* module_view_get_view(ModuleView* module_view) {
furi_assert(module_view);
return module_view->view;
}
void module_view_set_data(ModuleView* module_view, bool connected) {
furi_assert(module_view);
with_view_model(
module_view->view, (ModuleViewModel * model) {
model->connected = connected;
return true;
});
}

View File

@@ -0,0 +1,11 @@
#pragma once
#include <gui/view.h>
typedef struct ModuleView ModuleView;
ModuleView* module_view_alloc();
void module_view_free(ModuleView* module_view);
View* module_view_get_view(ModuleView* module_view);

View File

@@ -0,0 +1,138 @@
#include "reboot_view.h"
#include <furi.h>
#include <gui/elements.h>
#include <notification/notification.h>
#include <notification/notification_messages.h>
#include <furi_hal_uart.h>
#define MODULE_CONTROL_COMMAND_REBOOT 'r'
#define FLIPPERZERO_SERIAL_BAUD 115200
typedef enum ESerialCommand
{
ESerialCommand_Reboot
} ESerialCommand;
struct RebootView {
View* view;
};
typedef struct {
bool right_pressed;
bool connected;
} RebootViewModel;
static void Shake(void) {
NotificationApp* notification = furi_record_open(RECORD_NOTIFICATION);
notification_message(notification, &sequence_single_vibro);
furi_record_close(RECORD_NOTIFICATION);
}
void send_serial_command_reboot(ESerialCommand command)
{
uint8_t data[1] = { 0 };
switch(command)
{
case ESerialCommand_Reboot:
data[0] = MODULE_CONTROL_COMMAND_REBOOT;
break;
default:
return;
};
furi_hal_uart_tx(FuriHalUartIdUSART1, data, 1);
}
static void reboot_view_draw_callback(Canvas* canvas, void* context) {
furi_assert(context);
RebootViewModel* model = context;
canvas_clear(canvas);
canvas_set_color(canvas, ColorBlack);
canvas_draw_str_aligned(canvas, 64, 0, AlignCenter, AlignTop, "REBOOT MODULE");
canvas_draw_line(canvas, 0, 10, 128, 10);
canvas_draw_str_aligned(canvas, 64, 15, AlignCenter, AlignTop, "Press right to restart the");
canvas_draw_str_aligned(canvas, 64, 25, AlignCenter, AlignTop, "module or press and hold");
canvas_draw_str_aligned(canvas, 64, 35, AlignCenter, AlignTop, "back to return to the menu");
// Right
if(model->right_pressed) {
}
}
static void reboot_view_process(RebootView* reboot_view, InputEvent* event) {
with_view_model(
reboot_view->view, (RebootViewModel * model) {
if(event->type == InputTypePress) {
if(event->key == InputKeyUp) {
} else if(event->key == InputKeyDown) {
} else if(event->key == InputKeyLeft) {
} else if(event->key == InputKeyRight) {
model->right_pressed = true;
Shake();
send_serial_command_reboot(ESerialCommand_Reboot);
} else if(event->key == InputKeyOk) {
} else if(event->key == InputKeyBack) {
}
} else if(event->type == InputTypeRelease) {
if(event->key == InputKeyUp) {
} else if(event->key == InputKeyDown) {
} else if(event->key == InputKeyLeft) {
} else if(event->key == InputKeyRight) {
model->right_pressed = false;
} else if(event->key == InputKeyOk) {
} else if(event->key == InputKeyBack) {
}
} else if(event->type == InputTypeShort) {
if(event->key == InputKeyBack) {
}
}
return true;
});
}
static bool reboot_view_input_callback(InputEvent* event, void* context) {
furi_assert(context);
RebootView* reboot_view = context;
bool consumed = false;
if(event->type == InputTypeLong && event->key == InputKeyBack) {
} else {
reboot_view_process(reboot_view, event);
consumed = true;
}
return consumed;
}
RebootView* reboot_view_alloc() {
RebootView* reboot_view = malloc(sizeof(RebootView));
reboot_view->view = view_alloc();
view_set_context(reboot_view->view, reboot_view);
view_allocate_model(reboot_view->view, ViewModelTypeLocking, sizeof(RebootViewModel));
view_set_draw_callback(reboot_view->view, reboot_view_draw_callback);
view_set_input_callback(reboot_view->view, reboot_view_input_callback);
furi_hal_uart_set_br(FuriHalUartIdUSART1, FLIPPERZERO_SERIAL_BAUD);
return reboot_view;
}
void reboot_view_free(RebootView* reboot_view) {
furi_assert(reboot_view);
view_free(reboot_view->view);
free(reboot_view);
}
View* reboot_view_get_view(RebootView* reboot_view) {
furi_assert(reboot_view);
return reboot_view->view;
}
void reboot_view_set_data(RebootView* reboot_view, bool connected) {
furi_assert(reboot_view);
with_view_model(
reboot_view->view, (RebootViewModel * model) {
model->connected = connected;
return true;
});
}

View File

@@ -0,0 +1,11 @@
#pragma once
#include <gui/view.h>
typedef struct RebootView RebootView;
RebootView* reboot_view_alloc();
void reboot_view_free(RebootView* reboot_view);
View* reboot_view_get_view(RebootView* reboot_view);

View File

@@ -0,0 +1,138 @@
#include "reset_view.h"
#include <furi.h>
#include <gui/elements.h>
#include <notification/notification.h>
#include <notification/notification_messages.h>
#include <furi_hal_uart.h>
#define MODULE_CONTROL_COMMAND_RESET 'a'
#define FLIPPERZERO_SERIAL_BAUD 115200
typedef enum ESerialCommand
{
ESerialCommand_Reset
} ESerialCommand;
struct ResetView {
View* view;
};
typedef struct {
bool right_pressed;
bool connected;
} ResetViewModel;
static void Shake(void) {
NotificationApp* notification = furi_record_open(RECORD_NOTIFICATION);
notification_message(notification, &sequence_single_vibro);
furi_record_close(RECORD_NOTIFICATION);
}
void send_serial_command_reset(ESerialCommand command)
{
uint8_t data[1] = { 0 };
switch(command)
{
case ESerialCommand_Reset:
data[0] = MODULE_CONTROL_COMMAND_RESET;
break;
default:
return;
};
furi_hal_uart_tx(FuriHalUartIdUSART1, data, 1);
}
static void reset_view_draw_callback(Canvas* canvas, void* context) {
furi_assert(context);
ResetViewModel* model = context;
canvas_clear(canvas);
canvas_set_color(canvas, ColorBlack);
canvas_draw_str_aligned(canvas, 64, 0, AlignCenter, AlignTop, "RESET MODULE");
canvas_draw_line(canvas, 0, 10, 128, 10);
canvas_draw_str_aligned(canvas, 64, 15, AlignCenter, AlignTop, "Press right to reset");
canvas_draw_str_aligned(canvas, 64, 25, AlignCenter, AlignTop, "module or press and hold");
canvas_draw_str_aligned(canvas, 64, 35, AlignCenter, AlignTop, "back to return to the menu");
// Right
if(model->right_pressed) {
}
}
static void reset_view_process(ResetView* reset_view, InputEvent* event) {
with_view_model(
reset_view->view, (ResetViewModel * model) {
if(event->type == InputTypePress) {
if(event->key == InputKeyUp) {
} else if(event->key == InputKeyDown) {
} else if(event->key == InputKeyLeft) {
} else if(event->key == InputKeyRight) {
model->right_pressed = true;
Shake();
send_serial_command_reset(ESerialCommand_Reset);
} else if(event->key == InputKeyOk) {
} else if(event->key == InputKeyBack) {
}
} else if(event->type == InputTypeRelease) {
if(event->key == InputKeyUp) {
} else if(event->key == InputKeyDown) {
} else if(event->key == InputKeyLeft) {
} else if(event->key == InputKeyRight) {
model->right_pressed = false;
} else if(event->key == InputKeyOk) {
} else if(event->key == InputKeyBack) {
}
} else if(event->type == InputTypeShort) {
if(event->key == InputKeyBack) {
}
}
return true;
});
}
static bool reset_view_input_callback(InputEvent* event, void* context) {
furi_assert(context);
ResetView* reset_view = context;
bool consumed = false;
if(event->type == InputTypeLong && event->key == InputKeyBack) {
} else {
reset_view_process(reset_view, event);
consumed = true;
}
return consumed;
}
ResetView* reset_view_alloc() {
ResetView* reset_view = malloc(sizeof(ResetView));
reset_view->view = view_alloc();
view_set_context(reset_view->view, reset_view);
view_allocate_model(reset_view->view, ViewModelTypeLocking, sizeof(ResetViewModel));
view_set_draw_callback(reset_view->view, reset_view_draw_callback);
view_set_input_callback(reset_view->view, reset_view_input_callback);
furi_hal_uart_set_br(FuriHalUartIdUSART1, FLIPPERZERO_SERIAL_BAUD);
return reset_view;
}
void reset_view_free(ResetView* reset_view) {
furi_assert(reset_view);
view_free(reset_view->view);
free(reset_view);
}
View* reset_view_get_view(ResetView* reset_view) {
furi_assert(reset_view);
return reset_view->view;
}
void reset_view_set_data(ResetView* reset_view, bool connected) {
furi_assert(reset_view);
with_view_model(
reset_view->view, (ResetViewModel * model) {
model->connected = connected;
return true;
});
}

View File

@@ -0,0 +1,11 @@
#pragma once
#include <gui/view.h>
typedef struct ResetView ResetView;
ResetView* reset_view_alloc();
void reset_view_free(ResetView* reset_view);
View* reset_view_get_view(ResetView* reset_view);

View File

@@ -0,0 +1,138 @@
#include "send_view.h"
#include <furi.h>
#include <gui/elements.h>
#include <notification/notification.h>
#include <notification/notification_messages.h>
#include <furi_hal_uart.h>
#define MODULE_CONTROL_COMMAND_SEND 's'
#define FLIPPERZERO_SERIAL_BAUD 115200
typedef enum ESerialCommand
{
ESerialCommand_Send
} ESerialCommand;
struct SendView {
View* view;
};
typedef struct {
bool right_pressed;
bool connected;
} SendViewModel;
static void Shake(void) {
NotificationApp* notification = furi_record_open(RECORD_NOTIFICATION);
notification_message(notification, &sequence_single_vibro);
furi_record_close(RECORD_NOTIFICATION);
}
void send_serial_command_send(ESerialCommand command)
{
uint8_t data[1] = { 0 };
switch(command)
{
case ESerialCommand_Send:
data[0] = MODULE_CONTROL_COMMAND_SEND;
break;
default:
return;
};
furi_hal_uart_tx(FuriHalUartIdUSART1, data, 1);
}
static void send_view_draw_callback(Canvas* canvas, void* context) {
furi_assert(context);
SendViewModel* model = context;
canvas_clear(canvas);
canvas_set_color(canvas, ColorBlack);
canvas_draw_str_aligned(canvas, 64, 0, AlignCenter, AlignTop, "SEND MODULE");
canvas_draw_line(canvas, 0, 10, 128, 10);
canvas_draw_str_aligned(canvas, 64, 15, AlignCenter, AlignTop, "Press right to send IFTTT");
canvas_draw_str_aligned(canvas, 64, 25, AlignCenter, AlignTop, "command or press and hold");
canvas_draw_str_aligned(canvas, 64, 35, AlignCenter, AlignTop, "back to return to the menu");
// Right
if(model->right_pressed) {
}
}
static void send_view_process(SendView* send_view, InputEvent* event) {
with_view_model(
send_view->view, (SendViewModel * model) {
if(event->type == InputTypePress) {
if(event->key == InputKeyUp) {
} else if(event->key == InputKeyDown) {
} else if(event->key == InputKeyLeft) {
} else if(event->key == InputKeyRight) {
model->right_pressed = true;
Shake();
send_serial_command_send(ESerialCommand_Send);
} else if(event->key == InputKeyOk) {
} else if(event->key == InputKeyBack) {
}
} else if(event->type == InputTypeRelease) {
if(event->key == InputKeyUp) {
} else if(event->key == InputKeyDown) {
} else if(event->key == InputKeyLeft) {
} else if(event->key == InputKeyRight) {
model->right_pressed = false;
} else if(event->key == InputKeyOk) {
} else if(event->key == InputKeyBack) {
}
} else if(event->type == InputTypeShort) {
if(event->key == InputKeyBack) {
}
}
return true;
});
}
static bool send_view_input_callback(InputEvent* event, void* context) {
furi_assert(context);
SendView* send_view = context;
bool consumed = false;
if(event->type == InputTypeLong && event->key == InputKeyBack) {
} else {
send_view_process(send_view, event);
consumed = true;
}
return consumed;
}
SendView* send_view_alloc() {
SendView* send_view = malloc(sizeof(SendView));
send_view->view = view_alloc();
view_set_context(send_view->view, send_view);
view_allocate_model(send_view->view, ViewModelTypeLocking, sizeof(SendViewModel));
view_set_draw_callback(send_view->view, send_view_draw_callback);
view_set_input_callback(send_view->view, send_view_input_callback);
furi_hal_uart_set_br(FuriHalUartIdUSART1, FLIPPERZERO_SERIAL_BAUD);
return send_view;
}
void send_view_free(SendView* send_view) {
furi_assert(send_view);
view_free(send_view->view);
free(send_view);
}
View* send_view_get_view(SendView* send_view) {
furi_assert(send_view);
return send_view->view;
}
void send_view_set_data(SendView* send_view, bool connected) {
furi_assert(send_view);
with_view_model(
send_view->view, (SendViewModel * model) {
model->connected = connected;
return true;
});
}

View File

@@ -0,0 +1,11 @@
#pragma once
#include <gui/view.h>
typedef struct SendView SendView;
SendView* send_view_alloc();
void send_view_free(SendView* send_view);
View* send_view_get_view(SendView* send_view);