Skip to content

Commit

Permalink
add surprise
Browse files Browse the repository at this point in the history
  • Loading branch information
Alx-Lai authored and john0312 committed Aug 17, 2024
1 parent 638e109 commit b5a11a1
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 15 deletions.
16 changes: 14 additions & 2 deletions fw/Core/Hitcon/App/ShowNameApp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ namespace {

// Update once every 15s. Units: ms.
constexpr unsigned kMinUpdateInterval = 15 * 1000;
static const char SURPRISE_NAME[] = "Cool!";
static const int SURPRISE_NAME_LEN = sizeof(SURPRISE_NAME) / sizeof(char);
static constexpr unsigned SURPRISE_TIME = 10000;

} // namespace
ShowNameApp show_name_app;
Expand All @@ -44,8 +47,8 @@ void ShowNameApp::Init() {
void ShowNameApp::OnEntry() {
display_set_orientation(0);
score_cache = gameLogic.GetScore();
update_display();
scheduler.EnablePeriodic(&_routine_task);
update_display();
}

void ShowNameApp::OnExit() {
Expand All @@ -66,7 +69,12 @@ void ShowNameApp::OnButton(button_t button) {
}

void ShowNameApp::check_update() {
if (SysTimer::GetTime() - last_disp_update > kMinUpdateInterval) {
if (mode == Surprise &&
SysTimer::GetTime() - last_disp_update > SURPRISE_TIME) {
mode = NameScore;
update_display();
} else if (mode != Surprise &&
SysTimer::GetTime() - last_disp_update > kMinUpdateInterval) {
if (score_cache != gameLogic.GetScore() && mode != NameOnly) {
score_cache = gameLogic.GetScore();
update_display();
Expand Down Expand Up @@ -105,6 +113,10 @@ void ShowNameApp::update_display() {
strncpy(display_str, num_str, num_len);
display_str[num_len] = 0;
break;
case Surprise:
strncpy(display_str, SURPRISE_NAME, SURPRISE_NAME_LEN);
display_str[SURPRISE_NAME_LEN] = 0;
break;
default:
break;
}
Expand Down
2 changes: 2 additions & 0 deletions fw/Core/Hitcon/App/ShowNameApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ enum ShowNameMode {
NameScore,
NameOnly,
ScoreOnly,
Surprise,
};

class ShowNameApp : public App {
public:
static constexpr int NAME_LEN = 16;
static constexpr char *DEFAULT_NAME = "HITCON2024";

char name[NAME_LEN + 1] = {0};
char display_buf[DISPLAY_SCROLL_MAX_COLUMNS];

Expand Down
18 changes: 6 additions & 12 deletions fw/Core/Hitcon/Logic/IrController.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "IrController.h"

#include <App/HardwareTestApp.h>
#include <App/ShowNameApp.h>
#include <Logic/BadgeController.h>
#include <Logic/Display/display.h>
#include <Logic/GameLogic.h>
Expand Down Expand Up @@ -28,27 +29,23 @@ IrController::IrController()
broadcast_task(800, (callback_t)&IrController::BroadcastIr, this),
send2game_task(800, (callback_t)&IrController::Send2Game, this),
showtext_task(800, (callback_t)&IrController::ShowText, this),
send_lock(true), show_lock(true), recv_lock(true),
received_packet_cnt(0) {}
send_lock(true), recv_lock(true), received_packet_cnt(0) {}

void IrController::Send2Game(void* arg) {
GamePacket* game = reinterpret_cast<GamePacket*>(arg);
gameLogic.AcceptData(game->col, game->data);
send_lock = true;
}
void IrController::ShowText(void* arg) {
ShowPacket* show = reinterpret_cast<ShowPacket*>(arg);
display_set_mode_scroll_text(show->message);
show_lock = true;
show_name_app.SetMode(Surprise);
badge_controller.change_app(&show_name_app);
}

static char* surprise_msg = "Cool!";

void IrController::Init() {
irLogic.SetOnPacketReceived((callback_t)&IrController::OnPacketReceived,
this);
badge_controller.SetCallback((callback_t)&IrController::SendShowPacket, this,
surprise_msg);
nullptr);
scheduler.Queue(&routine_task, nullptr);
scheduler.EnablePeriodic(&routine_task);
}
Expand All @@ -68,10 +65,7 @@ void IrController::OnPacketReceived(void* arg) {
} else if (data->type == packet_type::kTest) {
hardware_test_app.CheckIr(&data->show);
} else if (data->type == packet_type::kShow) {
if (show_lock) {
show_lock = false;
scheduler.Queue(&showtext_task, &data->show);
}
scheduler.Queue(&showtext_task, &data->show);
}
}

Expand Down
1 change: 0 additions & 1 deletion fw/Core/Hitcon/Logic/IrController.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ class IrController {

private:
bool send_lock;
bool show_lock;
bool recv_lock;
// TODO: Tune the quadratic function parameters
uint8_t v[3] = {1, 27, 111};
Expand Down

0 comments on commit b5a11a1

Please sign in to comment.