This commit is contained in:
lokiuox
2022-10-15 11:19:10 +02:00
11 changed files with 147 additions and 111 deletions
@@ -3,6 +3,7 @@ App(
name="Applications",
apptype=FlipperAppType.APP,
entry_point="fap_loader_app",
cdefines=["APP_FAP_LOADER"],
requires=[
"gui",
"storage",
@@ -101,7 +101,7 @@ static bool fap_loader_run_selected_app(FapLoader* loader) {
}
FURI_LOG_I(TAG, "Loaded in %ums", (size_t)(furi_get_tick() - start));
FURI_LOG_I(TAG, "FAP Loader is staring app");
FURI_LOG_I(TAG, "FAP Loader is starting app");
FuriThread* thread = flipper_application_spawn(loader->app, NULL);
furi_thread_start(thread);
+30 -92
View File
@@ -42,10 +42,7 @@ typedef enum {
TileTypeMine
} TileType;
typedef enum {
FieldEmpty, // <-- same goes for this
FieldMine
} Field;
typedef enum { FieldEmpty, FieldMine } Field;
typedef struct {
Field minefield[PLAYFIELD_WIDTH][PLAYFIELD_HEIGHT];
@@ -99,6 +96,8 @@ static void render_callback(Canvas* const canvas, void* ctx) {
furi_string_printf(timeStr, "%01d:%02d", minutes, seconds);
canvas_draw_str_aligned(canvas, 128, 0, AlignRight, AlignTop, furi_string_get_cstr(timeStr));
uint8_t* tile_to_draw;
for(int y = 0; y < PLAYFIELD_HEIGHT; y++) {
for(int x = 0; x < PLAYFIELD_WIDTH; x++) {
if(x == minesweeper_state->cursor_x && y == minesweeper_state->cursor_y) {
@@ -106,114 +105,53 @@ static void render_callback(Canvas* const canvas, void* ctx) {
}
switch(minesweeper_state->playfield[x][y]) {
case TileType0:
canvas_draw_xbm(
canvas,
x * TILE_HEIGHT, // x
8 + (y * TILE_WIDTH), // y
TILE_WIDTH,
TILE_HEIGHT,
tile_0_bits);
tile_to_draw = tile_0_bits;
break;
case TileType1:
canvas_draw_xbm(
canvas,
x * TILE_HEIGHT, // x
8 + (y * TILE_WIDTH), // y
TILE_WIDTH,
TILE_HEIGHT,
tile_1_bits);
tile_to_draw = tile_1_bits;
break;
case TileType2:
canvas_draw_xbm(
canvas,
x * TILE_HEIGHT, // x
8 + (y * TILE_WIDTH), // y
TILE_WIDTH,
TILE_HEIGHT,
tile_2_bits);
tile_to_draw = tile_2_bits;
break;
case TileType3:
canvas_draw_xbm(
canvas,
x * TILE_HEIGHT, // x
8 + (y * TILE_WIDTH), // y
TILE_WIDTH,
TILE_HEIGHT,
tile_3_bits);
tile_to_draw = tile_3_bits;
break;
case TileType4:
canvas_draw_xbm(
canvas,
x * TILE_HEIGHT, // x
8 + (y * TILE_WIDTH), // y
TILE_WIDTH,
TILE_HEIGHT,
tile_4_bits);
tile_to_draw = tile_4_bits;
break;
case TileType5:
canvas_draw_xbm(
canvas,
x * TILE_HEIGHT, // x
8 + (y * TILE_WIDTH), // y
TILE_WIDTH,
TILE_HEIGHT,
tile_5_bits);
tile_to_draw = tile_5_bits;
break;
case TileType6:
canvas_draw_xbm(
canvas,
x * TILE_HEIGHT, // x
8 + (y * TILE_WIDTH), // y
TILE_WIDTH,
TILE_HEIGHT,
tile_6_bits);
tile_to_draw = tile_6_bits;
break;
case TileType7:
canvas_draw_xbm(
canvas,
x * TILE_HEIGHT, // x
8 + (y * TILE_WIDTH), // y
TILE_WIDTH,
TILE_HEIGHT,
tile_7_bits);
tile_to_draw = tile_7_bits;
break;
case TileType8:
canvas_draw_xbm(
canvas,
x * TILE_HEIGHT, // x
8 + (y * TILE_WIDTH), // y
TILE_WIDTH,
TILE_HEIGHT,
tile_8_bits);
tile_to_draw = tile_8_bits;
break;
case TileTypeFlag:
canvas_draw_xbm(
canvas,
x * TILE_HEIGHT, // x
8 + (y * TILE_WIDTH), // y
TILE_WIDTH,
TILE_HEIGHT,
tile_flag_bits);
tile_to_draw = tile_flag_bits;
break;
case TileTypeUncleared:
canvas_draw_xbm(
canvas,
x * TILE_HEIGHT, // x
8 + (y * TILE_WIDTH), // y
TILE_WIDTH,
TILE_HEIGHT,
tile_uncleared_bits);
tile_to_draw = tile_uncleared_bits;
break;
case TileTypeMine:
canvas_draw_xbm(
canvas,
x * TILE_HEIGHT, // x
8 + (y * TILE_WIDTH), // y
TILE_WIDTH,
TILE_HEIGHT,
tile_mine_bits);
tile_to_draw = tile_mine_bits;
break;
default:
// this should never happen
tile_to_draw = tile_mine_bits;
break;
}
canvas_draw_xbm(
canvas,
x * TILE_HEIGHT, // x
8 + (y * TILE_WIDTH), // y
TILE_WIDTH,
TILE_HEIGHT,
tile_to_draw);
if(x == minesweeper_state->cursor_x && y == minesweeper_state->cursor_y) {
canvas_invert_color(canvas);
}
@@ -479,25 +417,25 @@ int32_t minesweeper_app(void* p) {
case InputKeyUp:
minesweeper_state->cursor_y--;
if(minesweeper_state->cursor_y < 0) {
minesweeper_state->cursor_y = 0;
minesweeper_state->cursor_y = PLAYFIELD_HEIGHT - 1;
}
break;
case InputKeyDown:
minesweeper_state->cursor_y++;
if(minesweeper_state->cursor_y >= PLAYFIELD_HEIGHT) {
minesweeper_state->cursor_y = PLAYFIELD_HEIGHT - 1;
minesweeper_state->cursor_y = 0;
}
break;
case InputKeyRight:
minesweeper_state->cursor_x++;
if(minesweeper_state->cursor_x >= PLAYFIELD_WIDTH) {
minesweeper_state->cursor_x = PLAYFIELD_WIDTH - 1;
minesweeper_state->cursor_x = 0;
}
break;
case InputKeyLeft:
minesweeper_state->cursor_x--;
if(minesweeper_state->cursor_x < 0) {
minesweeper_state->cursor_x = 0;
minesweeper_state->cursor_x = PLAYFIELD_WIDTH - 1;
}
break;
case InputKeyOk:
+16 -3
View File
@@ -165,6 +165,11 @@ static uint16_t bt_serial_event_callback(SerialServiceEvent event, void* context
ret = rpc_session_get_available_size(bt->rpc_session);
} else if(event.event == SerialServiceEventTypeDataSent) {
furi_event_flag_set(bt->rpc_event, BT_RPC_EVENT_BUFF_SENT);
} else if(event.event == SerialServiceEventTypesBleResetRequest) {
FURI_LOG_I(TAG, "BLE restart request received");
BtMessage message = {.type = BtMessageTypeSetProfile, .data.profile = BtProfileSerial};
furi_check(
furi_message_queue_put(bt->message_queue, &message, FuriWaitForever) == FuriStatusOk);
}
return ret;
}
@@ -226,6 +231,7 @@ static bool bt_on_gap_event_callback(GapEvent event, void* context) {
rpc_session_set_context(bt->rpc_session, bt);
furi_hal_bt_serial_set_event_callback(
RPC_BUFFER_SIZE, bt_serial_event_callback, bt);
furi_hal_bt_serial_set_rpc_status(FuriHalBtSerialRpcStatusActive);
} else {
FURI_LOG_W(TAG, "RPC is busy, failed to open new session");
}
@@ -241,6 +247,7 @@ static bool bt_on_gap_event_callback(GapEvent event, void* context) {
} else if(event.type == GapEventTypeDisconnected) {
if(bt->profile == BtProfileSerial && bt->rpc_session) {
FURI_LOG_I(TAG, "Close RPC connection");
furi_hal_bt_serial_set_rpc_status(FuriHalBtSerialRpcStatusNotActive);
furi_event_flag_set(bt->rpc_event, BT_RPC_EVENT_DISCONNECTED);
rpc_session_close(bt->rpc_session);
furi_hal_bt_serial_set_event_callback(0, NULL, NULL);
@@ -330,14 +337,20 @@ static void bt_change_profile(Bt* bt, BtMessage* message) {
}
furi_hal_bt_set_key_storage_change_callback(bt_on_key_storage_change_callback, bt);
bt->profile = message->data.profile;
*message->result = true;
if(message->result) {
*message->result = true;
}
} else {
FURI_LOG_E(TAG, "Failed to start Bt App");
*message->result = false;
if(message->result) {
*message->result = false;
}
}
} else {
bt_show_warning(bt, "Radio stack doesn't support this app");
*message->result = false;
if(message->result) {
*message->result = false;
}
}
furi_event_flag_set(bt->api_event, BT_API_UNLOCK_EVENT);
}
@@ -11,9 +11,16 @@ static bool favorite_fap_selector_item_callback(
uint8_t** icon_ptr,
FuriString* item_name) {
UNUSED(context);
#ifdef APP_FAP_LOADER
Storage* storage = furi_record_open(RECORD_STORAGE);
bool success = fap_loader_load_name_and_icon(file_path, storage, icon_ptr, item_name);
furi_record_close(RECORD_STORAGE);
#else
UNUSED(file_path);
UNUSED(icon_ptr);
UNUSED(item_name);
bool success = false;
#endif
return success;
}