This commit is contained in:
RogueMaster
2022-11-17 23:48:40 -05:00
parent d686d7f650
commit 567f9f4585
39 changed files with 2007 additions and 1630 deletions

View File

@@ -23,7 +23,6 @@ void start_round(GameState *game_state);
void init(GameState* game_state); void init(GameState* game_state);
static void draw_ui(Canvas* const canvas, const GameState* game_state) { static void draw_ui(Canvas* const canvas, const GameState* game_state) {
draw_money(canvas, game_state->player_score); draw_money(canvas, game_state->player_score);
draw_score(canvas, true, hand_count(game_state->player_cards, game_state->player_card_count)); draw_score(canvas, true, hand_count(game_state->player_cards, game_state->player_card_count));
@@ -71,7 +70,6 @@ Card draw_card(GameState *game_state) {
return c; return c;
} }
void drawPlayerCard(void* ctx) { void drawPlayerCard(void* ctx) {
GameState* game_state = ctx; GameState* game_state = ctx;
Card c = draw_card(game_state); Card c = draw_card(game_state);
@@ -93,48 +91,42 @@ void drawDealerCard(void *ctx) {
//region queue callbacks //region queue callbacks
void to_lose_state(const void* ctx, Canvas* const canvas) { void to_lose_state(const void* ctx, Canvas* const canvas) {
const GameState* game_state = ctx; const GameState* game_state = ctx;
if (game_state->settings.message_duration == 0) if(game_state->settings.message_duration == 0) return;
return;
popup_frame(canvas); popup_frame(canvas);
elements_multiline_text_aligned(canvas, 64, 22, AlignCenter, AlignCenter, "You lost"); elements_multiline_text_aligned(canvas, 64, 22, AlignCenter, AlignCenter, "You lost");
} }
void to_bust_state(const void* ctx, Canvas* const canvas) { void to_bust_state(const void* ctx, Canvas* const canvas) {
const GameState* game_state = ctx; const GameState* game_state = ctx;
if (game_state->settings.message_duration == 0) if(game_state->settings.message_duration == 0) return;
return;
popup_frame(canvas); popup_frame(canvas);
elements_multiline_text_aligned(canvas, 64, 22, AlignCenter, AlignCenter, "Busted!"); elements_multiline_text_aligned(canvas, 64, 22, AlignCenter, AlignCenter, "Busted!");
} }
void to_draw_state(const void* ctx, Canvas* const canvas) { void to_draw_state(const void* ctx, Canvas* const canvas) {
const GameState* game_state = ctx; const GameState* game_state = ctx;
if (game_state->settings.message_duration == 0) if(game_state->settings.message_duration == 0) return;
return;
popup_frame(canvas); popup_frame(canvas);
elements_multiline_text_aligned(canvas, 64, 22, AlignCenter, AlignCenter, "Draw"); elements_multiline_text_aligned(canvas, 64, 22, AlignCenter, AlignCenter, "Draw");
} }
void to_dealer_turn(const void* ctx, Canvas* const canvas) { void to_dealer_turn(const void* ctx, Canvas* const canvas) {
const GameState* game_state = ctx; const GameState* game_state = ctx;
if (game_state->settings.message_duration == 0) if(game_state->settings.message_duration == 0) return;
return;
popup_frame(canvas); popup_frame(canvas);
elements_multiline_text_aligned(canvas, 64, 22, AlignCenter, AlignCenter, "Dealers turn"); elements_multiline_text_aligned(canvas, 64, 22, AlignCenter, AlignCenter, "Dealers turn");
} }
void to_win_state(const void* ctx, Canvas* const canvas) { void to_win_state(const void* ctx, Canvas* const canvas) {
const GameState* game_state = ctx; const GameState* game_state = ctx;
if (game_state->settings.message_duration == 0) if(game_state->settings.message_duration == 0) return;
return;
popup_frame(canvas); popup_frame(canvas);
elements_multiline_text_aligned(canvas, 64, 22, AlignCenter, AlignCenter, "You win"); elements_multiline_text_aligned(canvas, 64, 22, AlignCenter, AlignCenter, "You win");
} }
void to_start(const void* ctx, Canvas* const canvas) { void to_start(const void* ctx, Canvas* const canvas) {
const GameState* game_state = ctx; const GameState* game_state = ctx;
if (game_state->settings.message_duration == 0) if(game_state->settings.message_duration == 0) return;
return;
popup_frame(canvas); popup_frame(canvas);
elements_multiline_text_aligned(canvas, 64, 22, AlignCenter, AlignCenter, "Round started"); elements_multiline_text_aligned(canvas, 64, 22, AlignCenter, AlignCenter, "Round started");
} }
@@ -145,7 +137,6 @@ void before_start(void *ctx) {
game_state->player_card_count = 0; game_state->player_card_count = 0;
} }
void start(void* ctx) { void start(void* ctx) {
GameState* game_state = ctx; GameState* game_state = ctx;
start_round(game_state); start_round(game_state);
@@ -155,7 +146,12 @@ void draw(void *ctx) {
GameState* game_state = ctx; GameState* game_state = ctx;
game_state->player_score += game_state->bet; game_state->player_score += game_state->bet;
game_state->bet = 0; game_state->bet = 0;
enqueue(&(game_state->queue_state), game_state, start, before_start, to_start, enqueue(
&(game_state->queue_state),
game_state,
start,
before_start,
to_start,
game_state->settings.message_duration); game_state->settings.message_duration);
} }
@@ -169,11 +165,15 @@ void lose(void *ctx) {
game_state->state = GameStatePlay; game_state->state = GameStatePlay;
game_state->bet = 0; game_state->bet = 0;
if(game_state->player_score >= game_state->settings.round_price) { if(game_state->player_score >= game_state->settings.round_price) {
enqueue(&(game_state->queue_state), game_state, start, before_start, to_start, enqueue(
&(game_state->queue_state),
game_state,
start,
before_start,
to_start,
game_state->settings.message_duration); game_state->settings.message_duration);
} else { } else {
enqueue(&(game_state->queue_state), game_state, game_over, NULL, NULL, enqueue(&(game_state->queue_state), game_state, game_over, NULL, NULL, 0);
0);
} }
} }
@@ -182,11 +182,15 @@ void win(void *ctx) {
game_state->state = GameStatePlay; game_state->state = GameStatePlay;
game_state->player_score += game_state->bet * 2; game_state->player_score += game_state->bet * 2;
game_state->bet = 0; game_state->bet = 0;
enqueue(&(game_state->queue_state), game_state, start, before_start, to_start, enqueue(
&(game_state->queue_state),
game_state,
start,
before_start,
to_start,
game_state->settings.message_duration); game_state->settings.message_duration);
} }
void dealerTurn(void* ctx) { void dealerTurn(void* ctx) {
GameState* game_state = ctx; GameState* game_state = ctx;
game_state->state = GameStateDealer; game_state->state = GameStateDealer;
@@ -204,15 +208,10 @@ void dealer_card_animation(const void *ctx, Canvas *const canvas) {
Card animatingCard = game_state->deck.cards[game_state->deck.index]; Card animatingCard = game_state->deck.cards[game_state->deck.index];
if(game_state->dealer_card_count > 1) { if(game_state->dealer_card_count > 1) {
Vector end = card_pos_at_index(game_state->dealer_card_count); Vector end = card_pos_at_index(game_state->dealer_card_count);
draw_card_animation(animatingCard, draw_card_animation(animatingCard, (Vector){0, 64}, (Vector){0, 32}, end, t, true, canvas);
(Vector) {0, 64},
(Vector) {0, 32},
end,
t,
true,
canvas);
} else { } else {
draw_card_animation(animatingCard, draw_card_animation(
animatingCard,
(Vector){32, -CARD_HEIGHT}, (Vector){32, -CARD_HEIGHT},
(Vector){64, 32}, (Vector){64, 32},
(Vector){2, 2}, (Vector){2, 2},
@@ -226,7 +225,8 @@ void dealer_back_card_animation(const void *ctx, Canvas *const canvas) {
const GameState* game_state = ctx; const GameState* game_state = ctx;
float t = animationTime(game_state); float t = animationTime(game_state);
Vector currentPos = quadratic_2d((Vector) {32, -CARD_HEIGHT}, (Vector) {64, 32}, (Vector) {13, 5}, t); Vector currentPos =
quadratic_2d((Vector){32, -CARD_HEIGHT}, (Vector){64, 32}, (Vector){13, 5}, t);
draw_card_back_at(currentPos.x, currentPos.y, canvas); draw_card_back_at(currentPos.x, currentPos.y, canvas);
} }
@@ -237,32 +237,37 @@ void player_card_animation(const void *ctx, Canvas *const canvas) {
Card animatingCard = game_state->deck.cards[game_state->deck.index]; Card animatingCard = game_state->deck.cards[game_state->deck.index];
Vector end = card_pos_at_index(game_state->player_card_count); Vector end = card_pos_at_index(game_state->player_card_count);
draw_card_animation(animatingCard, draw_card_animation(
(Vector) {32, -CARD_HEIGHT}, animatingCard, (Vector){32, -CARD_HEIGHT}, (Vector){0, 32}, end, t, true, canvas);
(Vector) {0, 32},
end,
t,
true,
canvas);
} }
//endregion //endregion
void player_tick(GameState* game_state) { void player_tick(GameState* game_state) {
uint8_t score = hand_count(game_state->player_cards, game_state->player_card_count); uint8_t score = hand_count(game_state->player_cards, game_state->player_card_count);
if((game_state->doubled && score <= 21) || score == 21) { if((game_state->doubled && score <= 21) || score == 21) {
enqueue(&(game_state->queue_state), game_state, dealerTurn, NULL, to_dealer_turn, enqueue(
&(game_state->queue_state),
game_state,
dealerTurn,
NULL,
to_dealer_turn,
game_state->settings.message_duration); game_state->settings.message_duration);
} else if(score > 21) { } else if(score > 21) {
enqueue(&(game_state->queue_state), game_state, lose, NULL, to_bust_state, enqueue(
&(game_state->queue_state),
game_state,
lose,
NULL,
to_bust_state,
game_state->settings.message_duration); game_state->settings.message_duration);
} else { } else {
if(game_state->selectDirection == DirectionUp || game_state->selectDirection == DirectionDown){ if(game_state->selectDirection == DirectionUp ||
game_state->selectDirection == DirectionDown) {
move_menu(game_state->menu, game_state->selectDirection == DirectionUp ? -1 : 1); move_menu(game_state->menu, game_state->selectDirection == DirectionUp ? -1 : 1);
} }
if(game_state->selectDirection == Select) { if(game_state->selectDirection == Select) {
activate_menu(game_state->menu, game_state); activate_menu(game_state->menu, game_state);
} }
} }
} }
@@ -273,17 +278,37 @@ void dealer_tick(GameState *game_state) {
if(dealer_score >= DEALER_MAX) { if(dealer_score >= DEALER_MAX) {
if(dealer_score > 21 || dealer_score < player_score) { if(dealer_score > 21 || dealer_score < player_score) {
enqueue(&(game_state->queue_state), game_state, win, NULL, to_win_state, enqueue(
&(game_state->queue_state),
game_state,
win,
NULL,
to_win_state,
game_state->settings.message_duration); game_state->settings.message_duration);
} else if(dealer_score > player_score) { } else if(dealer_score > player_score) {
enqueue(&(game_state->queue_state), game_state, lose, NULL, to_lose_state, enqueue(
&(game_state->queue_state),
game_state,
lose,
NULL,
to_lose_state,
game_state->settings.message_duration); game_state->settings.message_duration);
} else if(dealer_score == player_score) { } else if(dealer_score == player_score) {
enqueue(&(game_state->queue_state), game_state, draw, NULL, to_draw_state, enqueue(
&(game_state->queue_state),
game_state,
draw,
NULL,
to_draw_state,
game_state->settings.message_duration); game_state->settings.message_duration);
} }
} else { } else {
enqueue(&(game_state->queue_state), game_state, drawDealerCard, NULL, dealer_card_animation, enqueue(
&(game_state->queue_state),
game_state,
drawDealerCard,
NULL,
dealer_card_animation,
game_state->settings.animation_duration); game_state->settings.animation_duration);
} }
} }
@@ -296,7 +321,8 @@ void settings_tick(GameState *game_state) {
game_state->selectedMenu--; game_state->selectedMenu--;
} }
if (game_state->selectDirection == DirectionLeft || game_state->selectDirection == DirectionRight) { if(game_state->selectDirection == DirectionLeft ||
game_state->selectDirection == DirectionRight) {
int nextScore = 0; int nextScore = 0;
switch(game_state->selectedMenu) { switch(game_state->selectedMenu) {
case 0: case 0:
@@ -341,7 +367,6 @@ void settings_tick(GameState *game_state) {
break; break;
} }
} }
} }
void tick(GameState* game_state) { void tick(GameState* game_state) {
@@ -362,21 +387,39 @@ void tick(GameState *game_state) {
if(!game_state->started) { if(!game_state->started) {
game_state->selectedMenu = 0; game_state->selectedMenu = 0;
game_state->started = true; game_state->started = true;
enqueue(&(game_state->queue_state), game_state, drawDealerCard, NULL, dealer_back_card_animation, enqueue(
&(game_state->queue_state),
game_state,
drawDealerCard,
NULL,
dealer_back_card_animation,
game_state->settings.animation_duration); game_state->settings.animation_duration);
enqueue(&(game_state->queue_state), game_state, drawPlayerCard, NULL, player_card_animation, enqueue(
&(game_state->queue_state),
game_state,
drawPlayerCard,
NULL,
player_card_animation,
game_state->settings.animation_duration); game_state->settings.animation_duration);
enqueue(&(game_state->queue_state), game_state, drawDealerCard, NULL, dealer_card_animation, enqueue(
&(game_state->queue_state),
game_state,
drawDealerCard,
NULL,
dealer_card_animation,
game_state->settings.animation_duration); game_state->settings.animation_duration);
enqueue(&(game_state->queue_state), game_state, drawPlayerCard, NULL, player_card_animation, enqueue(
&(game_state->queue_state),
game_state,
drawPlayerCard,
NULL,
player_card_animation,
game_state->settings.animation_duration); game_state->settings.animation_duration);
} }
if (!queue_ran) if(!queue_ran) player_tick(game_state);
player_tick(game_state);
break; break;
case GameStateDealer: case GameStateDealer:
if (!queue_ran) if(!queue_ran) dealer_tick(game_state);
dealer_tick(game_state);
break; break;
case GameStateSettings: case GameStateSettings:
settings_tick(game_state); settings_tick(game_state);
@@ -386,7 +429,6 @@ void tick(GameState *game_state) {
} }
game_state->selectDirection = None; game_state->selectDirection = None;
} }
void start_round(GameState* game_state) { void start_round(GameState* game_state) {
@@ -440,15 +482,31 @@ void doubleAction(void *state){
game_state->player_score -= game_state->settings.round_price; game_state->player_score -= game_state->settings.round_price;
game_state->bet += game_state->settings.round_price; game_state->bet += game_state->settings.round_price;
game_state->doubled = true; game_state->doubled = true;
enqueue(&(game_state->queue_state), game_state, drawPlayerCard, NULL, player_card_animation, enqueue(
&(game_state->queue_state),
game_state,
drawPlayerCard,
NULL,
player_card_animation,
game_state->settings.animation_duration); game_state->settings.animation_duration);
game_state->player_cards[game_state->player_card_count] = game_state->deck.cards[game_state->deck.index]; game_state->player_cards[game_state->player_card_count] =
game_state->deck.cards[game_state->deck.index];
uint8_t score = hand_count(game_state->player_cards, game_state->player_card_count + 1); uint8_t score = hand_count(game_state->player_cards, game_state->player_card_count + 1);
if(score > 21) { if(score > 21) {
enqueue(&(game_state->queue_state), game_state, lose, NULL, to_bust_state, enqueue(
&(game_state->queue_state),
game_state,
lose,
NULL,
to_bust_state,
game_state->settings.message_duration); game_state->settings.message_duration);
} else { } else {
enqueue(&(game_state->queue_state), game_state, dealerTurn, NULL, to_dealer_turn, enqueue(
&(game_state->queue_state),
game_state,
dealerTurn,
NULL,
to_dealer_turn,
game_state->settings.message_duration); game_state->settings.message_duration);
} }
set_menu_state(game_state->menu, 0, false); set_menu_state(game_state->menu, 0, false);
@@ -457,12 +515,22 @@ void doubleAction(void *state){
void hitAction(void* state) { void hitAction(void* state) {
GameState* game_state = state; GameState* game_state = state;
enqueue(&(game_state->queue_state), game_state, drawPlayerCard, NULL, player_card_animation, enqueue(
&(game_state->queue_state),
game_state,
drawPlayerCard,
NULL,
player_card_animation,
game_state->settings.animation_duration); game_state->settings.animation_duration);
} }
void stayAction(void* state) { void stayAction(void* state) {
GameState* game_state = state; GameState* game_state = state;
enqueue(&(game_state->queue_state), game_state, dealerTurn, NULL, to_dealer_turn, enqueue(
&(game_state->queue_state),
game_state,
dealerTurn,
NULL,
to_dealer_turn,
game_state->settings.message_duration); game_state->settings.message_duration);
} }
@@ -495,8 +563,7 @@ int32_t blackjack_app(void *p) {
view_port_draw_callback_set(view_port, render_callback, &state_mutex); view_port_draw_callback_set(view_port, render_callback, &state_mutex);
view_port_input_callback_set(view_port, input_callback, event_queue); view_port_input_callback_set(view_port, input_callback, event_queue);
FuriTimer *timer = FuriTimer* timer = furi_timer_alloc(update_timer_callback, FuriTimerTypePeriodic, event_queue);
furi_timer_alloc(update_timer_callback, FuriTimerTypePeriodic, event_queue);
furi_timer_start(timer, furi_kernel_get_tick_frequency() / 25); furi_timer_start(timer, furi_kernel_get_tick_frequency() / 25);
Gui* gui = furi_record_open("gui"); Gui* gui = furi_record_open("gui");
@@ -509,7 +576,6 @@ int32_t blackjack_app(void *p) {
GameState* localstate = (GameState*)acquire_mutex_block(&state_mutex); GameState* localstate = (GameState*)acquire_mutex_block(&state_mutex);
if(event_status == FuriStatusOk) { if(event_status == FuriStatusOk) {
if(event.type == EventTypeKey) { if(event.type == EventTypeKey) {
if(event.input.type == InputTypePress) { if(event.input.type == InputTypePress) {
switch(event.input.key) { switch(event.input.key) {
case InputKeyUp: case InputKeyUp:
@@ -550,7 +616,6 @@ int32_t blackjack_app(void *p) {
release_mutex(&state_mutex, localstate); release_mutex(&state_mutex, localstate);
} }
furi_timer_free(timer); furi_timer_free(timer);
view_port_enabled_set(view_port, false); view_port_enabled_set(view_port, false);
gui_remove_view_port(gui, view_port); gui_remove_view_port(gui, view_port);

View File

@@ -65,8 +65,13 @@ void set_card_graphics(const Icon *graphics) {
card_graphics = (Icon*)graphics; card_graphics = (Icon*)graphics;
} }
void void draw_card_at_colored(
draw_card_at_colored(int8_t pos_x, int8_t pos_y, uint8_t pip, uint8_t character, bool inverted, Canvas *const canvas) { int8_t pos_x,
int8_t pos_y,
uint8_t pip,
uint8_t character,
bool inverted,
Canvas* const canvas) {
DrawMode primary = inverted ? Black : White; DrawMode primary = inverted ? Black : White;
DrawMode secondary = inverted ? White : Black; DrawMode secondary = inverted ? White : Black;
draw_rounded_box(canvas, pos_x, pos_y, CARD_WIDTH, CARD_HEIGHT, primary); draw_rounded_box(canvas, pos_x, pos_y, CARD_WIDTH, CARD_HEIGHT, primary);
@@ -80,10 +85,8 @@ draw_card_at_colored(int8_t pos_x, int8_t pos_y, uint8_t pip, uint8_t character,
uint8_t top = pos_y + 2; uint8_t top = pos_y + 2;
uint8_t bottom = (pos_y + CARD_HEIGHT - s - 2); uint8_t bottom = (pos_y + CARD_HEIGHT - s - 2);
draw_icon_clip(canvas, card_graphics, right, top, px, py, s, s, draw_icon_clip(canvas, card_graphics, right, top, px, py, s, s, secondary);
secondary); draw_icon_clip_flipped(canvas, card_graphics, left, bottom, px, py, s, s, secondary);
draw_icon_clip_flipped(canvas, card_graphics, left, bottom, px, py, s, s,
secondary);
drawInfo = letters[character]; drawInfo = letters[character];
px = drawInfo[0], py = drawInfo[1], s = drawInfo[2]; px = drawInfo[0], py = drawInfo[1], s = drawInfo[2];
@@ -92,10 +95,8 @@ draw_card_at_colored(int8_t pos_x, int8_t pos_y, uint8_t pip, uint8_t character,
top = pos_y + 2; top = pos_y + 2;
bottom = (pos_y + CARD_HEIGHT - s - 2); bottom = (pos_y + CARD_HEIGHT - s - 2);
draw_icon_clip(canvas, card_graphics, left, top + 1, px, py, s, s, draw_icon_clip(canvas, card_graphics, left, top + 1, px, py, s, s, secondary);
secondary); draw_icon_clip_flipped(canvas, card_graphics, right, bottom - 1, px, py, s, s, secondary);
draw_icon_clip_flipped(canvas, card_graphics, right, bottom - 1, px, py, s, s,
secondary);
} }
void draw_card_at(int8_t pos_x, int8_t pos_y, uint8_t pip, uint8_t character, Canvas* const canvas) { void draw_card_at(int8_t pos_x, int8_t pos_y, uint8_t pip, uint8_t character, Canvas* const canvas) {
@@ -104,15 +105,17 @@ void draw_card_at(int8_t pos_x, int8_t pos_y, uint8_t pip, uint8_t character, Ca
void draw_deck(const Card* cards, uint8_t count, Canvas* const canvas) { void draw_deck(const Card* cards, uint8_t count, Canvas* const canvas) {
for(int i = count - 1; i >= 0; i--) { for(int i = count - 1; i >= 0; i--) {
draw_card_at(playerCardPositions[i][0], playerCardPositions[i][1], cards[i].pip, cards[i].character, canvas); draw_card_at(
playerCardPositions[i][0],
playerCardPositions[i][1],
cards[i].pip,
cards[i].character,
canvas);
} }
} }
Vector card_pos_at_index(uint8_t index) { Vector card_pos_at_index(uint8_t index) {
return (Vector) { return (Vector){playerCardPositions[index][0], playerCardPositions[index][1]};
playerCardPositions[index][0],
playerCardPositions[index][1]
};
} }
void draw_card_back_at(int8_t pos_x, int8_t pos_y, Canvas* const canvas) { void draw_card_back_at(int8_t pos_x, int8_t pos_y, Canvas* const canvas) {
@@ -120,7 +123,6 @@ void draw_card_back_at(int8_t pos_x, int8_t pos_y, Canvas *const canvas) {
draw_rounded_box_frame(canvas, pos_x, pos_y, CARD_WIDTH, CARD_HEIGHT, Black); draw_rounded_box_frame(canvas, pos_x, pos_y, CARD_WIDTH, CARD_HEIGHT, Black);
draw_icon_clip(canvas, card_graphics, pos_x + 1, pos_y + 1, 35, 0, 15, 21, Black); draw_icon_clip(canvas, card_graphics, pos_x + 1, pos_y + 1, 35, 0, 15, 21, Black);
} }
void generate_deck(Deck* deck_ptr, uint8_t deck_count) { void generate_deck(Deck* deck_ptr, uint8_t deck_count) {
@@ -133,10 +135,7 @@ void generate_deck(Deck *deck_ptr, uint8_t deck_count) {
for(uint8_t deck = 0; deck < deck_count; deck++) { for(uint8_t deck = 0; deck < deck_count; deck++) {
for(uint8_t pip = 0; pip < 4; pip++) { for(uint8_t pip = 0; pip < 4; pip++) {
for(uint8_t label = 0; label < 13; label++) { for(uint8_t label = 0; label < 13; label++) {
deck_ptr->cards[counter] = (Card) deck_ptr->cards[counter] = (Card){pip, label, false, false};
{
pip, label, false, false
};
counter++; counter++;
} }
} }
@@ -171,14 +170,22 @@ uint8_t hand_count(const Card *cards, uint8_t count) {
} }
for(uint8_t i = 0; i < aceCount; i++) { for(uint8_t i = 0; i < aceCount; i++) {
if ((score + 11) <= 21) score += 11; if((score + 11) <= 21)
else score++; score += 11;
else
score++;
} }
return score; return score;
} }
void draw_card_animation(Card animatingCard, Vector from, Vector control, Vector to, float t, bool extra_margin, void draw_card_animation(
Card animatingCard,
Vector from,
Vector control,
Vector to,
float t,
bool extra_margin,
Canvas* const canvas) { Canvas* const canvas) {
float time = t; float time = t;
if(extra_margin) { if(extra_margin) {
@@ -187,14 +194,14 @@ void draw_card_animation(Card animatingCard, Vector from, Vector control, Vector
Vector currentPos = quadratic_2d(from, control, to, time); Vector currentPos = quadratic_2d(from, control, to, time);
if(t > 1) { if(t > 1) {
draw_card_at(currentPos.x, currentPos.y, animatingCard.pip, draw_card_at(
animatingCard.character, canvas); currentPos.x, currentPos.y, animatingCard.pip, animatingCard.character, canvas);
} else { } else {
if(t < 0.5) if(t < 0.5)
draw_card_back_at(currentPos.x, currentPos.y, canvas); draw_card_back_at(currentPos.x, currentPos.y, canvas);
else else
draw_card_at(currentPos.x, currentPos.y, animatingCard.pip, draw_card_at(
animatingCard.character, canvas); currentPos.x, currentPos.y, animatingCard.pip, animatingCard.character, canvas);
} }
} }
@@ -220,10 +227,12 @@ void add_to_hand(Hand *hand_ptr, Card card) {
void draw_card_space(int16_t pos_x, int16_t pos_y, bool highlighted, Canvas* const canvas) { void draw_card_space(int16_t pos_x, int16_t pos_y, bool highlighted, Canvas* const canvas) {
if(highlighted) { if(highlighted) {
draw_rounded_box_frame(canvas, pos_x, pos_y, CARD_WIDTH, CARD_HEIGHT, Black); draw_rounded_box_frame(canvas, pos_x, pos_y, CARD_WIDTH, CARD_HEIGHT, Black);
draw_rounded_box_frame(canvas, pos_x + 2, pos_y + 2, CARD_WIDTH - 4, CARD_HEIGHT - 4, White); draw_rounded_box_frame(
canvas, pos_x + 2, pos_y + 2, CARD_WIDTH - 4, CARD_HEIGHT - 4, White);
} else { } else {
draw_rounded_box(canvas, pos_x, pos_y, CARD_WIDTH, CARD_HEIGHT, Black); draw_rounded_box(canvas, pos_x, pos_y, CARD_WIDTH, CARD_HEIGHT, Black);
draw_rounded_box_frame(canvas, pos_x + 2, pos_y + 2, CARD_WIDTH - 4, CARD_HEIGHT - 4, White); draw_rounded_box_frame(
canvas, pos_x + 2, pos_y + 2, CARD_WIDTH - 4, CARD_HEIGHT - 4, White);
} }
} }
@@ -236,12 +245,16 @@ int first_non_flipped_card(Hand hand) {
return hand.index; return hand.index;
} }
void draw_hand_column(Hand hand, int16_t pos_x, int16_t pos_y, int8_t highlight, Canvas *const canvas) { void draw_hand_column(
Hand hand,
int16_t pos_x,
int16_t pos_y,
int8_t highlight,
Canvas* const canvas) {
if(hand.index == 0) { if(hand.index == 0) {
draw_card_space(pos_x, pos_y, highlight > 0, canvas); draw_card_space(pos_x, pos_y, highlight > 0, canvas);
if(highlight == 0) if(highlight == 0)
draw_rounded_box(canvas, pos_x, pos_y, CARD_WIDTH, CARD_HEIGHT, draw_rounded_box(canvas, pos_x, pos_y, CARD_WIDTH, CARD_HEIGHT, Inverse);
Inverse);
return; return;
} }
@@ -257,9 +270,8 @@ void draw_hand_column(Hand hand, int16_t pos_x, int16_t pos_y, int8_t highlight,
hStart++; hStart++;
wastop = true; wastop = true;
} }
draw_card_at_colored(pos_x, pos_y + pos, hand.cards[first].pip, hand.cards[first].character, draw_card_at_colored(
false, pos_x, pos_y + pos, hand.cards[first].pip, hand.cards[first].character, false, canvas);
canvas);
pos += 8; pos += 8;
hStart++; hStart++;
} }
@@ -269,7 +281,11 @@ void draw_hand_column(Hand hand, int16_t pos_x, int16_t pos_y, int8_t highlight,
pos += 4; pos += 4;
hStart++; hStart++;
} }
draw_card_at_colored(pos_x, pos_y + pos, hand.cards[highlight].pip, hand.cards[highlight].character, draw_card_at_colored(
pos_x,
pos_y + pos,
hand.cards[highlight].pip,
hand.cards[highlight].character,
true, true,
canvas); canvas);
pos += 8; pos += 8;
@@ -279,10 +295,14 @@ void draw_hand_column(Hand hand, int16_t pos_x, int16_t pos_y, int8_t highlight,
if(hand.cards[i].flipped) { if(hand.cards[i].flipped) {
draw_card_back_at(pos_x, pos_y + pos, canvas); draw_card_back_at(pos_x, pos_y + pos, canvas);
if(i == highlight) if(i == highlight)
draw_rounded_box(canvas, pos_x+1, pos_y + pos+1, CARD_WIDTH - 2, CARD_HEIGHT - 2, draw_rounded_box(
Inverse); canvas, pos_x + 1, pos_y + pos + 1, CARD_WIDTH - 2, CARD_HEIGHT - 2, Inverse);
} else { } else {
draw_card_at_colored(pos_x, pos_y + pos, hand.cards[i].pip, hand.cards[i].character, draw_card_at_colored(
pos_x,
pos_y + pos,
hand.cards[i].pip,
hand.cards[i].character,
(i == highlight), (i == highlight),
canvas); canvas);
if(i == highlight || i == first) pos += 4; if(i == highlight || i == first) pos += 4;

View File

@@ -63,8 +63,13 @@ void draw_card_at(int8_t pos_x, int8_t pos_y, uint8_t pip, uint8_t character, Ca
* @param inverted Invert colors * @param inverted Invert colors
* @param canvas Pointer to Flipper's canvas object * @param canvas Pointer to Flipper's canvas object
*/ */
void void draw_card_at_colored(
draw_card_at_colored(int8_t pos_x, int8_t pos_y, uint8_t pip, uint8_t character, bool inverted, Canvas *const canvas); int8_t pos_x,
int8_t pos_y,
uint8_t pip,
uint8_t character,
bool inverted,
Canvas* const canvas);
/** /**
* Draws 'count' cards at the bottom right corner * Draws 'count' cards at the bottom right corner
@@ -119,7 +124,13 @@ uint8_t hand_count(const Card *cards, uint8_t count);
* @param extra_margin Use extra margin at the end (arrives 0.2 unit before the end so it can stay there a bit) * @param extra_margin Use extra margin at the end (arrives 0.2 unit before the end so it can stay there a bit)
* @param canvas Pointer to Flipper's canvas object * @param canvas Pointer to Flipper's canvas object
*/ */
void draw_card_animation(Card animatingCard, Vector from, Vector control, Vector to, float t, bool extra_margin, void draw_card_animation(
Card animatingCard,
Vector from,
Vector control,
Vector to,
float t,
bool extra_margin,
Canvas* const canvas); Canvas* const canvas);
/** /**
@@ -159,8 +170,12 @@ void draw_card_space(int16_t pos_x, int16_t pos_y, bool highlighted, Canvas *con
* @param highlight Index to highlight, negative means no highlight * @param highlight Index to highlight, negative means no highlight
* @param canvas Canvas object * @param canvas Canvas object
*/ */
void void draw_hand_column(
draw_hand_column(Hand hand, int16_t pos_x, int16_t pos_y, int8_t highlight, Canvas *const canvas); Hand hand,
int16_t pos_x,
int16_t pos_y,
int8_t highlight,
Canvas* const canvas);
/** /**
* Removes a card from the deck (Be aware, if you remove the first item, the deck index will be at -1 so you have to handle that) * Removes a card from the deck (Be aware, if you remove the first item, the deck index will be at -1 so you have to handle that)

View File

@@ -14,11 +14,7 @@ Vector lerp_2d(Vector start, Vector end, float t) {
} }
Vector quadratic_2d(Vector start, Vector control, Vector end, float t) { Vector quadratic_2d(Vector start, Vector control, Vector end, float t) {
return lerp_2d( return lerp_2d(lerp_2d(start, control, t), lerp_2d(control, end, t), t);
lerp_2d(start, control, t),
lerp_2d(control, end, t),
t
);
} }
Vector vector_add(Vector a, Vector b) { Vector vector_add(Vector a, Vector b) {
@@ -39,10 +35,7 @@ Vector vector_div_components(Vector a, Vector b) {
Vector vector_normalized(Vector a) { Vector vector_normalized(Vector a) {
float length = vector_magnitude(a); float length = vector_magnitude(a);
return (Vector) { return (Vector){a.x / length, a.y / length};
a.x / length,
a.y / length
};
} }
float vector_magnitude(Vector a) { float vector_magnitude(Vector a) {

View File

@@ -22,21 +22,31 @@ void set_menu_state(Menu *menu, uint8_t index, bool state) {
if(menu->menu_count > index) { if(menu->menu_count > index) {
menu->items[index].enabled = state; menu->items[index].enabled = state;
} }
if(!state && menu->current_menu==index) if(!state && menu->current_menu == index) move_menu(menu, 1);
move_menu(menu, 1);
} }
void move_menu(Menu* menu, int8_t direction) { void move_menu(Menu* menu, int8_t direction) {
if(!menu->enabled) return; if(!menu->enabled) return;
int max = menu->menu_count; int max = menu->menu_count;
for(int8_t i = 0; i < max; i++) { for(int8_t i = 0; i < max; i++) {
FURI_LOG_D("MENU", "Iteration %i, current %i, direction %i, state %i", i, menu->current_menu,direction,menu->items[menu->current_menu].enabled?1:0); FURI_LOG_D(
"MENU",
"Iteration %i, current %i, direction %i, state %i",
i,
menu->current_menu,
direction,
menu->items[menu->current_menu].enabled ? 1 : 0);
if(direction < 0 && menu->current_menu == 0) { if(direction < 0 && menu->current_menu == 0) {
menu->current_menu = menu->menu_count - 1; menu->current_menu = menu->menu_count - 1;
} else { } else {
menu->current_menu = (menu->current_menu + direction) % menu->menu_count; menu->current_menu = (menu->current_menu + direction) % menu->menu_count;
} }
FURI_LOG_D("MENU", "After process current %i, direction %i, state %i", menu->current_menu,direction,menu->items[menu->current_menu].enabled?1:0); FURI_LOG_D(
"MENU",
"After process current %i, direction %i, state %i",
menu->current_menu,
direction,
menu->items[menu->current_menu].enabled ? 1 : 0);
if(menu->items[menu->current_menu].enabled) { if(menu->items[menu->current_menu].enabled) {
FURI_LOG_D("MENU", "Next menu %i", menu->current_menu); FURI_LOG_D("MENU", "Next menu %i", menu->current_menu);
return; return;
@@ -75,7 +85,12 @@ void render_menu(Menu *menu, Canvas *canvas, uint8_t pos_x, uint8_t pos_y) {
// canvas_draw_rbox(canvas, pos_x, pos_y, menu->menu_width + 2, 10, 2); // canvas_draw_rbox(canvas, pos_x, pos_y, menu->menu_width + 2, 10, 2);
canvas_set_font(canvas, FontSecondary); canvas_set_font(canvas, FontSecondary);
canvas_draw_str_aligned(canvas, pos_x + menu->menu_width / 2, pos_y + 6, AlignCenter, AlignCenter, canvas_draw_str_aligned(
canvas,
pos_x + menu->menu_width / 2,
pos_y + 6,
AlignCenter,
AlignCenter,
menu->items[menu->current_menu].name); menu->items[menu->current_menu].name);
//9*5 //9*5
int center = pos_x + menu->menu_width / 2; int center = pos_x + menu->menu_width / 2;
@@ -85,5 +100,4 @@ void render_menu(Menu *menu, Canvas *canvas, uint8_t pos_x, uint8_t pos_y) {
canvas_draw_dot(canvas, center + j, pos_y + 14 - i); canvas_draw_dot(canvas, center + j, pos_y + 14 - i);
} }
} }
} }

View File

@@ -7,7 +7,8 @@ typedef struct {
const char* name; //Name of the menu const char* name; //Name of the menu
bool enabled; //Is the menu item enabled (it will not render, you cannot select it) bool enabled; //Is the menu item enabled (it will not render, you cannot select it)
void (*callback)(void *state); //Callback for when the activate_menu is called while this menu is selected void (*callback)(
void* state); //Callback for when the activate_menu is called while this menu is selected
} MenuItem; } MenuItem;
typedef struct { typedef struct {

View File

@@ -1,6 +1,5 @@
#include "queue.h" #include "queue.h"
void render_queue(const QueueState* queue_state, const void* app_state, Canvas* const canvas) { void render_queue(const QueueState* queue_state, const void* app_state, Canvas* const canvas) {
if(queue_state->current != NULL && queue_state->current->render != NULL) if(queue_state->current != NULL && queue_state->current->render != NULL)
((QueueItem*)queue_state->current)->render(app_state, canvas); ((QueueItem*)queue_state->current)->render(app_state, canvas);
@@ -23,8 +22,7 @@ void dequeue(QueueState *queue_state, void *app_state) {
queue_state->current = f->next; queue_state->current = f->next;
free(f); free(f);
if(queue_state->current != NULL) { if(queue_state->current != NULL) {
if (queue_state->current->start != NULL) if(queue_state->current->start != NULL) queue_state->current->start(app_state);
queue_state->current->start(app_state);
queue_state->start = furi_get_tick(); queue_state->start = furi_get_tick();
} else { } else {
queue_state->running = false; queue_state->running = false;
@@ -41,20 +39,25 @@ void queue_clear(QueueState *queue_state) {
} }
} }
void enqueue(QueueState *queue_state, void *app_state, void enqueue(
void(*done)(void *state), void(*start)(void *state), QueueState* queue_state,
void (*render)(const void *state, Canvas *const canvas), uint32_t duration) { void* app_state,
void (*done)(void* state),
void (*start)(void* state),
void (*render)(const void* state, Canvas* const canvas),
uint32_t duration) {
QueueItem* next; QueueItem* next;
if(queue_state->current == NULL) { if(queue_state->current == NULL) {
queue_state->start = furi_get_tick(); queue_state->start = furi_get_tick();
queue_state->current = malloc(sizeof(QueueItem)); queue_state->current = malloc(sizeof(QueueItem));
next = queue_state->current; next = queue_state->current;
if (next->start != NULL) if(next->start != NULL) next->start(app_state);
next->start(app_state);
} else { } else {
next = queue_state->current; next = queue_state->current;
while (next->next != NULL) { next = (QueueItem *) (next->next); } while(next->next != NULL) {
next = (QueueItem*)(next->next);
}
next->next = malloc(sizeof(QueueItem)); next->next = malloc(sizeof(QueueItem));
next = next->next; next = next->next;
} }

View File

@@ -5,7 +5,9 @@
typedef struct { typedef struct {
void (*callback)(void* state); //Callback for when the item is dequeued void (*callback)(void* state); //Callback for when the item is dequeued
void (*render)(const void *state, Canvas *const canvas); //Callback for the rendering loop while this item is running void (*render)(
const void* state,
Canvas* const canvas); //Callback for the rendering loop while this item is running
void (*start)(void* state); //Callback when this item is started running void (*start)(void* state); //Callback when this item is started running
void* next; //Pointer to the next item void* next; //Pointer to the next item
uint32_t duration; //duration of the item uint32_t duration; //duration of the item
@@ -27,9 +29,13 @@ typedef struct {
* @param render Callback to render loop if needed * @param render Callback to render loop if needed
* @param duration Length of the item * @param duration Length of the item
*/ */
void enqueue(QueueState *queue_state, void *app_state, void enqueue(
void(*done)(void *state), void(*start)(void *state), QueueState* queue_state,
void (*render)(const void *state, Canvas *const canvas), uint32_t duration); void* app_state,
void (*done)(void* state),
void (*start)(void* state),
void (*render)(const void* state, Canvas* const canvas),
uint32_t duration);
/** /**
* Clears all queue items * Clears all queue items
* *

View File

@@ -12,8 +12,7 @@ uint8_t tileMapCount = 0;
void ui_cleanup() { void ui_cleanup() {
if(tileMap != NULL) { if(tileMap != NULL) {
for(uint8_t i = 0; i < tileMapCount; i++) { for(uint8_t i = 0; i < tileMapCount; i++) {
if (tileMap[i].data != NULL) if(tileMap[i].data != NULL) free(tileMap[i].data);
free(tileMap[i].data);
} }
free(tileMap); free(tileMap);
} }
@@ -24,17 +23,14 @@ void add_new_tilemap(uint8_t *data, unsigned long iconId) {
tileMapCount++; tileMapCount++;
tileMap = malloc(sizeof(TileMap) * tileMapCount); tileMap = malloc(sizeof(TileMap) * tileMapCount);
if(tileMapCount > 1) { if(tileMapCount > 1) {
for (uint8_t i = 0; i < tileMapCount; i++) for(uint8_t i = 0; i < tileMapCount; i++) tileMap[i] = old[i];
tileMap[i] = old[i];
} }
tileMap[tileMapCount - 1] = (TileMap){data, iconId}; tileMap[tileMapCount - 1] = (TileMap){data, iconId};
} }
uint8_t* get_tilemap(unsigned long icon_id) { uint8_t* get_tilemap(unsigned long icon_id) {
for(uint8_t i = 0; i < tileMapCount; i++) { for(uint8_t i = 0; i < tileMapCount; i++) {
if (tileMap[i].iconId == icon_id) if(tileMap[i].iconId == icon_id) return tileMap[i].data;
return tileMap[i].data;
} }
return NULL; return NULL;
@@ -80,7 +76,6 @@ void clone_buffer(uint8_t* canvas, uint8_t* data){
} }
} }
bool read_pixel(Canvas* const canvas, int16_t x, int16_t y) { bool read_pixel(Canvas* const canvas, int16_t x, int16_t y) {
if(in_screen(x, y)) { if(in_screen(x, y)) {
return test_pixel(get_buffer(canvas), x, y, SCREEN_WIDTH); return test_pixel(get_buffer(canvas), x, y, SCREEN_WIDTH);
@@ -108,7 +103,13 @@ void set_pixel(Canvas *const canvas, int16_t x, int16_t y, DrawMode draw_mode) {
} }
} }
void draw_line(Canvas *const canvas, int16_t x1, int16_t y1, int16_t x2, int16_t y2, DrawMode draw_mode) { void draw_line(
Canvas* const canvas,
int16_t x1,
int16_t y1,
int16_t x2,
int16_t y2,
DrawMode draw_mode) {
for(int16_t x = x2; x >= x1; x--) { for(int16_t x = x2; x >= x1; x--) {
for(int16_t y = y2; y >= y1; y--) { for(int16_t y = y2; y >= y1; y--) {
set_pixel(canvas, x, y, draw_mode); set_pixel(canvas, x, y, draw_mode);
@@ -116,7 +117,13 @@ void draw_line(Canvas *const canvas, int16_t x1, int16_t y1, int16_t x2, int16_t
} }
} }
void draw_rounded_box_frame(Canvas *const canvas, int16_t x, int16_t y, uint8_t w, uint8_t h, DrawMode draw_mode) { void draw_rounded_box_frame(
Canvas* const canvas,
int16_t x,
int16_t y,
uint8_t w,
uint8_t h,
DrawMode draw_mode) {
int16_t xMinCorner = x + 1; int16_t xMinCorner = x + 1;
int16_t xMax = x + w - 1; int16_t xMax = x + w - 1;
int16_t xMaxCorner = x + w - 2; int16_t xMaxCorner = x + w - 2;
@@ -129,7 +136,13 @@ void draw_rounded_box_frame(Canvas *const canvas, int16_t x, int16_t y, uint8_t
draw_line(canvas, xMax, yMinCorner, xMax, yMaxCorner, draw_mode); draw_line(canvas, xMax, yMinCorner, xMax, yMaxCorner, draw_mode);
} }
void draw_rounded_box(Canvas *const canvas, int16_t x, int16_t y, uint8_t w, uint8_t h, DrawMode draw_mode) { void draw_rounded_box(
Canvas* const canvas,
int16_t x,
int16_t y,
uint8_t w,
uint8_t h,
DrawMode draw_mode) {
for(int16_t o = w - 2; o >= 1; o--) { for(int16_t o = w - 2; o >= 1; o--) {
for(int16_t p = h - 2; p >= 1; p--) { for(int16_t p = h - 2; p >= 1; p--) {
set_pixel(canvas, x + o, y + p, draw_mode); set_pixel(canvas, x + o, y + p, draw_mode);
@@ -142,7 +155,14 @@ void invert_shape(Canvas *const canvas, uint8_t *data, int16_t x, int16_t y, uin
draw_pixels(canvas, data, x, y, w, h, Inverse); draw_pixels(canvas, data, x, y, w, h, Inverse);
} }
void draw_pixels(Canvas *const canvas, uint8_t *data, int16_t x, int16_t y, uint8_t w, uint8_t h, DrawMode drawMode) { void draw_pixels(
Canvas* const canvas,
uint8_t* data,
int16_t x,
int16_t y,
uint8_t w,
uint8_t h,
DrawMode drawMode) {
for(int8_t o = 0; o < w; o++) { for(int8_t o = 0; o < w; o++) {
for(int8_t p = 0; p < h; p++) { for(int8_t p = 0; p < h; p++) {
if(in_screen(o + x, p + y) && data[p * w + o] == 1) if(in_screen(o + x, p + y) && data[p * w + o] == 1)
@@ -151,7 +171,13 @@ void draw_pixels(Canvas *const canvas, uint8_t *data, int16_t x, int16_t y, uint
} }
} }
void draw_rectangle(Canvas *const canvas, int16_t x, int16_t y, uint8_t w, uint8_t h, DrawMode drawMode) { void draw_rectangle(
Canvas* const canvas,
int16_t x,
int16_t y,
uint8_t w,
uint8_t h,
DrawMode drawMode) {
for(int8_t o = 0; o < w; o++) { for(int8_t o = 0; o < w; o++) {
for(int8_t p = 0; p < h; p++) { for(int8_t p = 0; p < h; p++) {
if(in_screen(o + x, p + y)) { if(in_screen(o + x, p + y)) {
@@ -183,8 +209,16 @@ uint8_t *getOrAddIconData(Canvas *const canvas, const Icon *icon) {
return icon_data; return icon_data;
} }
void draw_icon_clip(Canvas *const canvas, const Icon *icon, int16_t x, int16_t y, uint8_t left, uint8_t top, uint8_t w, void draw_icon_clip(
uint8_t h, DrawMode drawMode) { Canvas* const canvas,
const Icon* icon,
int16_t x,
int16_t y,
uint8_t left,
uint8_t top,
uint8_t w,
uint8_t h,
DrawMode drawMode) {
uint8_t* icon_data = getOrAddIconData(canvas, icon); uint8_t* icon_data = getOrAddIconData(canvas, icon);
for(int i = 0; i < w; i++) { for(int i = 0; i < w; i++) {
@@ -198,9 +232,16 @@ void draw_icon_clip(Canvas *const canvas, const Icon *icon, int16_t x, int16_t y
} }
} }
void draw_icon_clip_flipped(Canvas *const canvas, const Icon *icon, int16_t x, int16_t y, uint8_t left, uint8_t top, void draw_icon_clip_flipped(
Canvas* const canvas,
const Icon* icon,
int16_t x,
int16_t y,
uint8_t left,
uint8_t top,
uint8_t w, uint8_t w,
uint8_t h, DrawMode drawMode) { uint8_t h,
DrawMode drawMode) {
uint8_t* icon_data = getOrAddIconData(canvas, icon); uint8_t* icon_data = getOrAddIconData(canvas, icon);
for(int i = 0; i < w; i++) { for(int i = 0; i < w; i++) {

View File

@@ -26,29 +26,76 @@ uint8_t *image_data(Canvas *const canvas, const Icon *icon);
uint32_t pixel_index(uint8_t x, uint8_t y); uint32_t pixel_index(uint8_t x, uint8_t y);
void draw_icon_clip(Canvas *const canvas, const Icon *icon, int16_t x, int16_t y, uint8_t left, uint8_t top, uint8_t w, void draw_icon_clip(
uint8_t h, DrawMode drawMode); Canvas* const canvas,
const Icon* icon,
int16_t x,
int16_t y,
uint8_t left,
uint8_t top,
uint8_t w,
uint8_t h,
DrawMode drawMode);
void draw_icon_clip_flipped(Canvas *const canvas, const Icon *icon, int16_t x, int16_t y, uint8_t left, uint8_t top, uint8_t w, void draw_icon_clip_flipped(
uint8_t h, DrawMode drawMode); Canvas* const canvas,
const Icon* icon,
int16_t x,
int16_t y,
uint8_t left,
uint8_t top,
uint8_t w,
uint8_t h,
DrawMode drawMode);
void draw_rounded_box(Canvas *const canvas, int16_t x, int16_t y, uint8_t w, uint8_t h, DrawMode drawMode); void draw_rounded_box(
Canvas* const canvas,
int16_t x,
int16_t y,
uint8_t w,
uint8_t h,
DrawMode drawMode);
void draw_rounded_box_frame(Canvas *const canvas, int16_t x, int16_t y, uint8_t w, uint8_t h, DrawMode drawMode); void draw_rounded_box_frame(
Canvas* const canvas,
int16_t x,
int16_t y,
uint8_t w,
uint8_t h,
DrawMode drawMode);
void draw_rectangle(Canvas *const canvas, int16_t x, int16_t y, uint8_t w, uint8_t h, DrawMode drawMode); void draw_rectangle(
Canvas* const canvas,
int16_t x,
int16_t y,
uint8_t w,
uint8_t h,
DrawMode drawMode);
void invert_rectangle(Canvas* const canvas, int16_t x, int16_t y, uint8_t w, uint8_t h); void invert_rectangle(Canvas* const canvas, int16_t x, int16_t y, uint8_t w, uint8_t h);
void invert_shape(Canvas* const canvas, uint8_t* data, int16_t x, int16_t y, uint8_t w, uint8_t h); void invert_shape(Canvas* const canvas, uint8_t* data, int16_t x, int16_t y, uint8_t w, uint8_t h);
void draw_pixels(Canvas *const canvas, uint8_t *data, int16_t x, int16_t y, uint8_t w, uint8_t h, DrawMode drawMode); void draw_pixels(
Canvas* const canvas,
uint8_t* data,
int16_t x,
int16_t y,
uint8_t w,
uint8_t h,
DrawMode drawMode);
bool read_pixel(Canvas* const canvas, int16_t x, int16_t y); bool read_pixel(Canvas* const canvas, int16_t x, int16_t y);
void set_pixel(Canvas* const canvas, int16_t x, int16_t y, DrawMode draw_mode); void set_pixel(Canvas* const canvas, int16_t x, int16_t y, DrawMode draw_mode);
void draw_line(Canvas *const canvas, int16_t x1, int16_t y1, int16_t x2, int16_t y2, DrawMode draw_mode); void draw_line(
Canvas* const canvas,
int16_t x1,
int16_t y1,
int16_t x2,
int16_t y2,
DrawMode draw_mode);
bool in_screen(int16_t x, int16_t y); bool in_screen(int16_t x, int16_t y);

View File

@@ -74,4 +74,3 @@ typedef struct {
Menu* menu; Menu* menu;
unsigned int last_tick; unsigned int last_tick;
} GameState; } GameState;

View File

@@ -6,23 +6,19 @@
#define LINE_HEIGHT 16 #define LINE_HEIGHT 16
#define ITEM_PADDING 4 #define ITEM_PADDING 4
const char MoneyMul[4] = { const char MoneyMul[4] = {'K', 'B', 'T', 'S'};
'K', 'B', 'T', 'S'
};
void draw_player_scene(Canvas* const canvas, const GameState* game_state) { void draw_player_scene(Canvas* const canvas, const GameState* game_state) {
int max_card = game_state->player_card_count; int max_card = game_state->player_card_count;
if (max_card > 0) if(max_card > 0) draw_deck((game_state->player_cards), max_card, canvas);
draw_deck((game_state->player_cards), max_card, canvas);
if (game_state->dealer_card_count > 0) if(game_state->dealer_card_count > 0) draw_card_back_at(13, 5, canvas);
draw_card_back_at(13, 5, canvas);
max_card = game_state->dealer_card_count; max_card = game_state->dealer_card_count;
if(max_card > 1) { if(max_card > 1) {
draw_card_at(2, 2, game_state->dealer_cards[1].pip, game_state->dealer_cards[1].character, draw_card_at(
canvas); 2, 2, game_state->dealer_cards[1].pip, game_state->dealer_cards[1].character, canvas);
} }
} }
@@ -39,11 +35,12 @@ void popup_frame(Canvas *const canvas) {
canvas_set_font(canvas, FontSecondary); canvas_set_font(canvas, FontSecondary);
} }
void draw_play_menu(Canvas* const canvas, const GameState* game_state) { void draw_play_menu(Canvas* const canvas, const GameState* game_state) {
const char* menus[3] = {"Double", "Hit", "Stay"}; const char* menus[3] = {"Double", "Hit", "Stay"};
for(uint8_t m = 0; m < 3; m++) { for(uint8_t m = 0; m < 3; m++) {
if (m == 0 && (game_state->doubled || game_state->player_score < game_state->settings.round_price)) continue; if(m == 0 &&
(game_state->doubled || game_state->player_score < game_state->settings.round_price))
continue;
int y = m * 13 + 25; int y = m * 13 + 25;
canvas_set_color(canvas, ColorBlack); canvas_set_color(canvas, ColorBlack);
@@ -68,8 +65,7 @@ void draw_play_menu(Canvas *const canvas, const GameState *game_state) {
void draw_screen(Canvas* const canvas, const bool* points) { void draw_screen(Canvas* const canvas, const bool* points) {
for(uint8_t x = 0; x < 128; x++) { for(uint8_t x = 0; x < 128; x++) {
for(uint8_t y = 0; y < 64; y++) { for(uint8_t y = 0; y < 64; y++) {
if (points[y * 128 + x]) if(points[y * 128 + x]) canvas_draw_dot(canvas, x, y);
canvas_draw_dot(canvas, x, y);
} }
} }
} }
@@ -104,8 +100,13 @@ void draw_money(Canvas *const canvas, uint32_t score) {
canvas_draw_str_aligned(canvas, 126, 2, AlignRight, AlignTop, drawChar); canvas_draw_str_aligned(canvas, 126, 2, AlignRight, AlignTop, drawChar);
} }
void draw_menu(
void draw_menu(Canvas *const canvas, const char *text, const char *value, int8_t y, bool left_caret, bool right_caret, Canvas* const canvas,
const char* text,
const char* value,
int8_t y,
bool left_caret,
bool right_caret,
bool selected) { bool selected) {
UNUSED(selected); UNUSED(selected);
if(y < 0 || y >= 64) return; if(y < 0 || y >= 64) return;
@@ -117,8 +118,7 @@ void draw_menu(Canvas *const canvas, const char *text, const char *value, int8_t
} }
canvas_draw_str_aligned(canvas, 4, y + ITEM_PADDING, AlignLeft, AlignTop, text); canvas_draw_str_aligned(canvas, 4, y + ITEM_PADDING, AlignLeft, AlignTop, text);
if (left_caret) if(left_caret) canvas_draw_str_aligned(canvas, 80, y + ITEM_PADDING, AlignLeft, AlignTop, "<");
canvas_draw_str_aligned(canvas, 80, y + ITEM_PADDING, AlignLeft, AlignTop, "<");
canvas_draw_str_aligned(canvas, 100, y + ITEM_PADDING, AlignCenter, AlignTop, value); canvas_draw_str_aligned(canvas, 100, y + ITEM_PADDING, AlignCenter, AlignTop, value);
if(right_caret) if(right_caret)
canvas_draw_str_aligned(canvas, 120, y + ITEM_PADDING, AlignRight, AlignTop, ">"); canvas_draw_str_aligned(canvas, 120, y + ITEM_PADDING, AlignRight, AlignTop, ">");
@@ -136,45 +136,51 @@ void settings_page(Canvas *const canvas, const GameState *gameState) {
int scrollHeight = round(64 / 6.0) + ITEM_PADDING * 2; int scrollHeight = round(64 / 6.0) + ITEM_PADDING * 2;
int scrollPos = 64 / (6.0 / (gameState->selectedMenu + 1)) - ITEM_PADDING * 2; int scrollPos = 64 / (6.0 / (gameState->selectedMenu + 1)) - ITEM_PADDING * 2;
canvas_set_color(canvas, ColorBlack); canvas_set_color(canvas, ColorBlack);
canvas_draw_box(canvas, 123, scrollPos, 4, scrollHeight); canvas_draw_box(canvas, 123, scrollPos, 4, scrollHeight);
canvas_draw_box(canvas, 125, 0, 1, 64); canvas_draw_box(canvas, 125, 0, 1, 64);
snprintf(drawChar, sizeof(drawChar), "%li", gameState->settings.starting_money); snprintf(drawChar, sizeof(drawChar), "%li", gameState->settings.starting_money);
draw_menu(canvas, "Start money", drawChar, draw_menu(
canvas,
"Start money",
drawChar,
0 * LINE_HEIGHT + startY, 0 * LINE_HEIGHT + startY,
gameState->settings.starting_money > gameState->settings.round_price, gameState->settings.starting_money > gameState->settings.round_price,
gameState->settings.starting_money < 400, gameState->settings.starting_money < 400,
gameState->selectedMenu == 0 gameState->selectedMenu == 0);
);
snprintf(drawChar, sizeof(drawChar), "%li", gameState->settings.round_price); snprintf(drawChar, sizeof(drawChar), "%li", gameState->settings.round_price);
draw_menu(canvas, "Round price", drawChar, draw_menu(
canvas,
"Round price",
drawChar,
1 * LINE_HEIGHT + startY, 1 * LINE_HEIGHT + startY,
gameState->settings.round_price > 10, gameState->settings.round_price > 10,
gameState->settings.round_price < gameState->settings.starting_money, gameState->settings.round_price < gameState->settings.starting_money,
gameState->selectedMenu == 1 gameState->selectedMenu == 1);
);
snprintf(drawChar, sizeof(drawChar), "%li", gameState->settings.animation_duration); snprintf(drawChar, sizeof(drawChar), "%li", gameState->settings.animation_duration);
draw_menu(canvas, "Anim. length", drawChar, draw_menu(
canvas,
"Anim. length",
drawChar,
2 * LINE_HEIGHT + startY, 2 * LINE_HEIGHT + startY,
gameState->settings.animation_duration > 0, gameState->settings.animation_duration > 0,
gameState->settings.animation_duration < 2000, gameState->settings.animation_duration < 2000,
gameState->selectedMenu == 2 gameState->selectedMenu == 2);
);
snprintf(drawChar, sizeof(drawChar), "%li", gameState->settings.message_duration); snprintf(drawChar, sizeof(drawChar), "%li", gameState->settings.message_duration);
draw_menu(canvas, "Popup time", drawChar, draw_menu(
canvas,
"Popup time",
drawChar,
3 * LINE_HEIGHT + startY, 3 * LINE_HEIGHT + startY,
gameState->settings.message_duration > 0, gameState->settings.message_duration > 0,
gameState->settings.message_duration < 2000, gameState->settings.message_duration < 2000,
gameState->selectedMenu == 3 gameState->selectedMenu == 3);
);
// draw_menu(canvas, "Sound", gameState->settings.sound_effects ? "Yes" : "No", // draw_menu(canvas, "Sound", gameState->settings.sound_effects ? "Yes" : "No",
// 5 * LINE_HEIGHT + startY, // 5 * LINE_HEIGHT + startY,
// true, // true,
// true, // true,
// gameState->selectedMenu == 5 // gameState->selectedMenu == 5
// ); // );
} }

View File

@@ -8,9 +8,10 @@ void save_settings(Settings settings) {
FlipperFormat* file = flipper_format_file_alloc(storage); FlipperFormat* file = flipper_format_file_alloc(storage);
FURI_LOG_D(APP_NAME, "Saving config"); FURI_LOG_D(APP_NAME, "Saving config");
if(flipper_format_file_open_existing(file, CONFIG_FILE_PATH)) { if(flipper_format_file_open_existing(file, CONFIG_FILE_PATH)) {
FURI_LOG_D(APP_NAME, "Saving %s: %ld", CONF_ANIMATION_DURATION, settings.animation_duration); FURI_LOG_D(
flipper_format_update_uint32(file, CONF_ANIMATION_DURATION, &(settings.animation_duration), 1); APP_NAME, "Saving %s: %ld", CONF_ANIMATION_DURATION, settings.animation_duration);
flipper_format_update_uint32(
file, CONF_ANIMATION_DURATION, &(settings.animation_duration), 1);
FURI_LOG_D(APP_NAME, "Saving %s: %ld", CONF_MESSAGE_DURATION, settings.message_duration); FURI_LOG_D(APP_NAME, "Saving %s: %ld", CONF_MESSAGE_DURATION, settings.message_duration);
flipper_format_update_uint32(file, CONF_MESSAGE_DURATION, &(settings.message_duration), 1); flipper_format_update_uint32(file, CONF_MESSAGE_DURATION, &(settings.message_duration), 1);
@@ -77,8 +78,7 @@ Settings load_settings() {
if(!flipper_format_file_open_existing(file, CONFIG_FILE_PATH)) { if(!flipper_format_file_open_existing(file, CONFIG_FILE_PATH)) {
FURI_LOG_E(APP_NAME, "Error opening existing file %s", CONFIG_FILE_PATH); FURI_LOG_E(APP_NAME, "Error opening existing file %s", CONFIG_FILE_PATH);
flipper_format_file_close(file); flipper_format_file_close(file);
} } else {
else {
uint32_t value; uint32_t value;
bool valueBool; bool valueBool;
FURI_LOG_D(APP_NAME, "Checking version"); FURI_LOG_D(APP_NAME, "Checking version");

View File

@@ -65,10 +65,8 @@ size_t calc_waveform_period(float freq) {
return 0; return 0;
} }
// DMA Rate calculation, thanks to Dr_Zlo // DMA Rate calculation, thanks to Dr_Zlo
float dma_rate = CPU_CLOCK_FREQ \ float dma_rate = CPU_CLOCK_FREQ / 2 / DTMF_DOLPHIN_HAL_DMA_PRESCALER /
/ 2 \ (DTMF_DOLPHIN_HAL_DMA_AUTORELOAD + 1);
/ DTMF_DOLPHIN_HAL_DMA_PRESCALER \
/ (DTMF_DOLPHIN_HAL_DMA_AUTORELOAD + 1);
// Using a constant scaling modifier, which likely represents // Using a constant scaling modifier, which likely represents
// the combined system overhead and isr latency. // the combined system overhead and isr latency.
@@ -93,7 +91,11 @@ void osc_generate_lookup_table(DTMFDolphinOsc* osc, float freq) {
} }
} }
void filter_generate_lookup_table(DTMFDolphinPulseFilter* pf, uint16_t pulses, uint16_t pulse_ms, uint16_t gap_ms) { void filter_generate_lookup_table(
DTMFDolphinPulseFilter* pf,
uint16_t pulses,
uint16_t pulse_ms,
uint16_t gap_ms) {
if(pf->lookup_table != NULL) { if(pf->lookup_table != NULL) {
free(pf->lookup_table); free(pf->lookup_table);
} }
@@ -165,16 +167,13 @@ void dtmf_dolphin_audio_free(DTMFDolphinAudio* player) {
current_player = NULL; current_player = NULL;
} }
bool generate_waveform(DTMFDolphinAudio* player, uint16_t buffer_index) { bool generate_waveform(DTMFDolphinAudio* player, uint16_t buffer_index) {
uint16_t* sample_buffer_start = &player->sample_buffer[buffer_index]; uint16_t* sample_buffer_start = &player->sample_buffer[buffer_index];
for(size_t i = 0; i < player->half_buffer_length; i++) { for(size_t i = 0; i < player->half_buffer_length; i++) {
float data = 0; float data = 0;
if(player->osc2->period) { if(player->osc2->period) {
data = \ data = (sample_frame(player->osc1) / 2) + (sample_frame(player->osc2) / 2);
(sample_frame(player->osc1) / 2) + \
(sample_frame(player->osc2) / 2);
} else { } else {
data = (sample_frame(player->osc1)); data = (sample_frame(player->osc1));
} }
@@ -196,7 +195,12 @@ bool generate_waveform(DTMFDolphinAudio* player, uint16_t buffer_index) {
return true; return true;
} }
bool dtmf_dolphin_audio_play_tones(float freq1, float freq2, uint16_t pulses, uint16_t pulse_ms, uint16_t gap_ms) { bool dtmf_dolphin_audio_play_tones(
float freq1,
float freq2,
uint16_t pulses,
uint16_t pulse_ms,
uint16_t gap_ms) {
if(current_player != NULL && current_player->playing) { if(current_player != NULL && current_player->playing) {
// Cannot start playing while still playing something else // Cannot start playing while still playing something else
return false; return false;
@@ -213,7 +217,8 @@ bool dtmf_dolphin_audio_play_tones(float freq1, float freq2, uint16_t pulses, ui
dtmf_dolphin_speaker_init(); dtmf_dolphin_speaker_init();
dtmf_dolphin_dma_init((uint32_t)current_player->sample_buffer, current_player->buffer_length); dtmf_dolphin_dma_init((uint32_t)current_player->sample_buffer, current_player->buffer_length);
furi_hal_interrupt_set_isr(FuriHalInterruptIdDma1Ch1, dtmf_dolphin_audio_dma_isr, current_player->queue); furi_hal_interrupt_set_isr(
FuriHalInterruptIdDma1Ch1, dtmf_dolphin_audio_dma_isr, current_player->queue);
dtmf_dolphin_dma_start(); dtmf_dolphin_dma_start();
dtmf_dolphin_speaker_start(); dtmf_dolphin_speaker_start();
@@ -226,7 +231,8 @@ bool dtmf_dolphin_audio_stop_tones() {
// Can't stop a player that isn't playing. // Can't stop a player that isn't playing.
return false; return false;
} }
while(current_player->filter->offset > 0 && current_player->filter->offset < current_player->filter->duration) { while(current_player->filter->offset > 0 &&
current_player->filter->offset < current_player->filter->duration) {
// run remaining ticks if needed to complete filter sequence // run remaining ticks if needed to complete filter sequence
dtmf_dolphin_audio_handle_tick(); dtmf_dolphin_audio_handle_tick();
} }

View File

@@ -42,7 +42,12 @@ void dtmf_dolphin_audio_free(DTMFDolphinAudio* player);
void dtmf_dolphin_osc_free(DTMFDolphinOsc* osc); void dtmf_dolphin_osc_free(DTMFDolphinOsc* osc);
bool dtmf_dolphin_audio_play_tones(float freq1, float freq2, uint16_t pulses, uint16_t pulse_ms, uint16_t gap_ms); bool dtmf_dolphin_audio_play_tones(
float freq1,
float freq2,
uint16_t pulses,
uint16_t pulse_ms,
uint16_t gap_ms);
bool dtmf_dolphin_audio_stop_tones(); bool dtmf_dolphin_audio_stop_tones();

View File

@@ -44,8 +44,7 @@ DTMFDolphinSceneData DTMFDolphinSceneDataDialer = {
{"0", 941.0, 1336.0, {3, 1, 1}, 0, 0, 0}, {"0", 941.0, 1336.0, {3, 1, 1}, 0, 0, 0},
{"#", 941.0, 1477.0, {3, 2, 1}, 0, 0, 0}, {"#", 941.0, 1477.0, {3, 2, 1}, 0, 0, 0},
{"D", 941.0, 1633.0, {3, 3, 1}, 0, 0, 0}, {"D", 941.0, 1633.0, {3, 3, 1}, 0, 0, 0},
} }};
};
DTMFDolphinSceneData DTMFDolphinSceneDataBluebox = { DTMFDolphinSceneData DTMFDolphinSceneDataBluebox = {
.name = "Bluebox", .name = "Bluebox",
@@ -65,8 +64,7 @@ DTMFDolphinSceneData DTMFDolphinSceneDataBluebox = {
{"KP", 1100.0, 1700.0, {0, 3, 2}, 0, 0, 0}, {"KP", 1100.0, 1700.0, {0, 3, 2}, 0, 0, 0},
{"ST", 1500.0, 1700.0, {1, 3, 2}, 0, 0, 0}, {"ST", 1500.0, 1700.0, {1, 3, 2}, 0, 0, 0},
{"2600", 2600.0, 0.0, {3, 2, 3}, 0, 0, 0}, {"2600", 2600.0, 0.0, {3, 2, 3}, 0, 0, 0},
} }};
};
DTMFDolphinSceneData DTMFDolphinSceneDataRedboxUS = { DTMFDolphinSceneData DTMFDolphinSceneDataRedboxUS = {
.name = "Redbox (US)", .name = "Redbox (US)",
@@ -77,8 +75,7 @@ DTMFDolphinSceneData DTMFDolphinSceneDataRedboxUS = {
{"Dime", 1700.0, 2200.0, {1, 0, 5}, 2, 66, 66}, {"Dime", 1700.0, 2200.0, {1, 0, 5}, 2, 66, 66},
{"Quarter", 1700.0, 2200.0, {2, 0, 5}, 5, 33, 33}, {"Quarter", 1700.0, 2200.0, {2, 0, 5}, 5, 33, 33},
{"Dollar", 1700.0, 2200.0, {3, 0, 5}, 1, 650, 0}, {"Dollar", 1700.0, 2200.0, {3, 0, 5}, 1, 650, 0},
} }};
};
DTMFDolphinSceneData DTMFDolphinSceneDataRedboxCA = { DTMFDolphinSceneData DTMFDolphinSceneDataRedboxCA = {
.name = "Redbox (CA)", .name = "Redbox (CA)",
@@ -88,8 +85,7 @@ DTMFDolphinSceneData DTMFDolphinSceneDataRedboxCA = {
{"Nickel", 2200.0, 0.0, {0, 0, 5}, 1, 66, 0}, {"Nickel", 2200.0, 0.0, {0, 0, 5}, 1, 66, 0},
{"Dime", 2200.0, 0.0, {1, 0, 5}, 2, 66, 66}, {"Dime", 2200.0, 0.0, {1, 0, 5}, 2, 66, 66},
{"Quarter", 2200.0, 0.0, {2, 0, 5}, 5, 33, 33}, {"Quarter", 2200.0, 0.0, {2, 0, 5}, 5, 33, 33},
} }};
};
DTMFDolphinSceneData DTMFDolphinSceneDataRedboxUK = { DTMFDolphinSceneData DTMFDolphinSceneDataRedboxUK = {
.name = "Redbox (UK)", .name = "Redbox (UK)",
@@ -98,8 +94,7 @@ DTMFDolphinSceneData DTMFDolphinSceneDataRedboxUK = {
.tones = { .tones = {
{"10p", 1000.0, 0.0, {0, 0, 5}, 1, 200, 0}, {"10p", 1000.0, 0.0, {0, 0, 5}, 1, 200, 0},
{"50p", 1000.0, 0.0, {1, 0, 5}, 1, 350, 0}, {"50p", 1000.0, 0.0, {1, 0, 5}, 1, 350, 0},
} }};
};
DTMFDolphinSceneData DTMFDolphinSceneDataMisc = { DTMFDolphinSceneData DTMFDolphinSceneDataMisc = {
.name = "Misc", .name = "Misc",
@@ -109,8 +104,7 @@ DTMFDolphinSceneData DTMFDolphinSceneDataMisc = {
{"CCITT 11", 700.0, 1700.0, {0, 0, 5}, 0, 0, 0}, {"CCITT 11", 700.0, 1700.0, {0, 0, 5}, 0, 0, 0},
{"CCITT 12", 900.0, 1700.0, {1, 0, 5}, 0, 0, 0}, {"CCITT 12", 900.0, 1700.0, {1, 0, 5}, 0, 0, 0},
{"CCITT KP2", 1300.0, 1700.0, {2, 0, 5}, 0, 0, 0}, {"CCITT KP2", 1300.0, 1700.0, {2, 0, 5}, 0, 0, 0},
} }};
};
DTMFDolphinToneSection current_section; DTMFDolphinToneSection current_section;
DTMFDolphinSceneData* current_scene_data; DTMFDolphinSceneData* current_scene_data;
@@ -118,8 +112,7 @@ DTMFDolphinSceneData *current_scene_data;
void dtmf_dolphin_data_set_current_section(DTMFDolphinToneSection section) { void dtmf_dolphin_data_set_current_section(DTMFDolphinToneSection section) {
current_section = section; current_section = section;
switch (current_section) switch(current_section) {
{
case DTMF_DOLPHIN_TONE_BLOCK_BLUEBOX: case DTMF_DOLPHIN_TONE_BLOCK_BLUEBOX:
current_scene_data = &DTMFDolphinSceneDataBluebox; current_scene_data = &DTMFDolphinSceneDataBluebox;
break; break;
@@ -161,7 +154,12 @@ bool dtmf_dolphin_data_get_tone_frequencies(float *freq1, float *freq2, uint8_t
return false; return false;
} }
bool dtmf_dolphin_data_get_filter_data(uint16_t *pulses, uint16_t *pulse_ms, uint16_t *gap_ms, uint8_t row, uint8_t col) { bool dtmf_dolphin_data_get_filter_data(
uint16_t* pulses,
uint16_t* pulse_ms,
uint16_t* gap_ms,
uint8_t row,
uint8_t col) {
for(size_t i = 0; i < current_scene_data->tone_count; i++) { for(size_t i = 0; i < current_scene_data->tone_count; i++) {
DTMFDolphinTones tones = current_scene_data->tones[i]; DTMFDolphinTones tones = current_scene_data->tones[i];
if(tones.pos.row == row && tones.pos.col == col) { if(tones.pos.row == row && tones.pos.col == col) {
@@ -205,8 +203,7 @@ void dtmf_dolphin_tone_get_max_pos(uint8_t* max_rows, uint8_t* max_cols, uint8_t
max_cols[0] = tones.pos.col; max_cols[0] = tones.pos.col;
} }
tmp_rowspan[tones.pos.row] += tones.pos.span; tmp_rowspan[tones.pos.row] += tones.pos.span;
if (tmp_rowspan[tones.pos.row] > max_span[0]) if(tmp_rowspan[tones.pos.row] > max_span[0]) max_span[0] = tmp_rowspan[tones.pos.row];
max_span[0] = tmp_rowspan[tones.pos.row];
} }
max_rows[0]++; max_rows[0]++;
max_cols[0]++; max_cols[0]++;

View File

@@ -19,7 +19,12 @@ DTMFDolphinToneSection dtmf_dolphin_data_get_current_section();
bool dtmf_dolphin_data_get_tone_frequencies(float* freq1, float* freq2, uint8_t row, uint8_t col); bool dtmf_dolphin_data_get_tone_frequencies(float* freq1, float* freq2, uint8_t row, uint8_t col);
bool dtmf_dolphin_data_get_filter_data(uint16_t *pulses, uint16_t *pulse_ms, uint16_t *gap_ms, uint8_t row, uint8_t col); bool dtmf_dolphin_data_get_filter_data(
uint16_t* pulses,
uint16_t* pulse_ms,
uint16_t* gap_ms,
uint8_t row,
uint8_t col);
const char* dtmf_dolphin_data_get_tone_name(uint8_t row, uint8_t col); const char* dtmf_dolphin_data_get_tone_name(uint8_t row, uint8_t col);

View File

@@ -17,7 +17,6 @@
#define TAG "DTMFDolphin" #define TAG "DTMFDolphin"
enum DTMFDolphinSceneState { enum DTMFDolphinSceneState {
DTMFDolphinSceneStateDialer, DTMFDolphinSceneStateDialer,
DTMFDolphinSceneStateBluebox, DTMFDolphinSceneStateBluebox,
@@ -39,7 +38,4 @@ typedef struct {
NotificationApp* notification; NotificationApp* notification;
} DTMFDolphinApp; } DTMFDolphinApp;
typedef enum { typedef enum { DTMFDolphinViewMainMenu, DTMFDolphinViewDialer } DTMFDolphinView;
DTMFDolphinViewMainMenu,
DTMFDolphinViewDialer
} DTMFDolphinView;

View File

@@ -2,14 +2,12 @@
// #include "../dtmf_dolphin_data.h" // #include "../dtmf_dolphin_data.h"
// #include "../dtmf_dolphin_audio.h" // #include "../dtmf_dolphin_audio.h"
void dtmf_dolphin_scene_dialer_on_enter(void* context) { void dtmf_dolphin_scene_dialer_on_enter(void* context) {
DTMFDolphinApp* app = context; DTMFDolphinApp* app = context;
DTMFDolphinScene scene_id = DTMFDolphinSceneDialer; DTMFDolphinScene scene_id = DTMFDolphinSceneDialer;
enum DTMFDolphinSceneState state = scene_manager_get_scene_state(app->scene_manager, scene_id); enum DTMFDolphinSceneState state = scene_manager_get_scene_state(app->scene_manager, scene_id);
switch (state) switch(state) {
{
case DTMFDolphinSceneStateBluebox: case DTMFDolphinSceneStateBluebox:
dtmf_dolphin_data_set_current_section(DTMF_DOLPHIN_TONE_BLOCK_BLUEBOX); dtmf_dolphin_data_set_current_section(DTMF_DOLPHIN_TONE_BLOCK_BLUEBOX);
break; break;

View File

@@ -3,8 +3,7 @@
static void dtmf_dolphin_scene_start_main_menu_enter_callback(void* context, uint32_t index) { static void dtmf_dolphin_scene_start_main_menu_enter_callback(void* context, uint32_t index) {
DTMFDolphinApp* app = context; DTMFDolphinApp* app = context;
uint8_t cust_event = 255; uint8_t cust_event = 255;
switch (index) switch(index) {
{
case 0: case 0:
cust_event = DTMFDolphinEventStartDialer; cust_event = DTMFDolphinEventStartDialer;
break; break;
@@ -24,10 +23,7 @@ static void dtmf_dolphin_scene_start_main_menu_enter_callback(void* context, uin
return; return;
} }
view_dispatcher_send_custom_event( view_dispatcher_send_custom_event(app->view_dispatcher, cust_event);
app->view_dispatcher,
cust_event
);
} }
void dtmf_dolphin_scene_start_on_enter(void* context) { void dtmf_dolphin_scene_start_on_enter(void* context) {
@@ -36,9 +32,7 @@ void dtmf_dolphin_scene_start_on_enter(void* context) {
// VariableItem* item; // VariableItem* item;
variable_item_list_set_enter_callback( variable_item_list_set_enter_callback(
var_item_list, var_item_list, dtmf_dolphin_scene_start_main_menu_enter_callback, app);
dtmf_dolphin_scene_start_main_menu_enter_callback,
app);
variable_item_list_add(var_item_list, "Dialer", 0, NULL, context); variable_item_list_add(var_item_list, "Dialer", 0, NULL, context);
variable_item_list_add(var_item_list, "Bluebox", 0, NULL, context); variable_item_list_add(var_item_list, "Bluebox", 0, NULL, context);
@@ -47,12 +41,9 @@ void dtmf_dolphin_scene_start_on_enter(void* context) {
variable_item_list_add(var_item_list, "Misc", 0, NULL, context); variable_item_list_add(var_item_list, "Misc", 0, NULL, context);
variable_item_list_set_selected_item( variable_item_list_set_selected_item(
var_item_list, var_item_list, scene_manager_get_scene_state(app->scene_manager, DTMFDolphinSceneStart));
scene_manager_get_scene_state(app->scene_manager, DTMFDolphinSceneStart));
view_dispatcher_switch_to_view( view_dispatcher_switch_to_view(app->view_dispatcher, DTMFDolphinViewMainMenu);
app->view_dispatcher,
DTMFDolphinViewMainMenu);
} }
bool dtmf_dolphin_scene_start_on_event(void* context, SceneManagerEvent event) { bool dtmf_dolphin_scene_start_on_event(void* context, SceneManagerEvent event) {
@@ -63,8 +54,7 @@ bool dtmf_dolphin_scene_start_on_event(void* context, SceneManagerEvent event) {
if(event.type == SceneManagerEventTypeCustom) { if(event.type == SceneManagerEventTypeCustom) {
uint8_t sc_state; uint8_t sc_state;
switch (event.event) switch(event.event) {
{
case DTMFDolphinEventStartDialer: case DTMFDolphinEventStartDialer:
sc_state = DTMFDolphinSceneStateDialer; sc_state = DTMFDolphinSceneStateDialer;
break; break;

View File

@@ -24,16 +24,14 @@ static bool dtmf_dolphin_dialer_process_up(DTMFDolphinDialer* dtmf_dolphin_diale
static bool dtmf_dolphin_dialer_process_down(DTMFDolphinDialer* dtmf_dolphin_dialer); static bool dtmf_dolphin_dialer_process_down(DTMFDolphinDialer* dtmf_dolphin_dialer);
static bool dtmf_dolphin_dialer_process_left(DTMFDolphinDialer* dtmf_dolphin_dialer); static bool dtmf_dolphin_dialer_process_left(DTMFDolphinDialer* dtmf_dolphin_dialer);
static bool dtmf_dolphin_dialer_process_right(DTMFDolphinDialer* dtmf_dolphin_dialer); static bool dtmf_dolphin_dialer_process_right(DTMFDolphinDialer* dtmf_dolphin_dialer);
static bool dtmf_dolphin_dialer_process_ok(DTMFDolphinDialer* dtmf_dolphin_dialer, InputEvent* event); static bool
dtmf_dolphin_dialer_process_ok(DTMFDolphinDialer* dtmf_dolphin_dialer, InputEvent* event);
void draw_button(Canvas* canvas, uint8_t row, uint8_t col, bool invert) { void draw_button(Canvas* canvas, uint8_t row, uint8_t col, bool invert) {
uint8_t left = DTMF_DOLPHIN_NUMPAD_X + // ((col + 1) * DTMF_DOLPHIN_BUTTON_PADDING) +
uint8_t left = DTMF_DOLPHIN_NUMPAD_X + \
// ((col + 1) * DTMF_DOLPHIN_BUTTON_PADDING) +
(col * DTMF_DOLPHIN_BUTTON_WIDTH); (col * DTMF_DOLPHIN_BUTTON_WIDTH);
// (col * DTMF_DOLPHIN_BUTTON_PADDING); // (col * DTMF_DOLPHIN_BUTTON_PADDING);
uint8_t top = DTMF_DOLPHIN_NUMPAD_Y + \ uint8_t top = DTMF_DOLPHIN_NUMPAD_Y + // ((row + 1) * DTMF_DOLPHIN_BUTTON_PADDING) +
// ((row + 1) * DTMF_DOLPHIN_BUTTON_PADDING) +
(row * DTMF_DOLPHIN_BUTTON_HEIGHT); (row * DTMF_DOLPHIN_BUTTON_HEIGHT);
// (row * DTMF_DOLPHIN_BUTTON_PADDING); // (row * DTMF_DOLPHIN_BUTTON_PADDING);
@@ -46,31 +44,35 @@ void draw_button(Canvas* canvas, uint8_t row, uint8_t col, bool invert) {
canvas_set_color(canvas, ColorBlack); canvas_set_color(canvas, ColorBlack);
if(invert) if(invert)
canvas_draw_rbox(canvas, left, top, canvas_draw_rbox(
canvas,
left,
top,
(DTMF_DOLPHIN_BUTTON_WIDTH * span) - (DTMF_DOLPHIN_BUTTON_PADDING * 2), (DTMF_DOLPHIN_BUTTON_WIDTH * span) - (DTMF_DOLPHIN_BUTTON_PADDING * 2),
DTMF_DOLPHIN_BUTTON_HEIGHT - (DTMF_DOLPHIN_BUTTON_PADDING * 2), DTMF_DOLPHIN_BUTTON_HEIGHT - (DTMF_DOLPHIN_BUTTON_PADDING * 2),
2); 2);
else else
canvas_draw_rframe(canvas, left, top, canvas_draw_rframe(
canvas,
left,
top,
(DTMF_DOLPHIN_BUTTON_WIDTH * span) - (DTMF_DOLPHIN_BUTTON_PADDING * 2), (DTMF_DOLPHIN_BUTTON_WIDTH * span) - (DTMF_DOLPHIN_BUTTON_PADDING * 2),
DTMF_DOLPHIN_BUTTON_HEIGHT - (DTMF_DOLPHIN_BUTTON_PADDING * 2), DTMF_DOLPHIN_BUTTON_HEIGHT - (DTMF_DOLPHIN_BUTTON_PADDING * 2),
2); 2);
if (invert) if(invert) canvas_invert_color(canvas);
canvas_invert_color(canvas);
canvas_set_font(canvas, FontSecondary); canvas_set_font(canvas, FontSecondary);
// canvas_set_color(canvas, invert ? ColorWhite : ColorBlack); // canvas_set_color(canvas, invert ? ColorWhite : ColorBlack);
canvas_draw_str_aligned(canvas, canvas_draw_str_aligned(
canvas,
left - 1 + (int)((DTMF_DOLPHIN_BUTTON_WIDTH * span) / 2), left - 1 + (int)((DTMF_DOLPHIN_BUTTON_WIDTH * span) / 2),
top + (int)(DTMF_DOLPHIN_BUTTON_HEIGHT / 2), top + (int)(DTMF_DOLPHIN_BUTTON_HEIGHT / 2),
AlignCenter, AlignCenter,
AlignCenter, AlignCenter,
dtmf_dolphin_data_get_tone_name(row, col)); dtmf_dolphin_data_get_tone_name(row, col));
if (invert) if(invert) canvas_invert_color(canvas);
canvas_invert_color(canvas);
} }
void draw_dialer(Canvas* canvas, void* _model) { void draw_dialer(Canvas* canvas, void* _model) {
@@ -94,7 +96,8 @@ void draw_dialer(Canvas* canvas, void* _model) {
void update_frequencies(DTMFDolphinDialerModel* model) { void update_frequencies(DTMFDolphinDialerModel* model) {
dtmf_dolphin_data_get_tone_frequencies(&model->freq1, &model->freq2, model->row, model->col); dtmf_dolphin_data_get_tone_frequencies(&model->freq1, &model->freq2, model->row, model->col);
dtmf_dolphin_data_get_filter_data(&model->pulses, &model->pulse_ms, &model->gap_ms, model->row, model->col); dtmf_dolphin_data_get_filter_data(
&model->pulses, &model->pulse_ms, &model->gap_ms, model->row, model->col);
} }
static void dtmf_dolphin_dialer_draw_callback(Canvas* canvas, void* _model) { static void dtmf_dolphin_dialer_draw_callback(Canvas* canvas, void* _model) {
@@ -122,11 +125,15 @@ static void dtmf_dolphin_dialer_draw_callback(Canvas* canvas, void* _model) {
canvas_set_font(canvas, FontPrimary); canvas_set_font(canvas, FontPrimary);
elements_multiline_text(canvas, 2, 10, dtmf_dolphin_data_get_current_section_name()); elements_multiline_text(canvas, 2, 10, dtmf_dolphin_data_get_current_section_name());
canvas_draw_line(canvas, canvas_draw_line(
(max_span * DTMF_DOLPHIN_BUTTON_WIDTH) + 1, 0, canvas,
(max_span * DTMF_DOLPHIN_BUTTON_WIDTH) + 1, canvas_height(canvas)); (max_span * DTMF_DOLPHIN_BUTTON_WIDTH) + 1,
0,
(max_span * DTMF_DOLPHIN_BUTTON_WIDTH) + 1,
canvas_height(canvas));
elements_multiline_text(canvas, (max_span * DTMF_DOLPHIN_BUTTON_WIDTH) + 4, 10, "Detail"); elements_multiline_text(canvas, (max_span * DTMF_DOLPHIN_BUTTON_WIDTH) + 4, 10, "Detail");
canvas_draw_line(canvas, 0, DTMF_DOLPHIN_NUMPAD_Y - 3, canvas_width(canvas), DTMF_DOLPHIN_NUMPAD_Y - 3); canvas_draw_line(
canvas, 0, DTMF_DOLPHIN_NUMPAD_Y - 3, canvas_width(canvas), DTMF_DOLPHIN_NUMPAD_Y - 3);
// elements_multiline_text_aligned(canvas, 64, 2, AlignCenter, AlignTop, "Dialer Mode"); // elements_multiline_text_aligned(canvas, 64, 2, AlignCenter, AlignTop, "Dialer Mode");
draw_dialer(canvas, model); draw_dialer(canvas, model);
@@ -140,28 +147,19 @@ static void dtmf_dolphin_dialer_draw_callback(Canvas* canvas, void* _model) {
(unsigned int)model->freq1, (unsigned int)model->freq1,
(unsigned int)model->freq2); (unsigned int)model->freq2);
} else if(model->freq1) { } else if(model->freq1) {
furi_string_cat_printf( furi_string_cat_printf(output, "Single Tone\nF: %u Hz\n", (unsigned int)model->freq1);
output,
"Single Tone\nF: %u Hz\n",
(unsigned int) model->freq1);
} }
canvas_set_font(canvas, FontSecondary); canvas_set_font(canvas, FontSecondary);
canvas_set_color(canvas, ColorBlack); canvas_set_color(canvas, ColorBlack);
if(model->pulse_ms) { if(model->pulse_ms) {
furi_string_cat_printf( furi_string_cat_printf(output, "P: %u * %u ms\n", model->pulses, model->pulse_ms);
output,
"P: %u * %u ms\n",
model->pulses,
model->pulse_ms);
} }
if(model->gap_ms) { if(model->gap_ms) {
furi_string_cat_printf( furi_string_cat_printf(output, "Gaps: %u ms\n", model->gap_ms);
output,
"Gaps: %u ms\n",
model->gap_ms);
} }
elements_multiline_text(canvas, (max_span * DTMF_DOLPHIN_BUTTON_WIDTH) + 4, 21, furi_string_get_cstr(output)); elements_multiline_text(
canvas, (max_span * DTMF_DOLPHIN_BUTTON_WIDTH) + 4, 21, furi_string_get_cstr(output));
furi_string_free(output); furi_string_free(output);
} }
@@ -275,7 +273,8 @@ static bool dtmf_dolphin_dialer_process_right(DTMFDolphinDialer* dtmf_dolphin_di
return true; return true;
} }
static bool dtmf_dolphin_dialer_process_ok(DTMFDolphinDialer* dtmf_dolphin_dialer, InputEvent* event) { static bool
dtmf_dolphin_dialer_process_ok(DTMFDolphinDialer* dtmf_dolphin_dialer, InputEvent* event) {
bool consumed = false; bool consumed = false;
with_view_model( with_view_model(
@@ -283,7 +282,8 @@ static bool dtmf_dolphin_dialer_process_ok(DTMFDolphinDialer* dtmf_dolphin_diale
DTMFDolphinDialerModel * model, DTMFDolphinDialerModel * model,
{ {
if(event->type == InputTypePress) { if(event->type == InputTypePress) {
model->playing = dtmf_dolphin_audio_play_tones(model->freq1, model->freq2, model->pulses, model->pulse_ms, model->gap_ms); model->playing = dtmf_dolphin_audio_play_tones(
model->freq1, model->freq2, model->pulses, model->pulse_ms, model->gap_ms);
} else if(event->type == InputTypeRelease) { } else if(event->type == InputTypeRelease) {
model->playing = !dtmf_dolphin_audio_stop_tones(); model->playing = !dtmf_dolphin_audio_stop_tones();
} }
@@ -308,15 +308,15 @@ static void dtmf_dolphin_dialer_enter_callback(void* context) {
model->freq2 = 0.0; model->freq2 = 0.0;
model->playing = false; model->playing = false;
}, },
true true);
);
} }
DTMFDolphinDialer* dtmf_dolphin_dialer_alloc() { DTMFDolphinDialer* dtmf_dolphin_dialer_alloc() {
DTMFDolphinDialer* dtmf_dolphin_dialer = malloc(sizeof(DTMFDolphinDialer)); DTMFDolphinDialer* dtmf_dolphin_dialer = malloc(sizeof(DTMFDolphinDialer));
dtmf_dolphin_dialer->view = view_alloc(); dtmf_dolphin_dialer->view = view_alloc();
view_allocate_model(dtmf_dolphin_dialer->view, ViewModelTypeLocking, sizeof(DTMFDolphinDialerModel)); view_allocate_model(
dtmf_dolphin_dialer->view, ViewModelTypeLocking, sizeof(DTMFDolphinDialerModel));
with_view_model( with_view_model(
dtmf_dolphin_dialer->view, dtmf_dolphin_dialer->view,
@@ -329,8 +329,7 @@ DTMFDolphinDialer* dtmf_dolphin_dialer_alloc() {
model->freq2 = 0.0; model->freq2 = 0.0;
model->playing = false; model->playing = false;
}, },
true true);
);
view_set_context(dtmf_dolphin_dialer->view, dtmf_dolphin_dialer); view_set_context(dtmf_dolphin_dialer->view, dtmf_dolphin_dialer);
view_set_draw_callback(dtmf_dolphin_dialer->view, dtmf_dolphin_dialer_draw_callback); view_set_draw_callback(dtmf_dolphin_dialer->view, dtmf_dolphin_dialer_draw_callback);
@@ -349,4 +348,3 @@ View* dtmf_dolphin_dialer_get_view(DTMFDolphinDialer* dtmf_dolphin_dialer) {
furi_assert(dtmf_dolphin_dialer); furi_assert(dtmf_dolphin_dialer);
return dtmf_dolphin_dialer->view; return dtmf_dolphin_dialer->view;
} }

View File

@@ -12,4 +12,7 @@ void dtmf_dolphin_dialer_free(DTMFDolphinDialer* dtmf_dolphin_dialer);
View* dtmf_dolphin_dialer_get_view(DTMFDolphinDialer* dtmf_dolphin_dialer); View* dtmf_dolphin_dialer_get_view(DTMFDolphinDialer* dtmf_dolphin_dialer);
void dtmf_dolphin_dialer_set_ok_callback(DTMFDolphinDialer* dtmf_dolphin_dialer, DTMFDolphinDialerOkCallback callback, void* context); void dtmf_dolphin_dialer_set_ok_callback(
DTMFDolphinDialer* dtmf_dolphin_dialer,
DTMFDolphinDialerOkCallback callback,
void* context);

View File

@@ -65,8 +65,13 @@ void set_card_graphics(const Icon *graphics) {
card_graphics = (Icon*)graphics; card_graphics = (Icon*)graphics;
} }
void void draw_card_at_colored(
draw_card_at_colored(int8_t pos_x, int8_t pos_y, uint8_t pip, uint8_t character, bool inverted, Canvas *const canvas) { int8_t pos_x,
int8_t pos_y,
uint8_t pip,
uint8_t character,
bool inverted,
Canvas* const canvas) {
DrawMode primary = inverted ? Black : White; DrawMode primary = inverted ? Black : White;
DrawMode secondary = inverted ? White : Black; DrawMode secondary = inverted ? White : Black;
draw_rounded_box(canvas, pos_x, pos_y, CARD_WIDTH, CARD_HEIGHT, primary); draw_rounded_box(canvas, pos_x, pos_y, CARD_WIDTH, CARD_HEIGHT, primary);
@@ -80,10 +85,8 @@ draw_card_at_colored(int8_t pos_x, int8_t pos_y, uint8_t pip, uint8_t character,
uint8_t top = pos_y + 2; uint8_t top = pos_y + 2;
uint8_t bottom = (pos_y + CARD_HEIGHT - s - 2); uint8_t bottom = (pos_y + CARD_HEIGHT - s - 2);
draw_icon_clip(canvas, card_graphics, right, top, px, py, s, s, draw_icon_clip(canvas, card_graphics, right, top, px, py, s, s, secondary);
secondary); draw_icon_clip_flipped(canvas, card_graphics, left, bottom, px, py, s, s, secondary);
draw_icon_clip_flipped(canvas, card_graphics, left, bottom, px, py, s, s,
secondary);
drawInfo = letters[character]; drawInfo = letters[character];
px = drawInfo[0], py = drawInfo[1], s = drawInfo[2]; px = drawInfo[0], py = drawInfo[1], s = drawInfo[2];
@@ -92,10 +95,8 @@ draw_card_at_colored(int8_t pos_x, int8_t pos_y, uint8_t pip, uint8_t character,
top = pos_y + 2; top = pos_y + 2;
bottom = (pos_y + CARD_HEIGHT - s - 2); bottom = (pos_y + CARD_HEIGHT - s - 2);
draw_icon_clip(canvas, card_graphics, left, top + 1, px, py, s, s, draw_icon_clip(canvas, card_graphics, left, top + 1, px, py, s, s, secondary);
secondary); draw_icon_clip_flipped(canvas, card_graphics, right, bottom - 1, px, py, s, s, secondary);
draw_icon_clip_flipped(canvas, card_graphics, right, bottom - 1, px, py, s, s,
secondary);
} }
void draw_card_at(int8_t pos_x, int8_t pos_y, uint8_t pip, uint8_t character, Canvas* const canvas) { void draw_card_at(int8_t pos_x, int8_t pos_y, uint8_t pip, uint8_t character, Canvas* const canvas) {
@@ -104,15 +105,17 @@ void draw_card_at(int8_t pos_x, int8_t pos_y, uint8_t pip, uint8_t character, Ca
void draw_deck(const Card* cards, uint8_t count, Canvas* const canvas) { void draw_deck(const Card* cards, uint8_t count, Canvas* const canvas) {
for(int i = count - 1; i >= 0; i--) { for(int i = count - 1; i >= 0; i--) {
draw_card_at(playerCardPositions[i][0], playerCardPositions[i][1], cards[i].pip, cards[i].character, canvas); draw_card_at(
playerCardPositions[i][0],
playerCardPositions[i][1],
cards[i].pip,
cards[i].character,
canvas);
} }
} }
Vector card_pos_at_index(uint8_t index) { Vector card_pos_at_index(uint8_t index) {
return (Vector) { return (Vector){playerCardPositions[index][0], playerCardPositions[index][1]};
playerCardPositions[index][0],
playerCardPositions[index][1]
};
} }
void draw_card_back_at(int8_t pos_x, int8_t pos_y, Canvas* const canvas) { void draw_card_back_at(int8_t pos_x, int8_t pos_y, Canvas* const canvas) {
@@ -120,7 +123,6 @@ void draw_card_back_at(int8_t pos_x, int8_t pos_y, Canvas *const canvas) {
draw_rounded_box_frame(canvas, pos_x, pos_y, CARD_WIDTH, CARD_HEIGHT, Black); draw_rounded_box_frame(canvas, pos_x, pos_y, CARD_WIDTH, CARD_HEIGHT, Black);
draw_icon_clip(canvas, card_graphics, pos_x + 1, pos_y + 1, 35, 0, 15, 21, Black); draw_icon_clip(canvas, card_graphics, pos_x + 1, pos_y + 1, 35, 0, 15, 21, Black);
} }
void generate_deck(Deck* deck_ptr, uint8_t deck_count) { void generate_deck(Deck* deck_ptr, uint8_t deck_count) {
@@ -133,10 +135,7 @@ void generate_deck(Deck *deck_ptr, uint8_t deck_count) {
for(uint8_t deck = 0; deck < deck_count; deck++) { for(uint8_t deck = 0; deck < deck_count; deck++) {
for(uint8_t pip = 0; pip < 4; pip++) { for(uint8_t pip = 0; pip < 4; pip++) {
for(uint8_t label = 0; label < 13; label++) { for(uint8_t label = 0; label < 13; label++) {
deck_ptr->cards[counter] = (Card) deck_ptr->cards[counter] = (Card){pip, label, false, false};
{
pip, label, false, false
};
counter++; counter++;
} }
} }
@@ -171,14 +170,22 @@ uint8_t hand_count(const Card *cards, uint8_t count) {
} }
for(uint8_t i = 0; i < aceCount; i++) { for(uint8_t i = 0; i < aceCount; i++) {
if ((score + 11) <= 21) score += 11; if((score + 11) <= 21)
else score++; score += 11;
else
score++;
} }
return score; return score;
} }
void draw_card_animation(Card animatingCard, Vector from, Vector control, Vector to, float t, bool extra_margin, void draw_card_animation(
Card animatingCard,
Vector from,
Vector control,
Vector to,
float t,
bool extra_margin,
Canvas* const canvas) { Canvas* const canvas) {
float time = t; float time = t;
if(extra_margin) { if(extra_margin) {
@@ -187,14 +194,14 @@ void draw_card_animation(Card animatingCard, Vector from, Vector control, Vector
Vector currentPos = quadratic_2d(from, control, to, time); Vector currentPos = quadratic_2d(from, control, to, time);
if(t > 1) { if(t > 1) {
draw_card_at(currentPos.x, currentPos.y, animatingCard.pip, draw_card_at(
animatingCard.character, canvas); currentPos.x, currentPos.y, animatingCard.pip, animatingCard.character, canvas);
} else { } else {
if(t < 0.5) if(t < 0.5)
draw_card_back_at(currentPos.x, currentPos.y, canvas); draw_card_back_at(currentPos.x, currentPos.y, canvas);
else else
draw_card_at(currentPos.x, currentPos.y, animatingCard.pip, draw_card_at(
animatingCard.character, canvas); currentPos.x, currentPos.y, animatingCard.pip, animatingCard.character, canvas);
} }
} }
@@ -220,10 +227,12 @@ void add_to_hand(Hand *hand_ptr, Card card) {
void draw_card_space(int16_t pos_x, int16_t pos_y, bool highlighted, Canvas* const canvas) { void draw_card_space(int16_t pos_x, int16_t pos_y, bool highlighted, Canvas* const canvas) {
if(highlighted) { if(highlighted) {
draw_rounded_box_frame(canvas, pos_x, pos_y, CARD_WIDTH, CARD_HEIGHT, Black); draw_rounded_box_frame(canvas, pos_x, pos_y, CARD_WIDTH, CARD_HEIGHT, Black);
draw_rounded_box_frame(canvas, pos_x + 2, pos_y + 2, CARD_WIDTH - 4, CARD_HEIGHT - 4, White); draw_rounded_box_frame(
canvas, pos_x + 2, pos_y + 2, CARD_WIDTH - 4, CARD_HEIGHT - 4, White);
} else { } else {
draw_rounded_box(canvas, pos_x, pos_y, CARD_WIDTH, CARD_HEIGHT, Black); draw_rounded_box(canvas, pos_x, pos_y, CARD_WIDTH, CARD_HEIGHT, Black);
draw_rounded_box_frame(canvas, pos_x + 2, pos_y + 2, CARD_WIDTH - 4, CARD_HEIGHT - 4, White); draw_rounded_box_frame(
canvas, pos_x + 2, pos_y + 2, CARD_WIDTH - 4, CARD_HEIGHT - 4, White);
} }
} }
@@ -236,12 +245,16 @@ int first_non_flipped_card(Hand hand) {
return hand.index; return hand.index;
} }
void draw_hand_column(Hand hand, int16_t pos_x, int16_t pos_y, int8_t highlight, Canvas *const canvas) { void draw_hand_column(
Hand hand,
int16_t pos_x,
int16_t pos_y,
int8_t highlight,
Canvas* const canvas) {
if(hand.index == 0) { if(hand.index == 0) {
draw_card_space(pos_x, pos_y, highlight > 0, canvas); draw_card_space(pos_x, pos_y, highlight > 0, canvas);
if(highlight == 0) if(highlight == 0)
draw_rounded_box(canvas, pos_x, pos_y, CARD_WIDTH, CARD_HEIGHT, draw_rounded_box(canvas, pos_x, pos_y, CARD_WIDTH, CARD_HEIGHT, Inverse);
Inverse);
return; return;
} }
@@ -257,9 +270,8 @@ void draw_hand_column(Hand hand, int16_t pos_x, int16_t pos_y, int8_t highlight,
hStart++; hStart++;
wastop = true; wastop = true;
} }
draw_card_at_colored(pos_x, pos_y + pos, hand.cards[first].pip, hand.cards[first].character, draw_card_at_colored(
false, pos_x, pos_y + pos, hand.cards[first].pip, hand.cards[first].character, false, canvas);
canvas);
pos += 8; pos += 8;
hStart++; hStart++;
} }
@@ -269,7 +281,11 @@ void draw_hand_column(Hand hand, int16_t pos_x, int16_t pos_y, int8_t highlight,
pos += 4; pos += 4;
hStart++; hStart++;
} }
draw_card_at_colored(pos_x, pos_y + pos, hand.cards[highlight].pip, hand.cards[highlight].character, draw_card_at_colored(
pos_x,
pos_y + pos,
hand.cards[highlight].pip,
hand.cards[highlight].character,
true, true,
canvas); canvas);
pos += 8; pos += 8;
@@ -279,10 +295,14 @@ void draw_hand_column(Hand hand, int16_t pos_x, int16_t pos_y, int8_t highlight,
if(hand.cards[i].flipped) { if(hand.cards[i].flipped) {
draw_card_back_at(pos_x, pos_y + pos, canvas); draw_card_back_at(pos_x, pos_y + pos, canvas);
if(i == highlight) if(i == highlight)
draw_rounded_box(canvas, pos_x+1, pos_y + pos+1, CARD_WIDTH - 2, CARD_HEIGHT - 2, draw_rounded_box(
Inverse); canvas, pos_x + 1, pos_y + pos + 1, CARD_WIDTH - 2, CARD_HEIGHT - 2, Inverse);
} else { } else {
draw_card_at_colored(pos_x, pos_y + pos, hand.cards[i].pip, hand.cards[i].character, draw_card_at_colored(
pos_x,
pos_y + pos,
hand.cards[i].pip,
hand.cards[i].character,
(i == highlight), (i == highlight),
canvas); canvas);
if(i == highlight || i == first) pos += 4; if(i == highlight || i == first) pos += 4;

View File

@@ -63,8 +63,13 @@ void draw_card_at(int8_t pos_x, int8_t pos_y, uint8_t pip, uint8_t character, Ca
* @param inverted Invert colors * @param inverted Invert colors
* @param canvas Pointer to Flipper's canvas object * @param canvas Pointer to Flipper's canvas object
*/ */
void void draw_card_at_colored(
draw_card_at_colored(int8_t pos_x, int8_t pos_y, uint8_t pip, uint8_t character, bool inverted, Canvas *const canvas); int8_t pos_x,
int8_t pos_y,
uint8_t pip,
uint8_t character,
bool inverted,
Canvas* const canvas);
/** /**
* Draws 'count' cards at the bottom right corner * Draws 'count' cards at the bottom right corner
@@ -119,7 +124,13 @@ uint8_t hand_count(const Card *cards, uint8_t count);
* @param extra_margin Use extra margin at the end (arrives 0.2 unit before the end so it can stay there a bit) * @param extra_margin Use extra margin at the end (arrives 0.2 unit before the end so it can stay there a bit)
* @param canvas Pointer to Flipper's canvas object * @param canvas Pointer to Flipper's canvas object
*/ */
void draw_card_animation(Card animatingCard, Vector from, Vector control, Vector to, float t, bool extra_margin, void draw_card_animation(
Card animatingCard,
Vector from,
Vector control,
Vector to,
float t,
bool extra_margin,
Canvas* const canvas); Canvas* const canvas);
/** /**
@@ -159,8 +170,12 @@ void draw_card_space(int16_t pos_x, int16_t pos_y, bool highlighted, Canvas *con
* @param highlight Index to highlight, negative means no highlight * @param highlight Index to highlight, negative means no highlight
* @param canvas Canvas object * @param canvas Canvas object
*/ */
void void draw_hand_column(
draw_hand_column(Hand hand, int16_t pos_x, int16_t pos_y, int8_t highlight, Canvas *const canvas); Hand hand,
int16_t pos_x,
int16_t pos_y,
int8_t highlight,
Canvas* const canvas);
/** /**
* Removes a card from the deck (Be aware, if you remove the first item, the deck index will be at -1 so you have to handle that) * Removes a card from the deck (Be aware, if you remove the first item, the deck index will be at -1 so you have to handle that)

View File

@@ -14,11 +14,7 @@ Vector lerp_2d(Vector start, Vector end, float t) {
} }
Vector quadratic_2d(Vector start, Vector control, Vector end, float t) { Vector quadratic_2d(Vector start, Vector control, Vector end, float t) {
return lerp_2d( return lerp_2d(lerp_2d(start, control, t), lerp_2d(control, end, t), t);
lerp_2d(start, control, t),
lerp_2d(control, end, t),
t
);
} }
Vector vector_add(Vector a, Vector b) { Vector vector_add(Vector a, Vector b) {
@@ -39,10 +35,7 @@ Vector vector_div_components(Vector a, Vector b) {
Vector vector_normalized(Vector a) { Vector vector_normalized(Vector a) {
float length = vector_magnitude(a); float length = vector_magnitude(a);
return (Vector) { return (Vector){a.x / length, a.y / length};
a.x / length,
a.y / length
};
} }
float vector_magnitude(Vector a) { float vector_magnitude(Vector a) {

View File

@@ -22,21 +22,31 @@ void set_menu_state(Menu *menu, uint8_t index, bool state) {
if(menu->menu_count > index) { if(menu->menu_count > index) {
menu->items[index].enabled = state; menu->items[index].enabled = state;
} }
if(!state && menu->current_menu==index) if(!state && menu->current_menu == index) move_menu(menu, 1);
move_menu(menu, 1);
} }
void move_menu(Menu* menu, int8_t direction) { void move_menu(Menu* menu, int8_t direction) {
if(!menu->enabled) return; if(!menu->enabled) return;
int max = menu->menu_count; int max = menu->menu_count;
for(int8_t i = 0; i < max; i++) { for(int8_t i = 0; i < max; i++) {
FURI_LOG_D("MENU", "Iteration %i, current %i, direction %i, state %i", i, menu->current_menu,direction,menu->items[menu->current_menu].enabled?1:0); FURI_LOG_D(
"MENU",
"Iteration %i, current %i, direction %i, state %i",
i,
menu->current_menu,
direction,
menu->items[menu->current_menu].enabled ? 1 : 0);
if(direction < 0 && menu->current_menu == 0) { if(direction < 0 && menu->current_menu == 0) {
menu->current_menu = menu->menu_count - 1; menu->current_menu = menu->menu_count - 1;
} else { } else {
menu->current_menu = (menu->current_menu + direction) % menu->menu_count; menu->current_menu = (menu->current_menu + direction) % menu->menu_count;
} }
FURI_LOG_D("MENU", "After process current %i, direction %i, state %i", menu->current_menu,direction,menu->items[menu->current_menu].enabled?1:0); FURI_LOG_D(
"MENU",
"After process current %i, direction %i, state %i",
menu->current_menu,
direction,
menu->items[menu->current_menu].enabled ? 1 : 0);
if(menu->items[menu->current_menu].enabled) { if(menu->items[menu->current_menu].enabled) {
FURI_LOG_D("MENU", "Next menu %i", menu->current_menu); FURI_LOG_D("MENU", "Next menu %i", menu->current_menu);
return; return;
@@ -75,7 +85,12 @@ void render_menu(Menu *menu, Canvas *canvas, uint8_t pos_x, uint8_t pos_y) {
// canvas_draw_rbox(canvas, pos_x, pos_y, menu->menu_width + 2, 10, 2); // canvas_draw_rbox(canvas, pos_x, pos_y, menu->menu_width + 2, 10, 2);
canvas_set_font(canvas, FontSecondary); canvas_set_font(canvas, FontSecondary);
canvas_draw_str_aligned(canvas, pos_x + menu->menu_width / 2, pos_y + 6, AlignCenter, AlignCenter, canvas_draw_str_aligned(
canvas,
pos_x + menu->menu_width / 2,
pos_y + 6,
AlignCenter,
AlignCenter,
menu->items[menu->current_menu].name); menu->items[menu->current_menu].name);
//9*5 //9*5
int center = pos_x + menu->menu_width / 2; int center = pos_x + menu->menu_width / 2;
@@ -85,5 +100,4 @@ void render_menu(Menu *menu, Canvas *canvas, uint8_t pos_x, uint8_t pos_y) {
canvas_draw_dot(canvas, center + j, pos_y + 14 - i); canvas_draw_dot(canvas, center + j, pos_y + 14 - i);
} }
} }
} }

View File

@@ -7,7 +7,8 @@ typedef struct {
const char* name; //Name of the menu const char* name; //Name of the menu
bool enabled; //Is the menu item enabled (it will not render, you cannot select it) bool enabled; //Is the menu item enabled (it will not render, you cannot select it)
void (*callback)(void *state); //Callback for when the activate_menu is called while this menu is selected void (*callback)(
void* state); //Callback for when the activate_menu is called while this menu is selected
} MenuItem; } MenuItem;
typedef struct { typedef struct {

View File

@@ -1,6 +1,5 @@
#include "queue.h" #include "queue.h"
void render_queue(const QueueState* queue_state, const void* app_state, Canvas* const canvas) { void render_queue(const QueueState* queue_state, const void* app_state, Canvas* const canvas) {
if(queue_state->current != NULL && queue_state->current->render != NULL) if(queue_state->current != NULL && queue_state->current->render != NULL)
((QueueItem*)queue_state->current)->render(app_state, canvas); ((QueueItem*)queue_state->current)->render(app_state, canvas);
@@ -23,8 +22,7 @@ void dequeue(QueueState *queue_state, void *app_state) {
queue_state->current = f->next; queue_state->current = f->next;
free(f); free(f);
if(queue_state->current != NULL) { if(queue_state->current != NULL) {
if (queue_state->current->start != NULL) if(queue_state->current->start != NULL) queue_state->current->start(app_state);
queue_state->current->start(app_state);
queue_state->start = furi_get_tick(); queue_state->start = furi_get_tick();
} else { } else {
queue_state->running = false; queue_state->running = false;
@@ -41,20 +39,25 @@ void queue_clear(QueueState *queue_state) {
} }
} }
void enqueue(QueueState *queue_state, void *app_state, void enqueue(
void(*done)(void *state), void(*start)(void *state), QueueState* queue_state,
void (*render)(const void *state, Canvas *const canvas), uint32_t duration) { void* app_state,
void (*done)(void* state),
void (*start)(void* state),
void (*render)(const void* state, Canvas* const canvas),
uint32_t duration) {
QueueItem* next; QueueItem* next;
if(queue_state->current == NULL) { if(queue_state->current == NULL) {
queue_state->start = furi_get_tick(); queue_state->start = furi_get_tick();
queue_state->current = malloc(sizeof(QueueItem)); queue_state->current = malloc(sizeof(QueueItem));
next = queue_state->current; next = queue_state->current;
if (next->start != NULL) if(next->start != NULL) next->start(app_state);
next->start(app_state);
} else { } else {
next = queue_state->current; next = queue_state->current;
while (next->next != NULL) { next = (QueueItem *) (next->next); } while(next->next != NULL) {
next = (QueueItem*)(next->next);
}
next->next = malloc(sizeof(QueueItem)); next->next = malloc(sizeof(QueueItem));
next = next->next; next = next->next;
} }

View File

@@ -5,7 +5,9 @@
typedef struct { typedef struct {
void (*callback)(void* state); //Callback for when the item is dequeued void (*callback)(void* state); //Callback for when the item is dequeued
void (*render)(const void *state, Canvas *const canvas); //Callback for the rendering loop while this item is running void (*render)(
const void* state,
Canvas* const canvas); //Callback for the rendering loop while this item is running
void (*start)(void* state); //Callback when this item is started running void (*start)(void* state); //Callback when this item is started running
void* next; //Pointer to the next item void* next; //Pointer to the next item
uint32_t duration; //duration of the item uint32_t duration; //duration of the item
@@ -27,9 +29,13 @@ typedef struct {
* @param render Callback to render loop if needed * @param render Callback to render loop if needed
* @param duration Length of the item * @param duration Length of the item
*/ */
void enqueue(QueueState *queue_state, void *app_state, void enqueue(
void(*done)(void *state), void(*start)(void *state), QueueState* queue_state,
void (*render)(const void *state, Canvas *const canvas), uint32_t duration); void* app_state,
void (*done)(void* state),
void (*start)(void* state),
void (*render)(const void* state, Canvas* const canvas),
uint32_t duration);
/** /**
* Clears all queue items * Clears all queue items
* *

View File

@@ -12,8 +12,7 @@ uint8_t tileMapCount = 0;
void ui_cleanup() { void ui_cleanup() {
if(tileMap != NULL) { if(tileMap != NULL) {
for(uint8_t i = 0; i < tileMapCount; i++) { for(uint8_t i = 0; i < tileMapCount; i++) {
if (tileMap[i].data != NULL) if(tileMap[i].data != NULL) free(tileMap[i].data);
free(tileMap[i].data);
} }
free(tileMap); free(tileMap);
} }
@@ -24,17 +23,14 @@ void add_new_tilemap(uint8_t *data, unsigned long iconId) {
tileMapCount++; tileMapCount++;
tileMap = malloc(sizeof(TileMap) * tileMapCount); tileMap = malloc(sizeof(TileMap) * tileMapCount);
if(tileMapCount > 1) { if(tileMapCount > 1) {
for (uint8_t i = 0; i < tileMapCount; i++) for(uint8_t i = 0; i < tileMapCount; i++) tileMap[i] = old[i];
tileMap[i] = old[i];
} }
tileMap[tileMapCount - 1] = (TileMap){data, iconId}; tileMap[tileMapCount - 1] = (TileMap){data, iconId};
} }
uint8_t* get_tilemap(unsigned long icon_id) { uint8_t* get_tilemap(unsigned long icon_id) {
for(uint8_t i = 0; i < tileMapCount; i++) { for(uint8_t i = 0; i < tileMapCount; i++) {
if (tileMap[i].iconId == icon_id) if(tileMap[i].iconId == icon_id) return tileMap[i].data;
return tileMap[i].data;
} }
return NULL; return NULL;
@@ -80,7 +76,6 @@ void clone_buffer(uint8_t* canvas, uint8_t* data){
} }
} }
bool read_pixel(Canvas* const canvas, int16_t x, int16_t y) { bool read_pixel(Canvas* const canvas, int16_t x, int16_t y) {
if(in_screen(x, y)) { if(in_screen(x, y)) {
return test_pixel(get_buffer(canvas), x, y, SCREEN_WIDTH); return test_pixel(get_buffer(canvas), x, y, SCREEN_WIDTH);
@@ -108,7 +103,13 @@ void set_pixel(Canvas *const canvas, int16_t x, int16_t y, DrawMode draw_mode) {
} }
} }
void draw_line(Canvas *const canvas, int16_t x1, int16_t y1, int16_t x2, int16_t y2, DrawMode draw_mode) { void draw_line(
Canvas* const canvas,
int16_t x1,
int16_t y1,
int16_t x2,
int16_t y2,
DrawMode draw_mode) {
for(int16_t x = x2; x >= x1; x--) { for(int16_t x = x2; x >= x1; x--) {
for(int16_t y = y2; y >= y1; y--) { for(int16_t y = y2; y >= y1; y--) {
set_pixel(canvas, x, y, draw_mode); set_pixel(canvas, x, y, draw_mode);
@@ -116,7 +117,13 @@ void draw_line(Canvas *const canvas, int16_t x1, int16_t y1, int16_t x2, int16_t
} }
} }
void draw_rounded_box_frame(Canvas *const canvas, int16_t x, int16_t y, uint8_t w, uint8_t h, DrawMode draw_mode) { void draw_rounded_box_frame(
Canvas* const canvas,
int16_t x,
int16_t y,
uint8_t w,
uint8_t h,
DrawMode draw_mode) {
int16_t xMinCorner = x + 1; int16_t xMinCorner = x + 1;
int16_t xMax = x + w - 1; int16_t xMax = x + w - 1;
int16_t xMaxCorner = x + w - 2; int16_t xMaxCorner = x + w - 2;
@@ -129,7 +136,13 @@ void draw_rounded_box_frame(Canvas *const canvas, int16_t x, int16_t y, uint8_t
draw_line(canvas, xMax, yMinCorner, xMax, yMaxCorner, draw_mode); draw_line(canvas, xMax, yMinCorner, xMax, yMaxCorner, draw_mode);
} }
void draw_rounded_box(Canvas *const canvas, int16_t x, int16_t y, uint8_t w, uint8_t h, DrawMode draw_mode) { void draw_rounded_box(
Canvas* const canvas,
int16_t x,
int16_t y,
uint8_t w,
uint8_t h,
DrawMode draw_mode) {
for(int16_t o = w - 2; o >= 1; o--) { for(int16_t o = w - 2; o >= 1; o--) {
for(int16_t p = h - 2; p >= 1; p--) { for(int16_t p = h - 2; p >= 1; p--) {
set_pixel(canvas, x + o, y + p, draw_mode); set_pixel(canvas, x + o, y + p, draw_mode);
@@ -142,7 +155,14 @@ void invert_shape(Canvas *const canvas, uint8_t *data, int16_t x, int16_t y, uin
draw_pixels(canvas, data, x, y, w, h, Inverse); draw_pixels(canvas, data, x, y, w, h, Inverse);
} }
void draw_pixels(Canvas *const canvas, uint8_t *data, int16_t x, int16_t y, uint8_t w, uint8_t h, DrawMode drawMode) { void draw_pixels(
Canvas* const canvas,
uint8_t* data,
int16_t x,
int16_t y,
uint8_t w,
uint8_t h,
DrawMode drawMode) {
for(int8_t o = 0; o < w; o++) { for(int8_t o = 0; o < w; o++) {
for(int8_t p = 0; p < h; p++) { for(int8_t p = 0; p < h; p++) {
if(in_screen(o + x, p + y) && data[p * w + o] == 1) if(in_screen(o + x, p + y) && data[p * w + o] == 1)
@@ -151,7 +171,13 @@ void draw_pixels(Canvas *const canvas, uint8_t *data, int16_t x, int16_t y, uint
} }
} }
void draw_rectangle(Canvas *const canvas, int16_t x, int16_t y, uint8_t w, uint8_t h, DrawMode drawMode) { void draw_rectangle(
Canvas* const canvas,
int16_t x,
int16_t y,
uint8_t w,
uint8_t h,
DrawMode drawMode) {
for(int8_t o = 0; o < w; o++) { for(int8_t o = 0; o < w; o++) {
for(int8_t p = 0; p < h; p++) { for(int8_t p = 0; p < h; p++) {
if(in_screen(o + x, p + y)) { if(in_screen(o + x, p + y)) {
@@ -183,8 +209,16 @@ uint8_t *getOrAddIconData(Canvas *const canvas, const Icon *icon) {
return icon_data; return icon_data;
} }
void draw_icon_clip(Canvas *const canvas, const Icon *icon, int16_t x, int16_t y, uint8_t left, uint8_t top, uint8_t w, void draw_icon_clip(
uint8_t h, DrawMode drawMode) { Canvas* const canvas,
const Icon* icon,
int16_t x,
int16_t y,
uint8_t left,
uint8_t top,
uint8_t w,
uint8_t h,
DrawMode drawMode) {
uint8_t* icon_data = getOrAddIconData(canvas, icon); uint8_t* icon_data = getOrAddIconData(canvas, icon);
for(int i = 0; i < w; i++) { for(int i = 0; i < w; i++) {
@@ -198,9 +232,16 @@ void draw_icon_clip(Canvas *const canvas, const Icon *icon, int16_t x, int16_t y
} }
} }
void draw_icon_clip_flipped(Canvas *const canvas, const Icon *icon, int16_t x, int16_t y, uint8_t left, uint8_t top, void draw_icon_clip_flipped(
Canvas* const canvas,
const Icon* icon,
int16_t x,
int16_t y,
uint8_t left,
uint8_t top,
uint8_t w, uint8_t w,
uint8_t h, DrawMode drawMode) { uint8_t h,
DrawMode drawMode) {
uint8_t* icon_data = getOrAddIconData(canvas, icon); uint8_t* icon_data = getOrAddIconData(canvas, icon);
for(int i = 0; i < w; i++) { for(int i = 0; i < w; i++) {

View File

@@ -26,29 +26,76 @@ uint8_t *image_data(Canvas *const canvas, const Icon *icon);
uint32_t pixel_index(uint8_t x, uint8_t y); uint32_t pixel_index(uint8_t x, uint8_t y);
void draw_icon_clip(Canvas *const canvas, const Icon *icon, int16_t x, int16_t y, uint8_t left, uint8_t top, uint8_t w, void draw_icon_clip(
uint8_t h, DrawMode drawMode); Canvas* const canvas,
const Icon* icon,
int16_t x,
int16_t y,
uint8_t left,
uint8_t top,
uint8_t w,
uint8_t h,
DrawMode drawMode);
void draw_icon_clip_flipped(Canvas *const canvas, const Icon *icon, int16_t x, int16_t y, uint8_t left, uint8_t top, uint8_t w, void draw_icon_clip_flipped(
uint8_t h, DrawMode drawMode); Canvas* const canvas,
const Icon* icon,
int16_t x,
int16_t y,
uint8_t left,
uint8_t top,
uint8_t w,
uint8_t h,
DrawMode drawMode);
void draw_rounded_box(Canvas *const canvas, int16_t x, int16_t y, uint8_t w, uint8_t h, DrawMode drawMode); void draw_rounded_box(
Canvas* const canvas,
int16_t x,
int16_t y,
uint8_t w,
uint8_t h,
DrawMode drawMode);
void draw_rounded_box_frame(Canvas *const canvas, int16_t x, int16_t y, uint8_t w, uint8_t h, DrawMode drawMode); void draw_rounded_box_frame(
Canvas* const canvas,
int16_t x,
int16_t y,
uint8_t w,
uint8_t h,
DrawMode drawMode);
void draw_rectangle(Canvas *const canvas, int16_t x, int16_t y, uint8_t w, uint8_t h, DrawMode drawMode); void draw_rectangle(
Canvas* const canvas,
int16_t x,
int16_t y,
uint8_t w,
uint8_t h,
DrawMode drawMode);
void invert_rectangle(Canvas* const canvas, int16_t x, int16_t y, uint8_t w, uint8_t h); void invert_rectangle(Canvas* const canvas, int16_t x, int16_t y, uint8_t w, uint8_t h);
void invert_shape(Canvas* const canvas, uint8_t* data, int16_t x, int16_t y, uint8_t w, uint8_t h); void invert_shape(Canvas* const canvas, uint8_t* data, int16_t x, int16_t y, uint8_t w, uint8_t h);
void draw_pixels(Canvas *const canvas, uint8_t *data, int16_t x, int16_t y, uint8_t w, uint8_t h, DrawMode drawMode); void draw_pixels(
Canvas* const canvas,
uint8_t* data,
int16_t x,
int16_t y,
uint8_t w,
uint8_t h,
DrawMode drawMode);
bool read_pixel(Canvas* const canvas, int16_t x, int16_t y); bool read_pixel(Canvas* const canvas, int16_t x, int16_t y);
void set_pixel(Canvas* const canvas, int16_t x, int16_t y, DrawMode draw_mode); void set_pixel(Canvas* const canvas, int16_t x, int16_t y, DrawMode draw_mode);
void draw_line(Canvas *const canvas, int16_t x1, int16_t y1, int16_t x2, int16_t y2, DrawMode draw_mode); void draw_line(
Canvas* const canvas,
int16_t x1,
int16_t y1,
int16_t x2,
int16_t y2,
DrawMode draw_mode);
bool in_screen(int16_t x, int16_t y); bool in_screen(int16_t x, int16_t y);

View File

@@ -19,12 +19,7 @@ typedef struct {
InputEvent input; InputEvent input;
} AppEvent; } AppEvent;
typedef enum { typedef enum { GameStateGameOver, GameStateStart, GameStatePlay, GameStateAnimate } PlayState;
GameStateGameOver,
GameStateStart,
GameStatePlay,
GameStateAnimate
} PlayState;
typedef struct { typedef struct {
uint8_t* buffer; uint8_t* buffer;

View File

@@ -34,7 +34,12 @@ int8_t columns[7][3] = {
}; };
bool can_place_card(Card where, Card what) { bool can_place_card(Card where, Card what) {
FURI_LOG_D(APP_NAME, "TESTING pip %i, letter %i with pip %i, letter %i", where.pip, where.character, what.pip, FURI_LOG_D(
APP_NAME,
"TESTING pip %i, letter %i with pip %i, letter %i",
where.pip,
where.character,
what.pip,
what.character); what.character);
bool a_black = where.pip == 0 || where.pip == 3; bool a_black = where.pip == 0 || where.pip == 3;
bool b_black = what.pip == 0 || what.pip == 3; bool b_black = what.pip == 0 || what.pip == 3;
@@ -50,26 +55,41 @@ bool can_place_card(Card where, Card what) {
static void draw_scene(Canvas* const canvas, const GameState* game_state) { static void draw_scene(Canvas* const canvas, const GameState* game_state) {
int deckIndex = game_state->deck.index; int deckIndex = game_state->deck.index;
if (game_state->dragging_deck) if(game_state->dragging_deck) deckIndex--;
deckIndex--;
if ((game_state->deck.index < (game_state->deck.card_count - 1) || game_state->deck.index == -1) && game_state->deck.card_count>0) { if((game_state->deck.index < (game_state->deck.card_count - 1) ||
game_state->deck.index == -1) &&
game_state->deck.card_count > 0) {
draw_card_back_at(columns[0][0], columns[0][1], canvas); draw_card_back_at(columns[0][0], columns[0][1], canvas);
if(game_state->selectRow == 0 && game_state->selectColumn == 0) { if(game_state->selectRow == 0 && game_state->selectColumn == 0) {
draw_rounded_box(canvas, columns[0][0] + 1, columns[0][1] + 1, CARD_WIDTH - 2, CARD_HEIGHT - 2, draw_rounded_box(
canvas,
columns[0][0] + 1,
columns[0][1] + 1,
CARD_WIDTH - 2,
CARD_HEIGHT - 2,
Inverse); Inverse);
} }
} else } else
draw_card_space(columns[0][0], columns[0][1], draw_card_space(
columns[0][0],
columns[0][1],
game_state->selectRow == 0 && game_state->selectColumn == 0, game_state->selectRow == 0 && game_state->selectColumn == 0,
canvas); canvas);
//deck side //deck side
if(deckIndex >= 0) { if(deckIndex >= 0) {
Card c = game_state->deck.cards[deckIndex]; Card c = game_state->deck.cards[deckIndex];
draw_card_at_colored(columns[1][0], columns[1][1], c.pip, c.character, draw_card_at_colored(
game_state->selectRow == 0 && game_state->selectColumn == 1, canvas); columns[1][0],
columns[1][1],
c.pip,
c.character,
game_state->selectRow == 0 && game_state->selectColumn == 1,
canvas);
} else } else
draw_card_space(columns[1][0], columns[1][1], draw_card_space(
columns[1][0],
columns[1][1],
game_state->selectRow == 0 && game_state->selectColumn == 1, game_state->selectRow == 0 && game_state->selectColumn == 1,
canvas); canvas);
@@ -79,10 +99,11 @@ static void draw_scene(Canvas *const canvas, const GameState *game_state) {
if(current.disabled) { if(current.disabled) {
draw_card_space(columns[i + 3][0], columns[i + 3][1], selected, canvas); draw_card_space(columns[i + 3][0], columns[i + 3][1], selected, canvas);
} else { } else {
draw_card_at(columns[i + 3][0], columns[i + 3][1], current.pip, current.character, canvas); draw_card_at(
columns[i + 3][0], columns[i + 3][1], current.pip, current.character, canvas);
if(selected) { if(selected) {
draw_rounded_box(canvas, columns[i + 3][0], columns[i + 3][1], CARD_WIDTH, CARD_HEIGHT, draw_rounded_box(
Inverse); canvas, columns[i + 3][0], columns[i + 3][1], CARD_WIDTH, CARD_HEIGHT, Inverse);
} }
} }
} }
@@ -91,20 +112,28 @@ static void draw_scene(Canvas *const canvas, const GameState *game_state) {
bool selected = game_state->selectRow == 1 && game_state->selectColumn == i; bool selected = game_state->selectRow == 1 && game_state->selectColumn == i;
int8_t index = (game_state->bottom_columns[i].index - 1 - game_state->selected_card); int8_t index = (game_state->bottom_columns[i].index - 1 - game_state->selected_card);
if(index < 0) index = 0; if(index < 0) index = 0;
draw_hand_column(game_state->bottom_columns[i], columns[i][0], columns[i][2], draw_hand_column(
selected ? index : -1, canvas); game_state->bottom_columns[i],
columns[i][0],
columns[i][2],
selected ? index : -1,
canvas);
} }
int8_t pos[2] = {columns[game_state->selectColumn][0], int8_t pos[2] = {
columns[game_state->selectColumn][0],
columns[game_state->selectColumn][game_state->selectRow + 1]}; columns[game_state->selectColumn][game_state->selectRow + 1]};
/* draw_icon_clip(canvas, &I_card_graphics, pos[0] + CARD_HALF_WIDTH, pos[1] + CARD_HALF_HEIGHT, 30, 5, 5, 5, /* draw_icon_clip(canvas, &I_card_graphics, pos[0] + CARD_HALF_WIDTH, pos[1] + CARD_HALF_HEIGHT, 30, 5, 5, 5,
Filled);*/ Filled);*/
if(game_state->dragging_hand.index > 0) { if(game_state->dragging_hand.index > 0) {
draw_hand_column(game_state->dragging_hand, draw_hand_column(
pos[0] + CARD_HALF_WIDTH + 3, pos[1] + CARD_HALF_HEIGHT + 3, game_state->dragging_hand,
-1, canvas); pos[0] + CARD_HALF_WIDTH + 3,
pos[1] + CARD_HALF_HEIGHT + 3,
-1,
canvas);
} }
} }
@@ -114,9 +143,12 @@ static void draw_animation(Canvas *const canvas, const GameState *game_state) {
} else { } else {
clone_buffer(game_state->animation.buffer, get_buffer(canvas)); clone_buffer(game_state->animation.buffer, get_buffer(canvas));
draw_card_at((int8_t) game_state->animation.x, (int8_t) game_state->animation.y, game_state->animation.card.pip, draw_card_at(
game_state->animation.card.character, canvas); (int8_t)game_state->animation.x,
(int8_t)game_state->animation.y,
game_state->animation.card.pip,
game_state->animation.card.character,
canvas);
} }
clone_buffer(get_buffer(canvas), game_state->animation.buffer); clone_buffer(get_buffer(canvas), game_state->animation.buffer);
@@ -143,7 +175,6 @@ static void render_callback(Canvas *const canvas, void *ctx) {
} }
release_mutex((ValueMutex*)ctx, game_state); release_mutex((ValueMutex*)ctx, game_state);
} }
void remove_drag(GameState* game_state) { void remove_drag(GameState* game_state) {
@@ -209,8 +240,7 @@ bool handleInput(GameState *game_state) {
else else
game_state->selectColumn--; game_state->selectColumn--;
} }
if (game_state->dragging_hand.index > 0) if(game_state->dragging_hand.index > 0) game_state->selected_card = 0;
game_state->selected_card = 0;
return false; return false;
} }
@@ -244,14 +274,17 @@ void tick(GameState *game_state, NotificationApp *notification) {
if(handleInput(game_state)) { if(handleInput(game_state)) {
if(game_state->state == GameStatePlay) { if(game_state->state == GameStatePlay) {
if(game_state->top_cards[0].character == 11 &&
if(game_state->top_cards[0].character==11 && game_state->top_cards[1].character==11 && game_state->top_cards[2].character==11 && game_state->top_cards[3].character==11){ game_state->top_cards[1].character == 11 &&
game_state->top_cards[2].character == 11 &&
game_state->top_cards[3].character == 11) {
game_state->state = GameStateAnimate; game_state->state = GameStateAnimate;
return; return;
} }
if(game_state->longPress && game_state->dragging_hand.index == 1) { if(game_state->longPress && game_state->dragging_hand.index == 1) {
for(uint8_t i = 0; i < 4; i++) { for(uint8_t i = 0; i < 4; i++) {
if (place_on_top(&(game_state->top_cards[i]), game_state->dragging_hand.cards[0])) { if(place_on_top(
&(game_state->top_cards[i]), game_state->dragging_hand.cards[0])) {
remove_drag(game_state); remove_drag(game_state);
wasAction = true; wasAction = true;
break; break;
@@ -278,7 +311,9 @@ void tick(GameState *game_state, NotificationApp *notification) {
if(game_state->dragging_hand.index == 0 && game_state->deck.index >= 0) { if(game_state->dragging_hand.index == 0 && game_state->deck.index >= 0) {
wasAction = true; wasAction = true;
game_state->dragging_deck = true; game_state->dragging_deck = true;
add_to_hand(&(game_state->dragging_hand), game_state->deck.cards[game_state->deck.index]); add_to_hand(
&(game_state->dragging_hand),
game_state->deck.cards[game_state->deck.index]);
} }
} }
} }
@@ -287,8 +322,7 @@ void tick(GameState *game_state, NotificationApp *notification) {
column -= 3; column -= 3;
Card currCard = game_state->dragging_hand.cards[0]; Card currCard = game_state->dragging_hand.cards[0];
wasAction = place_on_top(&(game_state->top_cards[column]), currCard); wasAction = place_on_top(&(game_state->top_cards[column]), currCard);
if (wasAction) if(wasAction) remove_drag(game_state);
remove_drag(game_state);
} }
//pick/place from bottom //pick/place from bottom
else if(row == 1) { else if(row == 1) {
@@ -301,7 +335,9 @@ void tick(GameState *game_state, NotificationApp *notification) {
wasAction = true; wasAction = true;
} else { } else {
if(curr_hand->index > 0) { if(curr_hand->index > 0) {
extract_hand_region(curr_hand, &(game_state->dragging_hand), extract_hand_region(
curr_hand,
&(game_state->dragging_hand),
curr_hand->index - game_state->selected_card - 1); curr_hand->index - game_state->selected_card - 1);
game_state->selected_card = 0; game_state->selected_card = 0;
game_state->dragging_column = column; game_state->dragging_column = column;
@@ -314,8 +350,7 @@ void tick(GameState *game_state, NotificationApp *notification) {
Card first = game_state->dragging_hand.cards[0]; Card first = game_state->dragging_hand.cards[0];
if(game_state->dragging_column == column || if(game_state->dragging_column == column ||
(curr_hand->index == 0 && first.character == 11) || (curr_hand->index == 0 && first.character == 11) ||
can_place_card(curr_hand->cards[curr_hand->index - 1], first) can_place_card(curr_hand->cards[curr_hand->index - 1], first)) {
) {
add_hand_region(curr_hand, &(game_state->dragging_hand)); add_hand_region(curr_hand, &(game_state->dragging_hand));
remove_drag(game_state); remove_drag(game_state);
wasAction = true; wasAction = true;
@@ -324,38 +359,29 @@ void tick(GameState *game_state, NotificationApp *notification) {
} }
} }
if(!wasAction) { if(!wasAction) {
notification_message(notification, &sequence_fail); notification_message(notification, &sequence_fail);
} }
} }
} }
if(game_state->state == GameStateAnimate) { if(game_state->state == GameStateAnimate) {
if (game_state->animation.started) if(game_state->animation.started) game_state->state = GameStateStart;
game_state->state = GameStateStart;
game_state->animation.started = true; game_state->animation.started = true;
if(game_state->animation.x < -20 || game_state->animation.x > 128) { if(game_state->animation.x < -20 || game_state->animation.x > 128) {
game_state->animation.deck++; game_state->animation.deck++;
if (game_state->animation.deck > 3) if(game_state->animation.deck > 3) game_state->animation.deck = 0;
game_state->animation.deck = 0;
int8_t cardIndex = 11 - game_state->animation.indexes[game_state->animation.deck]; int8_t cardIndex = 11 - game_state->animation.indexes[game_state->animation.deck];
if (game_state->animation.indexes[0] == 13 && if(game_state->animation.indexes[0] == 13 && game_state->animation.indexes[1] == 13 &&
game_state->animation.indexes[1] == 13 && game_state->animation.indexes[2] == 13 && game_state->animation.indexes[3] == 13) {
game_state->animation.indexes[2] == 13 &&
game_state->animation.indexes[3] == 13) {
game_state->state = GameStateStart; game_state->state = GameStateStart;
return; return;
} }
if (cardIndex == -1) if(cardIndex == -1) cardIndex = 12;
cardIndex = 12;
game_state->animation.card = (Card){ game_state->animation.card = (Card){
game_state->top_cards[game_state->animation.deck].pip, game_state->top_cards[game_state->animation.deck].pip, cardIndex, false, false};
cardIndex,
false, false
};
game_state->animation.indexes[game_state->animation.deck]++; game_state->animation.indexes[game_state->animation.deck]++;
game_state->animation.vx = -(rand() % 3 + 1) * (rand() % 2 == 1 ? 1 : -1); game_state->animation.vx = -(rand() % 3 + 1) * (rand() % 2 == 1 ? 1 : -1);
game_state->animation.vy = (rand() % 3 + 1); game_state->animation.vy = (rand() % 3 + 1);
@@ -407,15 +433,12 @@ void init(GameState *game_state) {
void init_start(GameState* game_state) { void init_start(GameState* game_state) {
game_state->input = InputKeyMAX; game_state->input = InputKeyMAX;
for (uint8_t i = 0; i < 7; i++) for(uint8_t i = 0; i < 7; i++) init_hand(&(game_state->bottom_columns[i]), 21);
init_hand(&(game_state->bottom_columns[i]), 21);
init_hand(&(game_state->dragging_hand), 13); init_hand(&(game_state->dragging_hand), 13);
game_state->animation.buffer = make_buffer(); game_state->animation.buffer = make_buffer();
} }
static void input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) { static void input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) {
furi_assert(event_queue); furi_assert(event_queue);
AppEvent event = {.type = EventTypeKey, .input = *input_event}; AppEvent event = {.type = EventTypeKey, .input = *input_event};
@@ -453,8 +476,7 @@ int32_t solitaire_app(void *p) {
view_port_draw_callback_set(view_port, render_callback, &state_mutex); view_port_draw_callback_set(view_port, render_callback, &state_mutex);
view_port_input_callback_set(view_port, input_callback, event_queue); view_port_input_callback_set(view_port, input_callback, event_queue);
FuriTimer *timer = FuriTimer* timer = furi_timer_alloc(update_timer_callback, FuriTimerTypePeriodic, event_queue);
furi_timer_alloc(update_timer_callback, FuriTimerTypePeriodic, event_queue);
furi_timer_start(timer, furi_kernel_get_tick_frequency() / 30); furi_timer_start(timer, furi_kernel_get_tick_frequency() / 30);
Gui* gui = furi_record_open("gui"); Gui* gui = furi_record_open("gui");
@@ -491,8 +513,7 @@ int32_t solitaire_app(void *p) {
if(event.input.key == InputKeyOk && localstate->state == GameStateStart) { if(event.input.key == InputKeyOk && localstate->state == GameStateStart) {
localstate->state = GameStatePlay; localstate->state = GameStatePlay;
init(game_state); init(game_state);
} } else {
else {
hadChange = true; hadChange = true;
localstate->input = event.input.key; localstate->input = event.input.key;
} }
@@ -514,12 +535,10 @@ int32_t solitaire_app(void *p) {
FURI_LOG_W(APP_NAME, "osMessageQueue: event timeout"); FURI_LOG_W(APP_NAME, "osMessageQueue: event timeout");
// event timeout // event timeout
} }
if (hadChange || game_state->state == GameStateAnimate) if(hadChange || game_state->state == GameStateAnimate) view_port_update(view_port);
view_port_update(view_port);
release_mutex(&state_mutex, localstate); release_mutex(&state_mutex, localstate);
} }
notification_message_block(notification, &sequence_display_backlight_enforce_auto); notification_message_block(notification, &sequence_display_backlight_enforce_auto);
furi_timer_free(timer); furi_timer_free(timer);
view_port_enabled_set(view_port, false); view_port_enabled_set(view_port, false);
@@ -532,8 +551,7 @@ int32_t solitaire_app(void *p) {
free_and_exit: free_and_exit:
free(game_state->animation.buffer); free(game_state->animation.buffer);
ui_cleanup(); ui_cleanup();
for (uint8_t i = 0; i < 7; i++) for(uint8_t i = 0; i < 7; i++) free_hand(&(game_state->bottom_columns[i]));
free_hand(&(game_state->bottom_columns[i]));
free(game_state->deck.cards); free(game_state->deck.cards);
free(game_state); free(game_state);

View File

@@ -52,7 +52,13 @@ static bool totp_plugin_state_init(PluginState* const plugin_state) {
if(plugin_state->crypto_verify_data == NULL) { if(plugin_state->crypto_verify_data == NULL) {
DialogMessage* message = dialog_message_alloc(); DialogMessage* message = dialog_message_alloc();
dialog_message_set_buttons(message, "No", NULL, "Yes"); dialog_message_set_buttons(message, "No", NULL, "Yes");
dialog_message_set_text(message, "Would you like to setup PIN?", SCREEN_WIDTH_CENTER, SCREEN_HEIGHT_CENTER, AlignCenter, AlignCenter); dialog_message_set_text(
message,
"Would you like to setup PIN?",
SCREEN_WIDTH_CENTER,
SCREEN_HEIGHT_CENTER,
AlignCenter,
AlignCenter);
DialogMessageButton dialog_result = dialog_message_show(plugin_state->dialogs, message); DialogMessageButton dialog_result = dialog_message_show(plugin_state->dialogs, message);
dialog_message_free(message); dialog_message_free(message);
if(dialog_result == DialogMessageButtonRight) { if(dialog_result == DialogMessageButtonRight) {
@@ -68,10 +74,18 @@ static bool totp_plugin_state_init(PluginState* const plugin_state) {
if(totp_crypto_verify_key(plugin_state)) { if(totp_crypto_verify_key(plugin_state)) {
totp_scene_director_activate_scene(plugin_state, TotpSceneGenerateToken, NULL); totp_scene_director_activate_scene(plugin_state, TotpSceneGenerateToken, NULL);
} else { } else {
FURI_LOG_E(LOGGING_TAG, "Digital signature verification failed. Looks like conf file was created on another flipper and can't be used on any other"); FURI_LOG_E(
LOGGING_TAG,
"Digital signature verification failed. Looks like conf file was created on another flipper and can't be used on any other");
DialogMessage* message = dialog_message_alloc(); DialogMessage* message = dialog_message_alloc();
dialog_message_set_buttons(message, "Exit", NULL, NULL); dialog_message_set_buttons(message, "Exit", NULL, NULL);
dialog_message_set_text(message, "Digital signature verification failed", SCREEN_WIDTH_CENTER, SCREEN_HEIGHT_CENTER, AlignCenter, AlignCenter); dialog_message_set_text(
message,
"Digital signature verification failed",
SCREEN_WIDTH_CENTER,
SCREEN_HEIGHT_CENTER,
AlignCenter,
AlignCenter);
dialog_message_show(plugin_state->dialogs, message); dialog_message_show(plugin_state->dialogs, message);
dialog_message_free(message); dialog_message_free(message);
return false; return false;
@@ -149,7 +163,9 @@ int32_t totp_app() {
} }
processing = totp_scene_director_handle_event(&event, plugin_state_m); processing = totp_scene_director_handle_event(&event, plugin_state_m);
} else if (plugin_state_m->pin_set && plugin_state_m->current_scene != TotpSceneAuthentication && furi_get_tick() - last_user_interaction_time > IDLE_TIMEOUT) { } else if(
plugin_state_m->pin_set && plugin_state_m->current_scene != TotpSceneAuthentication &&
furi_get_tick() - last_user_interaction_time > IDLE_TIMEOUT) {
totp_scene_director_activate_scene(plugin_state_m, TotpSceneAuthentication, NULL); totp_scene_director_activate_scene(plugin_state_m, TotpSceneAuthentication, NULL);
} }