Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into release-candidate
Browse files Browse the repository at this point in the history
  • Loading branch information
skotopes committed May 31, 2022
2 parents f82484d + 66dbb68 commit 287defd
Show file tree
Hide file tree
Showing 213 changed files with 6,255 additions and 3,198 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ env:

jobs:
main:
runs-on: [self-hosted,Office]
runs-on: [self-hosted,FlipperZero]
steps:
- name: 'Cleanup workspace'
uses: AutoModality/action-clean@v1
Expand Down Expand Up @@ -166,7 +166,7 @@ jobs:

compact:
if: ${{ !startsWith(github.ref, 'refs/tags') }}
runs-on: [self-hosted,koteeq]
runs-on: [self-hosted,FlipperZero]
steps:
- name: 'Cleanup workspace'
uses: AutoModality/action-clean@v1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint_c.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ env:

jobs:
lint_c_cpp:
runs-on: [self-hosted,Office]
runs-on: [self-hosted,FlipperZero]
steps:
- name: 'Cleanup workspace'
uses: AutoModality/action-clean@v1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/reindex.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
jobs:
reindex:
name: 'Reindex updates'
runs-on: [self-hosted,Office]
runs-on: [self-hosted,FlipperZero]
steps:
- name: Trigger reindex
uses: wei/curl@master
Expand Down
9 changes: 9 additions & 0 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
Welcome to [Flipper Zero](https://flipperzero.one/)'s Firmware repo!
Our goal is to create nice and clean code with good documentation, to make it a pleasure for everyone to work with.

# Clone the Repository

You should clone with
```shell
$ git clone --recursive https://github.com/flipperdevices/flipperzero-firmware.git
```

# Update firmware

[Get Latest Firmware from Update Server](https://update.flipperzero.one/)
Expand Down Expand Up @@ -74,6 +81,8 @@ Check `dist/` for build outputs.

Use **`flipper-z-{target}-full-{suffix}.dfu`** to flash your device.

If compilation fails, make sure all submodules are all initialized. Either clone with `--recursive` or use `git submodule update --init --recursive`.

# Build on Linux/macOS

## macOS Prerequisites
Expand Down
17 changes: 9 additions & 8 deletions applications/applications.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ extern int32_t vibro_test_app(void* p);
extern int32_t bt_hid_app(void* p);
extern int32_t battery_test_app(void* p);
extern int32_t text_box_test_app(void* p);
extern int32_t file_browser_app(void* p);

// Plugins
extern int32_t music_player_app(void* p);
Expand Down Expand Up @@ -419,14 +420,6 @@ const FlipperApplication FLIPPER_DEBUG_APPS[] = {
.flags = FlipperApplicationFlagDefault},
#endif

#ifdef APP_SCENED
{.app = scened_app,
.name = "Templated Scene",
.stack_size = 1024,
.icon = NULL,
.flags = FlipperApplicationFlagDefault},
#endif

#ifdef APP_LF_RFID
{.app = lfrfid_debug_app,
.name = "LF-RFID Debug",
Expand Down Expand Up @@ -459,6 +452,14 @@ const FlipperApplication FLIPPER_DEBUG_APPS[] = {
.flags = FlipperApplicationFlagDefault},
#endif

#ifdef APP_FILE_BROWSER_TEST
{.app = file_browser_app,
.name = "File Browser test",
.stack_size = 2048,
.icon = &A_BadUsb_14,
.flags = FlipperApplicationFlagDefault},
#endif

#ifdef APP_BATTERY_TEST
{.app = battery_test_app,
.name = "Battery Test",
Expand Down
6 changes: 6 additions & 0 deletions applications/applications.mk
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ APP_USB_MOUSE = 1
APP_BAD_USB = 1
APP_U2F = 1
APP_UART_ECHO = 1
APP_FILE_BROWSER_TEST = 1
endif


Expand Down Expand Up @@ -207,6 +208,11 @@ CFLAGS += -DAPP_KEYPAD_TEST
SRV_GUI = 1
endif

APP_FILE_BROWSER_TEST ?= 0
ifeq ($(APP_FILE_BROWSER_TEST), 1)
CFLAGS += -DAPP_FILE_BROWSER_TEST
SRV_GUI = 1
endif

APP_ACCESSOR ?= 0
ifeq ($(APP_ACCESSOR), 1)
Expand Down
37 changes: 9 additions & 28 deletions applications/bad_usb/bad_usb_app.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "bad_usb_app_i.h"
#include "m-string.h"
#include <furi.h>
#include <furi_hal.h>
#include <storage/storage.h>
Expand All @@ -22,33 +23,13 @@ static void bad_usb_app_tick_event_callback(void* context) {
scene_manager_handle_tick_event(app->scene_manager);
}

static bool bad_usb_check_assets() {
Storage* fs_api = furi_record_open("storage");

File* dir = storage_file_alloc(fs_api);
bool ret = false;

if(storage_dir_open(dir, BAD_USB_APP_PATH_FOLDER)) {
ret = true;
}

storage_dir_close(dir);
storage_file_free(dir);

furi_record_close("storage");

return ret;
}

BadUsbApp* bad_usb_app_alloc(char* arg) {
BadUsbApp* app = malloc(sizeof(BadUsbApp));

string_init(app->file_path);

if(arg != NULL) {
string_t filename;
string_init(filename);
path_extract_filename_no_ext(arg, filename);
strncpy(app->file_name, string_get_cstr(filename), BAD_USB_FILE_NAME_LEN);
string_clear(filename);
string_set_str(app->file_path, arg);
}

app->gui = furi_record_open("gui");
Expand Down Expand Up @@ -83,13 +64,11 @@ BadUsbApp* bad_usb_app_alloc(char* arg) {
app->error = BadUsbAppErrorCloseRpc;
scene_manager_next_scene(app->scene_manager, BadUsbSceneError);
} else {
if(*app->file_name != '\0') {
if(!string_empty_p(app->file_path)) {
scene_manager_next_scene(app->scene_manager, BadUsbSceneWork);
} else if(bad_usb_check_assets()) {
scene_manager_next_scene(app->scene_manager, BadUsbSceneFileSelect);
} else {
app->error = BadUsbAppErrorNoFiles;
scene_manager_next_scene(app->scene_manager, BadUsbSceneError);
string_set_str(app->file_path, BAD_USB_APP_PATH_FOLDER);
scene_manager_next_scene(app->scene_manager, BadUsbSceneFileSelect);
}
}

Expand Down Expand Up @@ -117,6 +96,8 @@ void bad_usb_app_free(BadUsbApp* app) {
furi_record_close("notification");
furi_record_close("dialogs");

string_clear(app->file_path);

free(app);
}

Expand Down
3 changes: 1 addition & 2 deletions applications/bad_usb/bad_usb_app_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

#define BAD_USB_APP_PATH_FOLDER "/any/badusb"
#define BAD_USB_APP_EXTENSION ".txt"
#define BAD_USB_FILE_NAME_LEN 40

typedef enum {
BadUsbAppErrorNoFiles,
Expand All @@ -32,7 +31,7 @@ struct BadUsbApp {
Widget* widget;

BadUsbAppError error;
char file_name[BAD_USB_FILE_NAME_LEN + 1];
string_t file_path;
BadUsb* bad_usb_view;
BadUsbScript* bad_usb_script;
};
Expand Down
14 changes: 8 additions & 6 deletions applications/bad_usb/scenes/bad_usb_scene_file_select.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
static bool bad_usb_file_select(BadUsbApp* bad_usb) {
furi_assert(bad_usb);

// Input events and views are managed by file_select
bool res = dialog_file_select_show(
// Input events and views are managed by file_browser
bool res = dialog_file_browser_show(
bad_usb->dialogs,
BAD_USB_APP_PATH_FOLDER,
bad_usb->file_path,
bad_usb->file_path,
BAD_USB_APP_EXTENSION,
bad_usb->file_name,
sizeof(bad_usb->file_name),
NULL);
true,
&I_badusb_10px,
true);

return res;
}

Expand Down
9 changes: 5 additions & 4 deletions applications/bad_usb/scenes/bad_usb_scene_work.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include "../bad_usb_app_i.h"
#include "../views/bad_usb_view.h"
#include "furi_hal.h"
#include "m-string.h"
#include "toolbox/path.h"

void bad_usb_scene_work_ok_callback(InputType type, void* context) {
furi_assert(context);
Expand All @@ -28,10 +30,9 @@ void bad_usb_scene_work_on_enter(void* context) {
string_t file_name;
string_init(file_name);

bad_usb_set_file_name(app->bad_usb_view, app->file_name);
string_printf(
file_name, "%s/%s%s", BAD_USB_APP_PATH_FOLDER, app->file_name, BAD_USB_APP_EXTENSION);
app->bad_usb_script = bad_usb_script_open(file_name);
path_extract_filename(app->file_path, file_name, true);
bad_usb_set_file_name(app->bad_usb_view, string_get_cstr(file_name));
app->bad_usb_script = bad_usb_script_open(app->file_path);

string_clear(file_name);

Expand Down
8 changes: 5 additions & 3 deletions applications/bad_usb/views/bad_usb_view.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
#include "../bad_usb_script.h"
#include <gui/elements.h>

#define MAX_NAME_LEN 64

struct BadUsb {
View* view;
BadUsbOkCallback callback;
void* context;
};

typedef struct {
char* file_name;
char file_name[MAX_NAME_LEN];
BadUsbState state;
uint8_t anim_frame;
} BadUsbModel;
Expand Down Expand Up @@ -149,11 +151,11 @@ void bad_usb_set_ok_callback(BadUsb* bad_usb, BadUsbOkCallback callback, void* c
});
}

void bad_usb_set_file_name(BadUsb* bad_usb, char* name) {
void bad_usb_set_file_name(BadUsb* bad_usb, const char* name) {
furi_assert(name);
with_view_model(
bad_usb->view, (BadUsbModel * model) {
model->file_name = name;
strncpy(model->file_name, name, MAX_NAME_LEN);
return true;
});
}
Expand Down
2 changes: 1 addition & 1 deletion applications/bad_usb/views/bad_usb_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ View* bad_usb_get_view(BadUsb* bad_usb);

void bad_usb_set_ok_callback(BadUsb* bad_usb, BadUsbOkCallback callback, void* context);

void bad_usb_set_file_name(BadUsb* bad_usb, char* name);
void bad_usb_set_file_name(BadUsb* bad_usb, const char* name);

void bad_usb_set_state(BadUsb* bad_usb, BadUsbState* st);
31 changes: 24 additions & 7 deletions applications/bt/bt_service/bt.c
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ static bool bt_pin_code_verify_event_handler(Bt* bt, uint32_t pin) {
string_init_printf(pin_str, "Verify code\n%06d", pin);
dialog_message_set_text(
bt->dialog_message, string_get_cstr(pin_str), 64, 4, AlignCenter, AlignTop);
dialog_message_set_buttons(bt->dialog_message, "Cancel", "Ok", NULL);
dialog_message_set_buttons(bt->dialog_message, "Cancel", "OK", NULL);
DialogMessageButton button = dialog_message_show(bt->dialogs, bt->dialog_message);
string_clear(pin_str);
return button == DialogMessageButtonCenter;
Expand All @@ -91,11 +91,16 @@ static void bt_battery_level_changed_callback(const void* _event, void* context)
furi_assert(context);

Bt* bt = context;
BtMessage message = {};
const PowerEvent* event = _event;
if(event->type == PowerEventTypeBatteryLevelChanged) {
BtMessage message = {
.type = BtMessageTypeUpdateBatteryLevel,
.data.battery_level = event->data.battery_level};
message.type = BtMessageTypeUpdateBatteryLevel;
message.data.battery_level = event->data.battery_level;
furi_check(osMessageQueuePut(bt->message_queue, &message, 0, osWaitForever) == osOK);
} else if(
event->type == PowerEventTypeStartCharging || event->type == PowerEventTypeFullyCharged ||
event->type == PowerEventTypeStopCharging) {
message.type = BtMessageTypeUpdatePowerState;
furi_check(osMessageQueuePut(bt->message_queue, &message, 0, osWaitForever) == osOK);
}
}
Expand Down Expand Up @@ -167,7 +172,11 @@ static void bt_rpc_send_bytes_callback(void* context, uint8_t* bytes, size_t byt
furi_assert(context);
Bt* bt = context;

osEventFlagsClear(bt->rpc_event, BT_RPC_EVENT_ALL);
if(osEventFlagsGet(bt->rpc_event) & BT_RPC_EVENT_DISCONNECTED) {
// Early stop from sending if we're already disconnected
return;
}
osEventFlagsClear(bt->rpc_event, BT_RPC_EVENT_ALL & (~BT_RPC_EVENT_DISCONNECTED));
size_t bytes_sent = 0;
while(bytes_sent < bytes_len) {
size_t bytes_remain = bytes_len - bytes_sent;
Expand All @@ -178,10 +187,14 @@ static void bt_rpc_send_bytes_callback(void* context, uint8_t* bytes, size_t byt
furi_hal_bt_serial_tx(&bytes[bytes_sent], bytes_remain);
bytes_sent += bytes_remain;
}
uint32_t event_flag =
osEventFlagsWait(bt->rpc_event, BT_RPC_EVENT_ALL, osFlagsWaitAny, osWaitForever);
// We want BT_RPC_EVENT_DISCONNECTED to stick, so don't clear
uint32_t event_flag = osEventFlagsWait(
bt->rpc_event, BT_RPC_EVENT_ALL, osFlagsWaitAny | osFlagsNoClear, osWaitForever);
if(event_flag & BT_RPC_EVENT_DISCONNECTED) {
break;
} else {
// If we didn't get BT_RPC_EVENT_DISCONNECTED, then clear everything else
osEventFlagsClear(bt->rpc_event, BT_RPC_EVENT_ALL & (~BT_RPC_EVENT_DISCONNECTED));
}
}
}
Expand All @@ -197,6 +210,8 @@ static bool bt_on_gap_event_callback(GapEvent event, void* context) {
bt->status = BtStatusConnected;
BtMessage message = {.type = BtMessageTypeUpdateStatus};
furi_check(osMessageQueuePut(bt->message_queue, &message, 0, osWaitForever) == osOK);
// Clear BT_RPC_EVENT_DISCONNECTED because it might be set from previous session
osEventFlagsClear(bt->rpc_event, BT_RPC_EVENT_DISCONNECTED);
if(bt->profile == BtProfileSerial) {
// Open RPC session
bt->rpc_session = rpc_session_open(bt->rpc);
Expand Down Expand Up @@ -368,6 +383,8 @@ int32_t bt_srv() {
} else if(message.type == BtMessageTypeUpdateBatteryLevel) {
// Update battery level
furi_hal_bt_update_battery_level(message.data.battery_level);
} else if(message.type == BtMessageTypeUpdatePowerState) {
furi_hal_bt_update_power_state();
} else if(message.type == BtMessageTypePinCodeShow) {
// Display PIN code
bt_pin_code_show(bt, message.data.pin_code);
Expand Down
1 change: 1 addition & 0 deletions applications/bt/bt_service/bt_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
typedef enum {
BtMessageTypeUpdateStatus,
BtMessageTypeUpdateBatteryLevel,
BtMessageTypeUpdatePowerState,
BtMessageTypePinCodeShow,
BtMessageTypeKeysStorageUpdated,
BtMessageTypeSetProfile,
Expand Down
Loading

0 comments on commit 287defd

Please sign in to comment.