Skip to content

Commit 3826c16

Browse files
committed
gblink: bump to <version>, update calls
Since the gblink API can blink on data and automatically bump the backlight, remove blue LED control and backlight notification sending and set up gblink to do that for us instead. Signed-off-by: Kris Bahnsen <Kris@KBEmbedded.com>
1 parent 3f34c0a commit 3826c16

File tree

2 files changed

+13
-37
lines changed

2 files changed

+13
-37
lines changed

src/views/trade.c

+12-36
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@
9090
#include <furi_hal.h>
9191

9292
#include <dolphin/dolphin.h>
93-
#include <notification/notification_messages.h>
9493

9594
#include <gui/elements.h>
9695
#include <gui/view.h>
@@ -222,13 +221,12 @@ struct trade_ctx {
222221
struct patch_list* patch_list;
223222
void* gblink_handle;
224223
PokemonData* pdata;
225-
NotificationApp* notifications;
226224
};
227225

228226
/* These are the needed variables for the draw callback */
229227
struct trade_model {
230228
render_gameboy_state_t gameboy_status;
231-
bool ledon; // Controls the blue LED during trade
229+
bool step; // Controls the animation frame during trade
232230
uint8_t curr_pokemon;
233231
PokemonData* pdata;
234232
};
@@ -321,21 +319,6 @@ static void pokemon_plist_recreate_callback(void* context, uint32_t arg) {
321319
plist_create(&(trade->patch_list), trade->pdata);
322320
}
323321

324-
/* Call this at any point to reset the timer on the backlight turning off.
325-
* During trade, this should get called pretty frequently so long as data
326-
* is moving in and out.
327-
*
328-
* I hesitate to force the backlight on, as I don't want to be responsible
329-
* for draining someone's battery on accident.
330-
*/
331-
static void trade_backlight_bump_callback(void* context, uint32_t arg) {
332-
furi_assert(context);
333-
UNUSED(arg);
334-
struct trade_ctx* trade = context;
335-
336-
notification_message(trade->notifications, &sequence_display_backlight_on);
337-
}
338-
339322
static void trade_draw_bottom_bar(Canvas* const canvas) {
340323
furi_assert(canvas);
341324

@@ -401,23 +384,22 @@ static void trade_draw_pkmn_avatar(Canvas* canvas, PokemonData* pdata) {
401384
canvas_draw_xbm(
402385
canvas, 0, 0, pdata->bitmap->width, pdata->bitmap->height, pdata->bitmap->data);
403386

404-
furi_hal_light_set(LightBlue, 0x00);
405387
furi_hal_light_set(LightGreen, 0x00);
406388
}
407389

408-
/* Called every 250 ms on a timer. This controls the blue LED when in TRADING
390+
/* Called every 250 ms on a timer. This controls the animation when in TRADING
409391
* state. This is necessary as Flipper OS does not make any guarantees on when
410392
* draw updates may or may not be called. There are situations where a draw
411393
* update is called much faster. Therefore, we need to control the update rate
412-
* via the ledon view_model variable.
394+
* via the step view_model variable.
413395
*/
414396
static void trade_draw_timer_callback(void* context) {
415397
furi_assert(context);
416398

417399
struct trade_ctx* trade = (struct trade_ctx*)context;
418400

419401
with_view_model(
420-
trade->view, struct trade_model * model, { model->ledon ^= 1; }, true);
402+
trade->view, struct trade_model * model, { model->step ^= 1; }, true);
421403
}
422404

423405
static void trade_draw_callback(Canvas* canvas, void* view_model) {
@@ -450,13 +432,11 @@ static void trade_draw_callback(Canvas* canvas, void* view_model) {
450432
break;
451433
case GAMEBOY_TRADING:
452434
furi_hal_light_set(LightGreen, 0x00);
453-
if(model->ledon) {
454-
furi_hal_light_set(LightBlue, 0xff);
435+
if(model->step)
455436
canvas_draw_icon(canvas, 0, 5, &I_gb_step_1);
456-
} else {
457-
furi_hal_light_set(LightBlue, 0x00);
437+
else
458438
canvas_draw_icon(canvas, 0, 5, &I_gb_step_2);
459-
}
439+
460440
trade_draw_frame(canvas, "TRADING");
461441
break;
462442
case GAMEBOY_TRADE_CANCEL:
@@ -851,9 +831,6 @@ static void transferBit(void* context, uint8_t in_byte) {
851831
gblink_transfer(trade->gblink_handle, getTradeCentreResponse(trade));
852832
break;
853833
}
854-
855-
/* Each byte that comes in, bump the backlight timer so it stays on during a trade */
856-
furi_timer_pending_callback(trade_backlight_bump_callback, trade, 0);
857834
}
858835

859836
void trade_enter_callback(void* context) {
@@ -870,18 +847,20 @@ void trade_enter_callback(void* context) {
870847
}
871848
trade->trade_centre_state = TRADE_RESET;
872849
model->curr_pokemon = pokemon_stat_get(trade->pdata, STAT_NUM, NONE);
873-
model->ledon = false;
850+
model->step = false;
874851

875852
view_commit_model(trade->view, true);
876853

877854
gblink_callback_set(trade->gblink_handle, transferBit, trade);
878855
gblink_nobyte_set(trade->gblink_handle, SERIAL_NO_DATA_BYTE);
856+
gblink_led_blink_on_byte(trade->gblink_handle, true);
857+
gblink_backlight_on_byte(trade->gblink_handle, true);
879858

880859
gblink_start(trade->gblink_handle);
881860

882861
/* Every 250 ms, trigger a draw update. 250 ms was chosen so that during
883-
* the trade process, each update can flip the LED and screen to make the
884-
* trade animation.
862+
* the trade process, each update can flip the screen to make the trade
863+
* animation.
885864
*/
886865
trade->draw_timer = furi_timer_alloc(trade_draw_timer_callback, FuriTimerTypePeriodic, trade);
887866
furi_timer_start(trade->draw_timer, furi_ms_to_ticks(250));
@@ -930,7 +909,6 @@ void* trade_alloc(
930909
trade->pdata = pdata;
931910
trade->input_pdata = pokemon_data_alloc(pdata->gen);
932911
trade->patch_list = NULL;
933-
trade->notifications = furi_record_open(RECORD_NOTIFICATION);
934912
trade->gblink_handle = gblink_handle;
935913

936914
view_set_context(trade->view, trade);
@@ -955,8 +933,6 @@ void trade_free(ViewDispatcher* view_dispatcher, uint32_t view_id, void* trade_c
955933

956934
view_dispatcher_remove_view(view_dispatcher, view_id);
957935

958-
furi_record_close(RECORD_NOTIFICATION);
959-
960936
view_free(trade->view);
961937
pokemon_data_free(trade->input_pdata);
962938
free(trade);

0 commit comments

Comments
 (0)