Skip to content

Commit

Permalink
Implement remote change for PreparedData partition
Browse files Browse the repository at this point in the history
  • Loading branch information
john0312 committed Aug 21, 2024
1 parent 90186f2 commit 3cb5268
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 1 deletion.
2 changes: 2 additions & 0 deletions fw/Core/Hitcon/Logic/IrController.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ void IrController::OnPacketReceived(void* arg) {
hardware_test_app.CheckIr(&data->show);
} else if (data->type == packet_type::kShow) {
scheduler.Queue(&showtext_task, &data->show);
} else if (data->type == packet_type::kPartition) {
g_prepared_data.SetPartitionAndShow(data->partition.partition);
}
}

Expand Down
7 changes: 7 additions & 0 deletions fw/Core/Hitcon/Logic/IrController.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <Logic/GameLogic.h>
#include <Logic/IrLogic.h>
#include <Secret/secret.h>
#include <Service/IrService.h>
#include <Service/Sched/PeriodicTask.h>
#include <Service/Sched/Scheduler.h>
Expand All @@ -13,6 +14,7 @@ enum class packet_type : uint8_t {
kGame = 0,
kShow = 1,
kTest = 2,
kPartition = hitcon::kPartitionPacketId,
};

namespace hitcon {
Expand All @@ -28,13 +30,18 @@ struct ShowPacket {
char message[16];
};

struct PartitionPacket {
uint8_t partition;
};

/*Definition of IR content.*/
struct IrData {
uint8_t ttl;
packet_type type;
union {
struct GamePacket game;
struct ShowPacket show;
struct PartitionPacket partition;
};
};

Expand Down
22 changes: 21 additions & 1 deletion fw/Core/Hitcon/Logic/PreparedData.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <App/ShowNameApp.h>
#include <Logic/BadgeController.h>
#include <Logic/EntropyHub.h>
#include <Logic/GameLogic.h>
#include <Logic/PreparedData.h>
Expand All @@ -20,7 +22,7 @@ PreparedData g_prepared_data;

PreparedData::PreparedData()
: current_partition_(0), ir_idx_(-1), xboard_idx_(-1), elapsed_sec_(0),
init_finish_(false),
partition_change_(-1), init_finish_(false),
routine_task(985, (task_callback_t)&PreparedData::Routine, this, 1000) {}

void PreparedData::Init() {
Expand Down Expand Up @@ -63,6 +65,10 @@ void PreparedData::GetRandomDataForXBoardTransmission(uint8_t* out_data,
}
}

void PreparedData::SetPartitionAndShow(int partition) {
partition = (partition + kPartitionOffset) & 0x0FF;
}

void PreparedData::Routine() {
elapsed_sec_++;

Expand All @@ -84,6 +90,20 @@ void PreparedData::Routine() {
xboard_idx_ = (xboard_idx_ + 1) % kXBoardPartitionSize;
}
}

if (partition_change_ != -1) {
SetPartition(partition_change_);
if (current_partition_ == partition_change_) {
char msg[5];
msg[0] = 'P';
msg[1] = '0' + current_partition_;
msg[2] = '\0';
show_name_app.SetSurpriseMsg(msg);
show_name_app.SetMode(Surprise);
badge_controller.change_app(&show_name_app);
}
partition_change_ = -1;
}
}

} // namespace hitcon
3 changes: 3 additions & 0 deletions fw/Core/Hitcon/Logic/PreparedData.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class PreparedData {
}
}

void SetPartitionAndShow(int partition);

int GetPartition(int partition) { return current_partition_; }

void GetRandomDataForIrTransmission(uint8_t* out_data, int* out_col);
Expand All @@ -29,6 +31,7 @@ class PreparedData {
int xboard_idx_;

int elapsed_sec_;
int partition_change_;

bool init_finish_;

Expand Down
4 changes: 4 additions & 0 deletions fw/Core/Hitcon/Secret/secret.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,10 @@ constexpr uint8_t kStrayXBoardData[] = {
#undef DATA
#endif

constexpr int kPartitionOffset = 0x0;

constexpr uint8_t kPartitionPacketId = 0x4;

constexpr size_t kPartitionCount = 4;

constexpr size_t kIrPartitionSize =
Expand Down

0 comments on commit 3cb5268

Please sign in to comment.