Skip to content

Commit

Permalink
make Dice vibrate on roll
Browse files Browse the repository at this point in the history
  • Loading branch information
yusufmte committed Oct 16, 2022
1 parent e789622 commit b47b13a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/displayapp/DisplayApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)
currentScreen = std::make_unique<Screens::Steps>(this, motionController, settingsController);
break;
case Apps::Dice:
currentScreen = std::make_unique<Screens::Dice>(this, motionController);
currentScreen = std::make_unique<Screens::Dice>(this, motionController, motorController);
break;
}
currentApp = app;
Expand Down
14 changes: 9 additions & 5 deletions src/displayapp/screens/Dice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ namespace {
}
}

Dice::Dice(DisplayApp* app, Controllers::MotionController& motionController) : Screen(app) {
Dice::Dice(DisplayApp* app, Controllers::MotionController& motion, Controllers::MotorController& motor) : Screen(app), motor {motor} {
std::seed_seq sseq {static_cast<uint32_t>(xTaskGetTickCount()),
static_cast<uint32_t>(motionController.X()),
static_cast<uint32_t>(motionController.Y()),
static_cast<uint32_t>(motionController.Z())};
static_cast<uint32_t>(motion.X()),
static_cast<uint32_t>(motion.Y()),
static_cast<uint32_t>(motion.Z())};
gen.seed(sseq);

nCounter.Create();
Expand Down Expand Up @@ -90,6 +90,7 @@ Dice::Dice(DisplayApp* app, Controllers::MotionController& motionController) : S
10);

Roll();
openingRoll = false;

btnRoll = lv_btn_create(lv_scr_act(), nullptr);
btnRoll->user_data = this;
Expand Down Expand Up @@ -130,7 +131,10 @@ void Dice::Roll() {
}

lv_label_set_text_fmt(resultTotalLabel, "%d", resultTotal);
NextColor();
if (openingRoll == false) {
motor.RunForDuration(30);
NextColor();
}
}

void Dice::NextColor() {
Expand Down
7 changes: 6 additions & 1 deletion src/displayapp/screens/Dice.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "components/motion/MotionController.h"
#include "components/motor/MotorController.h"
#include "displayapp/screens/Screen.h"
#include "displayapp/widgets/Counter.h"
#include "systemtask/SystemTask.h"
Expand All @@ -13,7 +14,7 @@
namespace Pinetime::Applications::Screens {
class Dice : public Screen {
public:
Dice(DisplayApp* app, Controllers::MotionController& motionController);
Dice(DisplayApp* app, Controllers::MotionController& motion, Controllers::MotorController& motor);
~Dice() override;
void Roll();

Expand All @@ -31,5 +32,9 @@ namespace Pinetime::Applications::Screens {

Widgets::Counter nCounter = Widgets::Counter(1, 9, jetbrains_mono_42);
Widgets::Counter dCounter = Widgets::Counter(2, 99, jetbrains_mono_42);

bool openingRoll = true;

Controllers::MotorController& motor;
};
}

0 comments on commit b47b13a

Please sign in to comment.