Skip to content

Commit

Permalink
docs: pre-commit with pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
sabas1080 committed Aug 6, 2024
1 parent 904efc9 commit 50808c9
Show file tree
Hide file tree
Showing 17 changed files with 1,856 additions and 1,779 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
.vscode
.vscode
165 changes: 87 additions & 78 deletions Canbus_app/app_user.c
Original file line number Diff line number Diff line change
@@ -1,126 +1,135 @@
#include "app_user.h"

void makePaths(App* app) {
furi_assert(app);
if(!storage_simply_mkdir(app->storage, PATHAPPEXT)) {
dialog_message_show_storage_error(app->dialogs, "Cannot create\napp folder");
}
if(!storage_simply_mkdir(app->storage, PATHLOGS)) {
dialog_message_show_storage_error(app->dialogs, "Cannot create\nlogs folder");
}
furi_assert(app);
if (!storage_simply_mkdir(app->storage, PATHAPPEXT)) {
dialog_message_show_storage_error(app->dialogs,
"Cannot create\napp folder");
}
if (!storage_simply_mkdir(app->storage, PATHLOGS)) {
dialog_message_show_storage_error(app->dialogs,
"Cannot create\nlogs folder");
}
}

static bool app_scene_costum_callback(void* context, uint32_t costum_event) {
furi_assert(context);
App* app = context;
return scene_manager_handle_custom_event(app->scene_manager, costum_event);
furi_assert(context);
App* app = context;
return scene_manager_handle_custom_event(app->scene_manager, costum_event);
}

static bool app_scene_back_event(void* context) {
furi_assert(context);
App* app = context;
return scene_manager_handle_back_event(app->scene_manager);
furi_assert(context);
App* app = context;
return scene_manager_handle_back_event(app->scene_manager);
}

static void app_tick_event(void* context) {
furi_assert(context);
App* app = context;
UNUSED(app);
furi_assert(context);
App* app = context;
UNUSED(app);
}

static App* app_alloc() {
App* app = malloc(sizeof(App));
app->scene_manager = scene_manager_alloc(&app_scene_handlers, app);
app->view_dispatcher = view_dispatcher_alloc();
view_dispatcher_enable_queue(app->view_dispatcher);
view_dispatcher_set_custom_event_callback(app->view_dispatcher, app_scene_costum_callback);
view_dispatcher_set_event_callback_context(app->view_dispatcher, app);
view_dispatcher_set_navigation_event_callback(app->view_dispatcher, app_scene_back_event);
view_dispatcher_set_tick_event_callback(app->view_dispatcher, app_tick_event, 100);
App* app = malloc(sizeof(App));
app->scene_manager = scene_manager_alloc(&app_scene_handlers, app);
app->view_dispatcher = view_dispatcher_alloc();
view_dispatcher_enable_queue(app->view_dispatcher);
view_dispatcher_set_custom_event_callback(app->view_dispatcher,
app_scene_costum_callback);
view_dispatcher_set_event_callback_context(app->view_dispatcher, app);
view_dispatcher_set_navigation_event_callback(app->view_dispatcher,
app_scene_back_event);
view_dispatcher_set_tick_event_callback(app->view_dispatcher, app_tick_event,
100);

app->widget = widget_alloc();
view_dispatcher_add_view(app->view_dispatcher, ViewWidget, widget_get_view(app->widget));
app->widget = widget_alloc();
view_dispatcher_add_view(app->view_dispatcher, ViewWidget,
widget_get_view(app->widget));

app->submenu = submenu_alloc();
view_dispatcher_add_view(app->view_dispatcher, SubmenuView, submenu_get_view(app->submenu));
app->submenu = submenu_alloc();
view_dispatcher_add_view(app->view_dispatcher, SubmenuView,
submenu_get_view(app->submenu));

app->varList = variable_item_list_alloc();
view_dispatcher_add_view(
app->view_dispatcher, VarListView, variable_item_list_get_view(app->varList));
app->varList = variable_item_list_alloc();
view_dispatcher_add_view(app->view_dispatcher, VarListView,
variable_item_list_get_view(app->varList));

app->textBox = text_box_alloc();
view_dispatcher_add_view(app->view_dispatcher, TextBoxView, text_box_get_view(app->textBox));
app->textBox = text_box_alloc();
view_dispatcher_add_view(app->view_dispatcher, TextBoxView,
text_box_get_view(app->textBox));

app->input_byte_value = byte_input_alloc();
view_dispatcher_add_view(
app->view_dispatcher, InputByteView, byte_input_get_view(app->input_byte_value));
app->input_byte_value = byte_input_alloc();
view_dispatcher_add_view(app->view_dispatcher, InputByteView,
byte_input_get_view(app->input_byte_value));

app->dialogs = furi_record_open(RECORD_DIALOGS);
app->storage = furi_record_open(RECORD_STORAGE);
app->log_file = storage_file_alloc(app->storage);
app->dialogs = furi_record_open(RECORD_DIALOGS);
app->storage = furi_record_open(RECORD_STORAGE);
app->log_file = storage_file_alloc(app->storage);

app->text = furi_string_alloc();
app->data = furi_string_alloc();
app->text = furi_string_alloc();
app->data = furi_string_alloc();

app->mcp_can = mcp_alloc(MCP_NORMAL, MCP_16MHZ, MCP_500KBPS);
app->mcp_can = mcp_alloc(MCP_NORMAL, MCP_16MHZ, MCP_500KBPS);

app->frameArray = (CANFRAME*)malloc(100 * sizeof(CANFRAME));
app->frameArray = (CANFRAME*) malloc(100 * sizeof(CANFRAME));

app->frame_to_send = malloc(sizeof(CANFRAME));
app->frame_to_send = malloc(sizeof(CANFRAME));

makePaths(app);
makePaths(app);

return app;
return app;
}

static void app_free(App* app) {
furi_assert(app);
furi_assert(app);

view_dispatcher_remove_view(app->view_dispatcher, SubmenuView);
view_dispatcher_remove_view(app->view_dispatcher, ViewWidget);
view_dispatcher_remove_view(app->view_dispatcher, TextBoxView);
view_dispatcher_remove_view(app->view_dispatcher, VarListView);
view_dispatcher_remove_view(app->view_dispatcher, InputByteView);
view_dispatcher_remove_view(app->view_dispatcher, SubmenuView);
view_dispatcher_remove_view(app->view_dispatcher, ViewWidget);
view_dispatcher_remove_view(app->view_dispatcher, TextBoxView);
view_dispatcher_remove_view(app->view_dispatcher, VarListView);
view_dispatcher_remove_view(app->view_dispatcher, InputByteView);

scene_manager_free(app->scene_manager);
view_dispatcher_free(app->view_dispatcher);
scene_manager_free(app->scene_manager);
view_dispatcher_free(app->view_dispatcher);

widget_free(app->widget);
submenu_free(app->submenu);
text_box_free(app->textBox);
byte_input_free(app->input_byte_value);
widget_free(app->widget);
submenu_free(app->submenu);
text_box_free(app->textBox);
byte_input_free(app->input_byte_value);

furi_string_free(app->text);
furi_string_free(app->data);
furi_string_free(app->text);
furi_string_free(app->data);

if(app->log_file && storage_file_is_open(app->log_file)) {
storage_file_close(app->log_file);
}
if (app->log_file && storage_file_is_open(app->log_file)) {
storage_file_close(app->log_file);
}

storage_file_free(app->log_file);
furi_record_close(RECORD_STORAGE);
furi_record_close(RECORD_DIALOGS);
storage_file_free(app->log_file);
furi_record_close(RECORD_STORAGE);
furi_record_close(RECORD_DIALOGS);

free(app->frameArray);
free(app->frameArray);

free(app);
free(app);
}

int app_main(void* p) {
UNUSED(p);
UNUSED(p);

App* app = app_alloc();
App* app = app_alloc();

Gui* gui = furi_record_open(RECORD_GUI);
Gui* gui = furi_record_open(RECORD_GUI);

view_dispatcher_attach_to_gui(app->view_dispatcher, gui, ViewDispatcherTypeFullscreen);
view_dispatcher_attach_to_gui(app->view_dispatcher, gui,
ViewDispatcherTypeFullscreen);

scene_manager_next_scene(app->scene_manager, app_scene_main_menu);
scene_manager_next_scene(app->scene_manager, app_scene_main_menu);

view_dispatcher_run(app->view_dispatcher);
furi_record_close(RECORD_GUI);
view_dispatcher_run(app->view_dispatcher);
furi_record_close(RECORD_GUI);

app_free(app);
app_free(app);

return 0;
}
return 0;
}
139 changes: 71 additions & 68 deletions Canbus_app/app_user.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,92 +2,96 @@
#include <furi_hal.h>
#include <gui/gui.h>

#include <gui/view_dispatcher.h>
#include <gui/scene_manager.h>
#include <storage/storage.h>
#include <dialogs/dialogs.h>
#include <gui/modules/widget.h>
#include <gui/modules/byte_input.h>
#include <gui/modules/submenu.h>
#include <gui/modules/variable_item_list.h>
#include <gui/modules/text_box.h>
#include <gui/modules/byte_input.h>
#include <gui/modules/text_input.h>
#include <gui/modules/variable_item_list.h>
#include <gui/modules/widget.h>
#include <gui/scene_manager.h>
#include <gui/view_dispatcher.h>
#include <storage/storage.h>

#include "scenes_config/app_scene_functions.h"

#include "libraries/mcp_can_2515.h"

#define PATHAPP "apps_data/canbus"
#define PATHAPP "apps_data/canbus"
#define PATHAPPEXT EXT_PATH(PATHAPP)
#define PATHLOGS PATHAPPEXT "/logs"
#define PATHLOGS PATHAPPEXT "/logs"

#define DEVICE_NO_CONNECTED (0xFF)

typedef enum {
WorkerflagStop = (1 << 0),
WorkerflagReceived = (1 << 1),
WorkerflagStop = (1 << 0),
WorkerflagReceived = (1 << 1),
} WorkerEvtFlags;

#define WORKER_ALL_RX_EVENTS (WorkerflagStop | WorkerflagReceived)

typedef struct {
MCP2515* mcp_can;
CANFRAME can_frame;
CANFRAME* frameArray;
CANFRAME* frame_to_send;

uint32_t time;
uint32_t times[100];
uint32_t current_time[100];

FuriThread* thread;
SceneManager* scene_manager;
ViewDispatcher* view_dispatcher;
Widget* widget;
Submenu* submenu;
VariableItemList* varList;
TextBox* textBox;
ByteInput* input_byte_value;

FuriString* text;
FuriString* data;

Storage* storage;
DialogsApp* dialogs;
File* log_file;
char log_file_path[100];
bool log_file_ready;
uint8_t save_logs;

uint32_t sniffer_index;
uint32_t sniffer_index_aux;

uint8_t num_of_devices;
uint8_t sender_selected_item;
uint8_t sender_id_compose[4];

uint64_t size_of_storage;
MCP2515* mcp_can;
CANFRAME can_frame;
CANFRAME* frameArray;
CANFRAME* frame_to_send;

uint32_t time;
uint32_t times[100];
uint32_t current_time[100];

FuriThread* thread;
SceneManager* scene_manager;
ViewDispatcher* view_dispatcher;
Widget* widget;
Submenu* submenu;
VariableItemList* varList;
TextBox* textBox;
ByteInput* input_byte_value;

FuriString* text;
FuriString* data;

Storage* storage;
DialogsApp* dialogs;
File* log_file;
char log_file_path[100];
bool log_file_ready;
uint8_t save_logs;

uint32_t sniffer_index;
uint32_t sniffer_index_aux;

uint8_t num_of_devices;
uint8_t sender_selected_item;
uint8_t sender_id_compose[4];

uint64_t size_of_storage;
} App;

// This is for the menu Options
typedef enum {
SniffingTestOption,
SenderOption,
ReadLOGOption,
SettingsOption,
AboutUsOption,
SniffingTestOption,
SenderOption,
ReadLOGOption,
SettingsOption,
AboutUsOption,
} MainMenuOptions;

typedef enum {
SniffingOptionEvent,
SenderOptionEvent,
SettingsOptionEvent,
ReadLOGOptionEvent,
AboutUsEvent,
SniffingOptionEvent,
SenderOptionEvent,
SettingsOptionEvent,
ReadLOGOptionEvent,
AboutUsEvent,
} MainMenuEvents;

// This is for the Setting Options
typedef enum { BitrateOption, CristyalClkOption, SaveLogsOption } OptionSettings;
typedef enum {
BitrateOption,
CristyalClkOption,
SaveLogsOption
} OptionSettings;
typedef enum { BitrateOptionEvent, CristyalClkOptionEvent } SettingsMenuEvent;
typedef enum { ChooseIdEvent, SetIdEvent, ReturnEvent } SenderEvents;

Expand All @@ -102,16 +106,15 @@ typedef enum { ButtonGetPressed } ButtonPressedEvent;

// Views in the App
typedef enum {
SubmenuView,
ViewWidget,
VarListView,
TextBoxView,
DialogInfoView,
InputByteView,
SubmenuView,
ViewWidget,
VarListView,
TextBoxView,
DialogInfoView,
InputByteView,
} scenesViews;

char* sequential_file_resolve_path(
Storage* storage,
const char* dir,
const char* prefix,
const char* extension);
char* sequential_file_resolve_path(Storage* storage,
const char* dir,
const char* prefix,
const char* extension);
Loading

1 comment on commit 50808c9

@RogueMaster
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI this build has some compile errors on dev builds 😄

Please sign in to comment.