Skip to content

Commit

Permalink
GUI: abolish API injection into instances. (#265)
Browse files Browse the repository at this point in the history
* GUI: abolish API injection into instances. Update usage by 3rd party apps.
* GUI: update documentation. Cleanup api usage. Adjust status bar item spacing.
  • Loading branch information
skotopes authored Dec 14, 2020
1 parent ff7ce6f commit d3ff787
Show file tree
Hide file tree
Showing 39 changed files with 489 additions and 425 deletions.
18 changes: 9 additions & 9 deletions applications/app-loader/app-loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ typedef struct {

// TODO add mutex for contex

static void render_callback(CanvasApi* canvas, void* _ctx) {
static void render_callback(Canvas* canvas, void* _ctx) {
AppLoaderState* ctx = (AppLoaderState*)_ctx;

canvas->clear(canvas);
canvas->set_color(canvas, ColorBlack);
canvas->set_font(canvas, FontPrimary);
canvas->draw_str(canvas, 2, 32, ctx->current_app->name);
canvas_clear(canvas);
canvas_set_color(canvas, ColorBlack);
canvas_set_font(canvas, FontPrimary);
canvas_draw_str(canvas, 2, 32, ctx->current_app->name);

canvas->set_font(canvas, FontSecondary);
canvas->draw_str(canvas, 2, 44, "press back to exit");
canvas_set_font(canvas, FontSecondary);
canvas_draw_str(canvas, 2, 44, "press back to exit");
}

static void input_callback(InputEvent* input_event, void* _ctx) {
Expand Down Expand Up @@ -92,12 +92,12 @@ void app_loader(void* p) {
Cli* cli = furi_open("cli");

// Open GUI and register widget
GuiApi* gui = furi_open("gui");
Gui* gui = furi_open("gui");
if(gui == NULL) {
printf("gui is not available\n");
furiac_exit(NULL);
}
gui->add_widget(gui, state.widget, GuiLayerFullscreen);
gui_add_widget(gui, state.widget, GuiLayerFullscreen);

// FURI startup
const size_t flipper_app_count = sizeof(FLIPPER_APPS) / sizeof(FLIPPER_APPS[0]);
Expand Down
2 changes: 0 additions & 2 deletions applications/applications.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,6 @@ const FlipperStartupApp FLIPPER_APPS[] = {
.icon = A_iButton_14},
#endif

{.app = NULL, .name = "Bluetooth", .libs = {0}, .icon = A_Bluetooth_14},

#ifdef BUILD_GPIO_DEMO
{.app = app_gpio_test, .name = "GPIO", .libs = {1, FURI_LIB{"gui_task"}}, .icon = A_GPIO_14},
#endif
Expand Down
20 changes: 11 additions & 9 deletions applications/bt/bt.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@ Bt* bt_alloc() {

bt->statusbar_icon = assets_icons_get(I_Bluetooth_5x8);
bt->statusbar_widget = widget_alloc();
widget_set_width(bt->statusbar_widget, icon_get_width(bt->statusbar_icon) + 2);
widget_set_width(bt->statusbar_widget, icon_get_width(bt->statusbar_icon));
widget_draw_callback_set(bt->statusbar_widget, bt_draw_statusbar_callback, bt);
widget_enabled_set(bt->statusbar_widget, false);

bt->menu_icon = assets_icons_get(A_Bluetooth_14);
bt->menu_item = menu_item_alloc_menu("Bluetooth", bt->menu_icon);

return bt;
}

void bt_draw_statusbar_callback(CanvasApi* canvas, void* context) {
void bt_draw_statusbar_callback(Canvas* canvas, void* context) {
assert(context);
Bt* bt = context;
canvas->draw_icon(canvas, 0, 0, bt->statusbar_icon);
canvas_draw_icon(canvas, 0, 0, bt->statusbar_icon);
}

void bt_cli_info(string_t args, void* context) {
Expand All @@ -40,12 +43,11 @@ void bt_task() {
furiac_exit(NULL);
}

FuriRecordSubscriber* gui_record = furi_open_deprecated("gui", false, false, NULL, NULL, NULL);
furi_assert(gui_record);
GuiApi* gui = furi_take(gui_record);
furi_assert(gui);
gui->add_widget(gui, bt->statusbar_widget, GuiLayerStatusBarLeft);
furi_commit(gui_record);
Gui* gui = furi_open("gui");
gui_add_widget(gui, bt->statusbar_widget, GuiLayerStatusBarLeft);

with_value_mutex(
furi_open("menu"), (Menu * menu) { menu_item_add(menu, bt->menu_item); });

furiac_ready();

Expand Down
11 changes: 10 additions & 1 deletion applications/bt/bt_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,26 @@
#include "bt.h"

#include <cli/cli.h>

#include <flipper.h>
#include <flipper_v2.h>

#include <gui/gui.h>
#include <gui/widget.h>

#include <menu/menu.h>
#include <menu/menu_item.h>

typedef struct {
Cli* cli;
// Status bar
Icon* statusbar_icon;
Widget* statusbar_widget;
// Menu
Icon* menu_icon;
MenuItem* menu_item;
} Bt;

Bt* bt_alloc();

void bt_draw_statusbar_callback(CanvasApi* canvas, void* context);
void bt_draw_statusbar_callback(Canvas* canvas, void* context);
36 changes: 18 additions & 18 deletions applications/cc1101-workaround/cc1101-workaround.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,37 +329,37 @@ typedef struct {
bool need_cc1101_conf;
} State;

static void render_callback(CanvasApi* canvas, void* ctx) {
static void render_callback(Canvas* canvas, void* ctx) {
State* state = (State*)acquire_mutex((ValueMutex*)ctx, 25);

if(!state) return;

canvas->clear(canvas);
canvas->set_color(canvas, ColorBlack);
canvas->set_font(canvas, FontPrimary);
canvas->draw_str(canvas, 2, 12, "cc1101 workaround");
canvas_clear(canvas);
canvas_set_color(canvas, ColorBlack);
canvas_set_font(canvas, FontPrimary);
canvas_draw_str(canvas, 2, 12, "cc1101 workaround");

{
char buf[24];
FreqConfig conf = FREQ_LIST[state->active_freq];
float freq = conf.band->base_freq + CHAN_SPA * conf.channel;
sprintf(buf, "freq: %ld.%02ld MHz", (uint32_t)freq, (uint32_t)(freq * 100.) % 100);

canvas->set_font(canvas, FontSecondary);
canvas->draw_str(canvas, 2, 25, buf);
canvas_set_font(canvas, FontSecondary);
canvas_draw_str(canvas, 2, 25, buf);
}

{
canvas->set_font(canvas, FontSecondary);
canvas_set_font(canvas, FontSecondary);

if(state->need_cc1101_conf) {
canvas->draw_str(canvas, 2, 36, "mode: configuring...");
canvas_draw_str(canvas, 2, 36, "mode: configuring...");
} else if(state->mode == ModeRx) {
canvas->draw_str(canvas, 2, 36, "mode: RX");
canvas_draw_str(canvas, 2, 36, "mode: RX");
} else if(state->mode == ModeTx) {
canvas->draw_str(canvas, 2, 36, "mode: TX");
canvas_draw_str(canvas, 2, 36, "mode: TX");
} else {
canvas->draw_str(canvas, 2, 36, "mode: unknown");
canvas_draw_str(canvas, 2, 36, "mode: unknown");
}
}

Expand All @@ -368,17 +368,17 @@ static void render_callback(CanvasApi* canvas, void* ctx) {
char buf[24];
sprintf(buf, "RSSI: %d dBm", state->last_rssi);

canvas->set_font(canvas, FontSecondary);
canvas->draw_str(canvas, 2, 48, buf);
canvas_set_font(canvas, FontSecondary);
canvas_draw_str(canvas, 2, 48, buf);
}
}

{
char buf[24];
sprintf(buf, "tx level: %d dBm", TX_LEVELS[state->tx_level].dbm);

canvas->set_font(canvas, FontSecondary);
canvas->draw_str(canvas, 2, 63, buf);
canvas_set_font(canvas, FontSecondary);
canvas_draw_str(canvas, 2, 63, buf);
}

release_mutex((ValueMutex*)ctx, state);
Expand Down Expand Up @@ -416,12 +416,12 @@ extern "C" void cc1101_workaround(void* p) {
widget_input_callback_set(widget, input_callback, event_queue);

// Open GUI and register widget
GuiApi* gui = (GuiApi*)furi_open("gui");
Gui* gui = (Gui*)furi_open("gui");
if(gui == NULL) {
printf("[cc1101] gui is not available\n");
furiac_exit(NULL);
}
gui->add_widget(gui, widget, GuiLayerFullscreen);
gui_add_widget(gui, widget, GuiLayerFullscreen);

gpio_init(&debug_0, GpioModeOutputPushPull);
gpio_write((GpioPin*)&debug_0, false);
Expand Down
2 changes: 1 addition & 1 deletion applications/floopper-bloopper
18 changes: 9 additions & 9 deletions applications/gpio-tester/gpio-tester.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ typedef struct {
uint8_t gpio_index;
} State;

static void render_callback(CanvasApi* canvas, void* ctx) {
static void render_callback(Canvas* canvas, void* ctx) {
State* state = (State*)acquire_mutex((ValueMutex*)ctx, 25);

canvas->clear(canvas);
canvas->set_color(canvas, ColorBlack);
canvas->set_font(canvas, FontPrimary);
canvas->draw_str(canvas, 2, 10, "GPIO demo");
canvas->set_font(canvas, FontSecondary);
canvas->draw_str(canvas, 2, 25, GPIO_PINS[state->gpio_index].name);
canvas_clear(canvas);
canvas_set_color(canvas, ColorBlack);
canvas_set_font(canvas, FontPrimary);
canvas_draw_str(canvas, 2, 10, "GPIO demo");
canvas_set_font(canvas, FontSecondary);
canvas_draw_str(canvas, 2, 25, GPIO_PINS[state->gpio_index].name);

release_mutex((ValueMutex*)ctx, state);
}
Expand Down Expand Up @@ -74,12 +74,12 @@ void app_gpio_test(void* p) {
widget_input_callback_set(widget, input_callback, event_queue);

// Open GUI and register widget
GuiApi* gui = (GuiApi*)furi_open("gui");
Gui* gui = (Gui*)furi_open("gui");
if(gui == NULL) {
printf("[gpio-tester] gui is not available\n");
furiac_exit(NULL);
}
gui->add_widget(gui, widget, GuiLayerFullscreen);
gui_add_widget(gui, widget, GuiLayerFullscreen);

// configure pin
for(uint8_t i = 0; i < sizeof(GPIO_PINS) / sizeof(GPIO_PINS[0]); i++) {
Expand Down
Loading

0 comments on commit d3ff787

Please sign in to comment.