Skip to content

Commit f11c262

Browse files
committed
refactor: update format setting
1 parent 514118c commit f11c262

21 files changed

+380
-364
lines changed

.clang-format

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
BasedOnStyle: Google
2-
IndentWidth: 4
1+
BasedOnStyle: LLVM
2+
IndentWidth: 2
33
ColumnLimit: 200
44
AllowShortFunctionsOnASingleLine: Empty
55
BreakBeforeBraces: Attach

CONTRIBUTING.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
## 2. 基本スタイル (Basic Style)
1717

18-
- **インデント**: スペース 4
18+
- **インデント**: スペース 2
1919
- **中括弧の位置**: 同じ行に置く (Attach)
2020
- OK: `void loop() {`
2121
- NG: `void loop()\n{`
@@ -26,10 +26,10 @@
2626

2727
## 3. ハードウェア定義 (Hardware Definitions)
2828

29-
- **ピン定義**: `#define` マクロの使用は避け、`const uint8_t` または `enum` を使用してください。
29+
- **ピン定義**: `#define` マクロの使用は避け、`constexpr` または `enum` を使用してください。
3030
```cpp
3131
// OK
32-
const uint8_t LED_PIN = 13;
32+
constexpr uint8_t LED_PIN = 13;
3333
// または
3434
enum Pin : uint8_t { LED_RED = 13 };
3535
```

src/Config.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ constexpr int OLED_SDA = PIN_D14;
1515

1616
// システム
1717
constexpr int WARN_LED = PIN_D02;
18-
} // namespace Pin
18+
} // namespace Pin
1919

2020
constexpr unsigned long DEBOUNCE_DELAY = 50;
2121
constexpr unsigned long DISPLAY_UPDATE_INTERVAL_MS = 100;
@@ -24,19 +24,19 @@ namespace OLED {
2424
constexpr int WIDTH = 128;
2525
constexpr int HEIGHT = 64;
2626
constexpr int ADDRESS = 0x3C;
27-
} // namespace OLED
27+
} // namespace OLED
2828

2929
namespace Time {
3030
constexpr int JST_OFFSET = 9;
3131
}
3232

3333
namespace Trip {
34-
constexpr float MOVE_THRESHOLD_KMH = 3.0f; // 「移動中」とみなすための閾値
34+
constexpr float MOVE_THRESHOLD_KMH = 3.0f; // 「移動中」とみなすための閾値
3535
}
3636

3737
namespace Power {
38-
constexpr int BATTERY_LOW_THRESHOLD = 3600; // 3.6V
38+
constexpr int BATTERY_LOW_THRESHOLD = 3600; // 3.6V
3939
constexpr int BATTERY_CHECK_INTERVAL_MS = 10000;
4040
constexpr int LED_BLINK_INTERVAL_MS = 500;
41-
} // namespace Power
42-
} // namespace Config
41+
} // namespace Power
42+
} // namespace Config

src/drivers/Button.cpp

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,27 @@
33
Button::Button(int pin) : pinNumber(pin) {}
44

55
void Button::begin() {
6-
pinMode(pinNumber, INPUT_PULLUP);
7-
stablePinLevel = digitalRead(pinNumber);
8-
lastPinLevel = stablePinLevel;
9-
lastDebounceTime = millis();
6+
pinMode(pinNumber, INPUT_PULLUP);
7+
stablePinLevel = digitalRead(pinNumber);
8+
lastPinLevel = stablePinLevel;
9+
lastDebounceTime = millis();
1010
}
1111

1212
bool Button::isPressed() {
13-
bool rawPinLevel = digitalRead(pinNumber);
14-
bool pressed = false;
13+
bool rawPinLevel = digitalRead(pinNumber);
14+
bool pressed = false;
1515

16-
if (rawPinLevel != lastPinLevel) resetDebounceTimer();
16+
if (rawPinLevel != lastPinLevel)
17+
resetDebounceTimer();
1718

18-
if (hasDebounceTimePassed()) {
19-
if (stablePinLevel != rawPinLevel) {
20-
if (rawPinLevel == LOW) pressed = true;
21-
stablePinLevel = rawPinLevel;
22-
}
19+
if (hasDebounceTimePassed()) {
20+
if (stablePinLevel != rawPinLevel) {
21+
if (rawPinLevel == LOW)
22+
pressed = true;
23+
stablePinLevel = rawPinLevel;
2324
}
25+
}
2426

25-
lastPinLevel = rawPinLevel;
26-
return pressed;
27+
lastPinLevel = rawPinLevel;
28+
return pressed;
2729
}

src/drivers/Button.h

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,26 @@
44
#include "Arduino.h"
55

66
class Button {
7-
private:
8-
const int pinNumber;
9-
bool stablePinLevel;
10-
bool lastPinLevel;
11-
unsigned long lastDebounceTime;
7+
private:
8+
const int pinNumber;
9+
bool stablePinLevel;
10+
bool lastPinLevel;
11+
unsigned long lastDebounceTime;
1212

13-
inline void resetDebounceTimer() {
14-
lastDebounceTime = millis();
15-
}
13+
inline void resetDebounceTimer() {
14+
lastDebounceTime = millis();
15+
}
1616

17-
inline bool hasDebounceTimePassed() const {
18-
return (millis() - lastDebounceTime) > Config::DEBOUNCE_DELAY;
19-
}
17+
inline bool hasDebounceTimePassed() const {
18+
return (millis() - lastDebounceTime) > Config::DEBOUNCE_DELAY;
19+
}
2020

21-
public:
22-
Button(int pin);
23-
void begin();
24-
bool isPressed();
21+
public:
22+
Button(int pin);
23+
void begin();
24+
bool isPressed();
2525

26-
inline bool isHeld() const {
27-
return stablePinLevel == LOW;
28-
}
26+
inline bool isHeld() const {
27+
return stablePinLevel == LOW;
28+
}
2929
};

src/drivers/GPSWrapper.cpp

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,45 +5,50 @@
55
#include "../Config.h"
66

77
bool GPSWrapper::begin() {
8-
if (gnss.begin() != 0) return false;
9-
gnss.select(GPS);
10-
gnss.select(QZ_L1CA);
11-
if (gnss.start(COLD_START) != 0) return false;
12-
13-
return true;
8+
if (gnss.begin() != 0)
9+
return false;
10+
gnss.select(GPS);
11+
gnss.select(QZ_L1CA);
12+
if (gnss.start(COLD_START) != 0)
13+
return false;
14+
15+
return true;
1416
}
1517

1618
void GPSWrapper::update() {
17-
if (!gnss.waitUpdate(0)) return;
18-
gnss.getNavData(&navData);
19+
if (!gnss.waitUpdate(0))
20+
return;
21+
gnss.getNavData(&navData);
1922
}
2023

2124
float GPSWrapper::getSpeedKmh() const {
22-
if (!(navData.posFixMode == Fix2D || navData.posFixMode == Fix3D)) return 0.0f;
23-
if (navData.velocity < 0.1f) return 0.0f; // 測位誤差対策
24-
float speedKmh = navData.velocity * 3.6f;
25-
return speedKmh;
25+
if (!(navData.posFixMode == Fix2D || navData.posFixMode == Fix3D))
26+
return 0.0f;
27+
if (navData.velocity < 0.1f)
28+
return 0.0f; // 測位誤差対策
29+
float speedKmh = navData.velocity * 3.6f;
30+
return speedKmh;
2631
}
2732

28-
void GPSWrapper::getTimeJST(char* displayData, size_t size) const {
29-
if (!(navData.time.year >= 2020)) {
30-
snprintf(displayData, size, "??:??");
31-
return;
32-
}
33+
void GPSWrapper::getTimeJST(char *displayData, size_t size) const {
34+
if (!(navData.time.year >= 2020)) {
35+
snprintf(displayData, size, "??:??");
36+
return;
37+
}
3338

34-
int hour = (navData.time.hour + Config::Time::JST_OFFSET + 24) % 24;
35-
int minute = navData.time.minute;
36-
snprintf(displayData, size, "%02d:%02d", hour, minute);
39+
int hour = (navData.time.hour + Config::Time::JST_OFFSET + 24) % 24;
40+
int minute = navData.time.minute;
41+
snprintf(displayData, size, "%02d:%02d", hour, minute);
3742
}
3843

3944
#ifdef UNIT_TEST
4045
void GPSWrapper::setMockTime(int h, int m, int s) {
41-
SpGnss::mockTimeData.hour = h;
42-
SpGnss::mockTimeData.minute = m;
43-
SpGnss::mockTimeData.second = s;
46+
SpGnss::mockTimeData.hour = h;
47+
SpGnss::mockTimeData.minute = m;
48+
SpGnss::mockTimeData.second = s;
4449
}
4550

4651
void GPSWrapper::setMockSpeed(float speedKmh) {
47-
SpGnss::mockVelocityData = speedKmh / 3.6f;
52+
SpGnss::mockVelocityData = speedKmh / 3.6f;
4853
}
4954
#endif

src/drivers/GPSWrapper.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@
44
#include <GNSS.h>
55

66
class GPSWrapper {
7-
public:
8-
bool begin();
9-
void update();
10-
float getSpeedKmh() const;
11-
void getTimeJST(char* buffer, size_t size) const;
7+
public:
8+
bool begin();
9+
void update();
10+
float getSpeedKmh() const;
11+
void getTimeJST(char *buffer, size_t size) const;
1212

13-
private:
14-
SpGnss gnss;
15-
SpNavData navData;
13+
private:
14+
SpGnss gnss;
15+
SpNavData navData;
1616

1717
#ifdef UNIT_TEST
18-
public:
19-
static void setMockTime(int h, int m, int s);
20-
static void setMockSpeed(float speedKmh);
18+
public:
19+
static void setMockTime(int h, int m, int s);
20+
static void setMockSpeed(float speedKmh);
2121
#endif
2222
};

src/drivers/OLEDDriver.cpp

Lines changed: 50 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -5,75 +5,78 @@
55
#include "../Config.h"
66

77
OLEDDriver::OLEDDriver() : display(Config::OLED::WIDTH, Config::OLED::HEIGHT, &Wire, -1) {
8-
currentType = DisplayDataType::INVALID;
8+
currentType = DisplayDataType::INVALID;
99
}
1010

1111
bool OLEDDriver::begin() {
12-
if (!display.begin(SSD1306_SWITCHCAPVCC, Config::OLED::ADDRESS)) return false;
12+
if (!display.begin(SSD1306_SWITCHCAPVCC, Config::OLED::ADDRESS))
13+
return false;
1314

14-
display.clearDisplay();
15-
display.display();
16-
display.setTextColor(SSD1306_WHITE);
17-
display.setTextSize(1);
15+
display.clearDisplay();
16+
display.display();
17+
display.setTextColor(SSD1306_WHITE);
18+
display.setTextSize(1);
1819

19-
currentValue = "";
20-
return true;
20+
currentValue = "";
21+
return true;
2122
}
2223

2324
void OLEDDriver::clear() {
24-
display.clearDisplay();
25-
display.display();
26-
currentValue = "";
27-
currentType = DisplayDataType::INVALID;
25+
display.clearDisplay();
26+
display.display();
27+
currentValue = "";
28+
currentType = DisplayDataType::INVALID;
2829
}
2930

30-
void OLEDDriver::drawTitle(const String& title) {
31-
display.setTextSize(1);
32-
display.setCursor(0, 0);
33-
display.println(title);
31+
void OLEDDriver::drawTitle(const String &title) {
32+
display.setTextSize(1);
33+
display.setCursor(0, 0);
34+
display.println(title);
3435
}
3536

36-
void OLEDDriver::drawUnit(const String& unit) {
37-
if (unit.length() <= 0) return;
37+
void OLEDDriver::drawUnit(const String &unit) {
38+
if (unit.length() <= 0)
39+
return;
3840

39-
int16_t x1, y1;
40-
uint16_t w, h;
41-
display.setTextSize(1);
42-
display.getTextBounds(unit, 0, 0, &x1, &y1, &w, &h);
43-
display.setCursor(Config::OLED::WIDTH - w - 4, Config::OLED::HEIGHT - h - 2);
44-
display.print(unit);
41+
int16_t x1, y1;
42+
uint16_t w, h;
43+
display.setTextSize(1);
44+
display.getTextBounds(unit, 0, 0, &x1, &y1, &w, &h);
45+
display.setCursor(Config::OLED::WIDTH - w - 4, Config::OLED::HEIGHT - h - 2);
46+
display.print(unit);
4547
}
4648

47-
void OLEDDriver::drawValue(const String& value) {
48-
int len = value.length();
49-
if (len < 5)
50-
display.setTextSize(3);
51-
else
52-
display.setTextSize(2);
49+
void OLEDDriver::drawValue(const String &value) {
50+
int len = value.length();
51+
if (len < 5)
52+
display.setTextSize(3);
53+
else
54+
display.setTextSize(2);
5355

54-
int16_t x1, y1;
55-
uint16_t w, h;
56-
display.getTextBounds(value, 0, 0, &x1, &y1, &w, &h);
56+
int16_t x1, y1;
57+
uint16_t w, h;
58+
display.getTextBounds(value, 0, 0, &x1, &y1, &w, &h);
5759

58-
int x = (Config::OLED::WIDTH - w) / 2;
59-
int y = (Config::OLED::HEIGHT - h) / 2 + 8; // shift down a bit below title
60+
int x = (Config::OLED::WIDTH - w) / 2;
61+
int y = (Config::OLED::HEIGHT - h) / 2 + 8; // shift down a bit below title
6062

61-
display.setCursor(x, y);
62-
display.print(value);
63+
display.setCursor(x, y);
64+
display.print(value);
6365
}
6466

65-
void OLEDDriver::show(DisplayDataType type, const char* value) {
66-
if (type == currentType && currentValue.equals(value)) return;
67+
void OLEDDriver::show(DisplayDataType type, const char *value) {
68+
if (type == currentType && currentValue.equals(value))
69+
return;
6770

68-
currentType = type;
69-
currentValue = String(value);
71+
currentType = type;
72+
currentValue = String(value);
7073

71-
display.clearDisplay();
74+
display.clearDisplay();
7275

73-
DisplayMetadata meta = getDisplayMetadata(type);
74-
drawTitle(meta.title);
75-
drawValue(currentValue);
76-
drawUnit(meta.unit);
76+
DisplayMetadata meta = getDisplayMetadata(type);
77+
drawTitle(meta.title);
78+
drawValue(currentValue);
79+
drawUnit(meta.unit);
7780

78-
display.display();
81+
display.display();
7982
}

0 commit comments

Comments
 (0)