Skip to content

Commit 4ca25dd

Browse files
committed
refactor: Move GPSWrapper and rename classes
1 parent d636cf4 commit 4ca25dd

File tree

8 files changed

+30
-30
lines changed

8 files changed

+30
-30
lines changed
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
#include "Button.h"
1+
#include "ButtonDriver.h"
22

33
namespace drivers {
44

5-
Button::Button(int pin) : pinNumber(pin) {}
5+
ButtonDriver::ButtonDriver(int pin) : pinNumber(pin) {}
66

7-
void Button::begin() {
7+
void ButtonDriver::begin() {
88
pinMode(pinNumber, INPUT_PULLUP);
99
stablePinLevel = digitalRead(pinNumber);
1010
lastPinLevel = stablePinLevel;
1111
lastDebounceTime = millis();
1212
}
1313

14-
bool Button::isPressed() {
14+
bool ButtonDriver::isPressed() {
1515
bool rawPinLevel = digitalRead(pinNumber);
1616
bool pressed = false;
1717

@@ -31,7 +31,7 @@ bool Button::isPressed() {
3131
}
3232

3333
#ifdef UNIT_TEST
34-
void Button::setMockState(int pin, int state) {
34+
void ButtonDriver::setMockState(int pin, int state) {
3535
setPinState(pin, state);
3636
}
3737
#endif
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace drivers {
77

8-
class Button {
8+
class ButtonDriver {
99
private:
1010
const int pinNumber;
1111
bool stablePinLevel;
@@ -21,7 +21,7 @@ class Button {
2121
}
2222

2323
public:
24-
Button(int pin);
24+
ButtonDriver(int pin);
2525
void begin();
2626
bool isPressed();
2727

src/system/CycleComputer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#pragma once
22

3-
#include "../drivers/GPSWrapper.h"
43
#include "../drivers/OLEDDriver.h"
4+
#include "GPSWrapper.h"
55
#include "InputManager.h"
66
#include "ModeManager.h"
77
#include "PowerManager.h"
@@ -14,7 +14,7 @@ class CycleComputer {
1414
drivers::OLEDDriver *display;
1515
InputManager inputManager;
1616
ModeManager modeManager;
17-
drivers::GPSWrapper gps;
17+
GPSWrapper gps;
1818
TripComputer tripComputer;
1919
PowerManager powerManager;
2020

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
#include "../Config.h"
66

7-
namespace drivers {
7+
namespace application {
88

99
bool GPSWrapper::begin() {
1010
if (gnss.begin() != 0)
@@ -55,4 +55,4 @@ void GPSWrapper::setMockSpeed(float speedKmh) {
5555
}
5656
#endif
5757

58-
} // namespace drivers
58+
} // namespace application
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include <Arduino.h>
44
#include <GNSS.h>
55

6-
namespace drivers {
6+
namespace application {
77

88
class GPSWrapper {
99
public:
@@ -23,4 +23,4 @@ class GPSWrapper {
2323
#endif
2424
};
2525

26-
} // namespace drivers
26+
} // namespace application

src/system/InputManager.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22

3-
#include "../drivers/Button.h"
3+
#include "../drivers/ButtonDriver.h"
44

55
namespace application {
66

@@ -13,8 +13,8 @@ enum class InputEvent {
1313

1414
class InputManager {
1515
private:
16-
drivers::Button btnA;
17-
drivers::Button btnB;
16+
drivers::ButtonDriver btnA;
17+
drivers::ButtonDriver btnB;
1818
unsigned long lastInputTime = 0;
1919

2020
public:

tests/host/CycleComputerTest.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ TEST_F(CycleComputerTest, DisplayGPSSpeed) {
132132
EXPECT_CALL(mockDisplay, show(_, _)).Times(AnyNumber());
133133

134134
float testSpeed = 15.5;
135-
drivers::GPSWrapper::setMockSpeed(testSpeed);
135+
application::GPSWrapper::setMockSpeed(testSpeed);
136136

137137
// Expect display to show formatted speed string
138138
EXPECT_CALL(mockDisplay, show(application::DisplayDataType::SPEED, testing::HasSubstr("15.5"))).Times(testing::AtLeast(1));
@@ -152,7 +152,7 @@ TEST_F(CycleComputerTest, DisplayTime) {
152152
pressButton(Config::Pin::BTN_A); // TIME
153153

154154
// Set UTC time to 3:34, which is 12:34 JST (UTC+9)
155-
drivers::GPSWrapper::setMockTime(3, 34, 56);
155+
application::GPSWrapper::setMockTime(3, 34, 56);
156156

157157
EXPECT_CALL(mockDisplay, show(application::DisplayDataType::TIME, StrEq("12:34"))).Times(testing::AtLeast(1));
158158

@@ -167,7 +167,7 @@ TEST_F(CycleComputerTest, ResetData) {
167167
EXPECT_CALL(mockDisplay, show(_, _)).Times(AnyNumber());
168168

169169
// 1. Accumulate some distance
170-
drivers::GPSWrapper::setMockSpeed(30.0f);
170+
application::GPSWrapper::setMockSpeed(30.0f);
171171
// Simulate 1 hour passing (needs many updates or large time jump?)
172172
// CycleComputer calls tripComputer.update(speed, millis())
173173
// We can jump time.

tests/host/InputManagerTest.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,29 @@ class InputManagerTest : public ::testing::Test {
99

1010
void SetUp() override {
1111
// Reset mocks
12-
// drivers::Button::resetMock(); // Removed
12+
// drivers::ButtonDriver::resetMock(); // Removed
1313
inputManager = new application::InputManager();
1414
inputManager->begin();
1515

1616
// Ensure initial state is released (HIGH)
17-
drivers::Button::setMockState(Config::Pin::BTN_A, HIGH);
18-
drivers::Button::setMockState(Config::Pin::BTN_B, HIGH);
17+
drivers::ButtonDriver::setMockState(Config::Pin::BTN_A, HIGH);
18+
drivers::ButtonDriver::setMockState(Config::Pin::BTN_B, HIGH);
1919
}
2020

2121
void TearDown() override {
2222
delete inputManager;
2323
}
2424
};
2525

26-
// Helper to simulate button press with debounce
26+
// Helper to simulate ButtonDriver press with debounce
2727
void pressButton(application::InputManager *im, int pin) {
28-
drivers::Button::setMockState(pin, LOW);
28+
drivers::ButtonDriver::setMockState(pin, LOW);
2929
im->update(); // Detect change (start debounce)
3030
_mock_millis += 70; // Wait > 50ms (Config::DEBOUNCE_DELAY assumed 50)
3131
}
3232

3333
void releaseButton(application::InputManager *im, int pin) {
34-
drivers::Button::setMockState(pin, HIGH);
34+
drivers::ButtonDriver::setMockState(pin, HIGH);
3535
im->update(); // Detect change
3636
_mock_millis += 70;
3737
}
@@ -40,7 +40,7 @@ TEST_F(InputManagerTest, InitialStateReturnsNone) {
4040
EXPECT_EQ(inputManager->update(), application::InputEvent::NONE);
4141
}
4242

43-
TEST_F(InputManagerTest, ButtonAPress) {
43+
TEST_F(InputManagerTest, ButtonDriverAPress) {
4444
pressButton(inputManager, Config::Pin::BTN_A);
4545
EXPECT_EQ(inputManager->update(), application::InputEvent::BTN_A);
4646

@@ -51,7 +51,7 @@ TEST_F(InputManagerTest, ButtonAPress) {
5151
EXPECT_EQ(inputManager->update(), application::InputEvent::NONE);
5252
}
5353

54-
TEST_F(InputManagerTest, ButtonBPress) {
54+
TEST_F(InputManagerTest, ButtonDriverBPress) {
5555
pressButton(inputManager, Config::Pin::BTN_B);
5656
EXPECT_EQ(inputManager->update(), application::InputEvent::BTN_B);
5757

@@ -60,8 +60,8 @@ TEST_F(InputManagerTest, ButtonBPress) {
6060
}
6161

6262
TEST_F(InputManagerTest, SimultaneousPress) {
63-
drivers::Button::setMockState(Config::Pin::BTN_A, LOW);
64-
drivers::Button::setMockState(Config::Pin::BTN_B, LOW);
63+
drivers::ButtonDriver::setMockState(Config::Pin::BTN_A, LOW);
64+
drivers::ButtonDriver::setMockState(Config::Pin::BTN_B, LOW);
6565
inputManager->update(); // Detect both change
6666

6767
_mock_millis += 70;
@@ -72,7 +72,7 @@ TEST_F(InputManagerTest, SimultaneousPress) {
7272
EXPECT_EQ(inputManager->update(), application::InputEvent::NONE);
7373
}
7474

75-
TEST_F(InputManagerTest, ButtonRelease) {
75+
TEST_F(InputManagerTest, ButtonDriverRelease) {
7676
pressButton(inputManager, Config::Pin::BTN_A);
7777
EXPECT_EQ(inputManager->update(), application::InputEvent::BTN_A);
7878

0 commit comments

Comments
 (0)