90
90
#include <furi_hal.h>
91
91
92
92
#include <dolphin/dolphin.h>
93
- #include <notification/notification_messages.h>
94
93
95
94
#include <gui/elements.h>
96
95
#include <gui/view.h>
@@ -222,13 +221,12 @@ struct trade_ctx {
222
221
struct patch_list * patch_list ;
223
222
void * gblink_handle ;
224
223
PokemonData * pdata ;
225
- NotificationApp * notifications ;
226
224
};
227
225
228
226
/* These are the needed variables for the draw callback */
229
227
struct trade_model {
230
228
render_gameboy_state_t gameboy_status ;
231
- bool ledon ; // Controls the blue LED during trade
229
+ bool step ; // Controls the animation frame during trade
232
230
uint8_t curr_pokemon ;
233
231
PokemonData * pdata ;
234
232
};
@@ -321,21 +319,6 @@ static void pokemon_plist_recreate_callback(void* context, uint32_t arg) {
321
319
plist_create (& (trade -> patch_list ), trade -> pdata );
322
320
}
323
321
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
-
339
322
static void trade_draw_bottom_bar (Canvas * const canvas ) {
340
323
furi_assert (canvas );
341
324
@@ -401,23 +384,22 @@ static void trade_draw_pkmn_avatar(Canvas* canvas, PokemonData* pdata) {
401
384
canvas_draw_xbm (
402
385
canvas , 0 , 0 , pdata -> bitmap -> width , pdata -> bitmap -> height , pdata -> bitmap -> data );
403
386
404
- furi_hal_light_set (LightBlue , 0x00 );
405
387
furi_hal_light_set (LightGreen , 0x00 );
406
388
}
407
389
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
409
391
* state. This is necessary as Flipper OS does not make any guarantees on when
410
392
* draw updates may or may not be called. There are situations where a draw
411
393
* 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.
413
395
*/
414
396
static void trade_draw_timer_callback (void * context ) {
415
397
furi_assert (context );
416
398
417
399
struct trade_ctx * trade = (struct trade_ctx * )context ;
418
400
419
401
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);
421
403
}
422
404
423
405
static void trade_draw_callback (Canvas * canvas , void * view_model ) {
@@ -450,13 +432,11 @@ static void trade_draw_callback(Canvas* canvas, void* view_model) {
450
432
break ;
451
433
case GAMEBOY_TRADING :
452
434
furi_hal_light_set (LightGreen , 0x00 );
453
- if (model -> ledon ) {
454
- furi_hal_light_set (LightBlue , 0xff );
435
+ if (model -> step )
455
436
canvas_draw_icon (canvas , 0 , 5 , & I_gb_step_1 );
456
- } else {
457
- furi_hal_light_set (LightBlue , 0x00 );
437
+ else
458
438
canvas_draw_icon (canvas , 0 , 5 , & I_gb_step_2 );
459
- }
439
+
460
440
trade_draw_frame (canvas , "TRADING" );
461
441
break ;
462
442
case GAMEBOY_TRADE_CANCEL :
@@ -851,9 +831,6 @@ static void transferBit(void* context, uint8_t in_byte) {
851
831
gblink_transfer (trade -> gblink_handle , getTradeCentreResponse (trade ));
852
832
break ;
853
833
}
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 );
857
834
}
858
835
859
836
void trade_enter_callback (void * context ) {
@@ -870,18 +847,20 @@ void trade_enter_callback(void* context) {
870
847
}
871
848
trade -> trade_centre_state = TRADE_RESET ;
872
849
model -> curr_pokemon = pokemon_stat_get (trade -> pdata , STAT_NUM , NONE );
873
- model -> ledon = false;
850
+ model -> step = false;
874
851
875
852
view_commit_model (trade -> view , true);
876
853
877
854
gblink_callback_set (trade -> gblink_handle , transferBit , trade );
878
855
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);
879
858
880
859
gblink_start (trade -> gblink_handle );
881
860
882
861
/* 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.
885
864
*/
886
865
trade -> draw_timer = furi_timer_alloc (trade_draw_timer_callback , FuriTimerTypePeriodic , trade );
887
866
furi_timer_start (trade -> draw_timer , furi_ms_to_ticks (250 ));
@@ -930,7 +909,6 @@ void* trade_alloc(
930
909
trade -> pdata = pdata ;
931
910
trade -> input_pdata = pokemon_data_alloc (pdata -> gen );
932
911
trade -> patch_list = NULL ;
933
- trade -> notifications = furi_record_open (RECORD_NOTIFICATION );
934
912
trade -> gblink_handle = gblink_handle ;
935
913
936
914
view_set_context (trade -> view , trade );
@@ -955,8 +933,6 @@ void trade_free(ViewDispatcher* view_dispatcher, uint32_t view_id, void* trade_c
955
933
956
934
view_dispatcher_remove_view (view_dispatcher , view_id );
957
935
958
- furi_record_close (RECORD_NOTIFICATION );
959
-
960
936
view_free (trade -> view );
961
937
pokemon_data_free (trade -> input_pdata );
962
938
free (trade );
0 commit comments