Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix send data and change SendDataApp to show progress #129

Merged
merged 1 commit into from
Aug 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 42 additions & 6 deletions fw/Core/Hitcon/App/SendDataApp.cc
Original file line number Diff line number Diff line change
@@ -1,27 +1,63 @@
#include <App/SendDataApp.h>
#include <Logic/XBoardGameController.h>
#include <Service/Sched/Scheduler.h>

using hitcon::xboard_game_controller::g_xboard_game_controller;

namespace hitcon {

namespace {

constexpr int kRoutineDelay = 500;

} // namespace

SendDataApp g_send_data_app;

SendDataApp::SendDataApp() {}
SendDataApp::SendDataApp()
: routine_task_delayed(900, (callback_t)&SendDataApp::Routine, this, 0) {}

void SendDataApp::Init() {}
void SendDataApp::Init() {
running_ = false;
in_queue_ = false;
}

void SendDataApp::OnEntry() {
g_xboard_game_controller.SendPartialData(25);
display_set_mode_scroll_text("Sending...");
running_ = true;
if (!in_queue_) {
in_queue_ = true;
routine_task_delayed.SetWakeTime(SysTimer::GetTime());
scheduler.Queue(&routine_task_delayed, nullptr);
}
}

void SendDataApp::OnExit() {
// Nothing.
}
void SendDataApp::OnExit() { running_ = false; }

void SendDataApp::OnButton(button_t button) {
// Unused.
}

void SendDataApp::Routine(void* arg) {
in_queue_ = false;
if (!running_) return;

RoutineInternal();

in_queue_ = true;
routine_task_delayed.SetWakeTime(SysTimer::GetTime() + kRoutineDelay);
scheduler.Queue(&routine_task_delayed, nullptr);
}

void SendDataApp::RoutineInternal() {
int left = g_xboard_game_controller.GetRemainingDataCount();
if (left >= 99) left = 99;

char temp[5];
temp[0] = left / 10 + '0';
temp[1] = left % 10 + '0';
temp[2] = 0;
display_set_mode_text(temp);
}

} // namespace hitcon
14 changes: 14 additions & 0 deletions fw/Core/Hitcon/App/SendDataApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@
#include <App/app.h>
#include <Logic/Display/display.h>
#include <Logic/XBoardGameController.h>
#include <Service/Sched/SysTimer.h>

namespace hitcon {

using hitcon::game::gameLogic;
using hitcon::service::sched::scheduler;
using hitcon::service::sched::SysTimer;

class SendDataApp : public App {
public:
SendDataApp();
Expand All @@ -17,6 +22,15 @@ class SendDataApp : public App {
void OnEntry() override;
void OnExit() override;
void OnButton(button_t button) override;

private:
bool running_;
bool in_queue_;

void Routine(void* args);
void RoutineInternal();

hitcon::service::sched::DelayedTask routine_task_delayed;
};

extern SendDataApp g_send_data_app;
Expand Down
4 changes: 2 additions & 2 deletions fw/Core/Hitcon/Logic/XBoardGameController.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ void XBoardGameController::Init() {

void XBoardGameController::SendPartialData(int percentage) {
random_send_left_ += hitcon::game::kNumRows *
hitcon::game::XBoardAllowedBroadcastColCnt * 100 /
percentage;
hitcon::game::XBoardAllowedBroadcastColCnt * percentage /
100;
if (send_state == Idle) {
send_state = Sending;
}
Expand Down
2 changes: 2 additions & 0 deletions fw/Core/Hitcon/Logic/XBoardGameController.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class XBoardGameController {
void OnConnect();
void OnDisconnect();

int GetRemainingDataCount() { return random_send_left_; }

private:
hitcon::service::sched::PeriodicTask _send_routine;
SendState send_state = Idle;
Expand Down
Loading