Skip to content

Commit d307c6b

Browse files
committed
Merge branch 'develop' into refresh_rework
2 parents 10b5d30 + 9fb3755 commit d307c6b

12 files changed

Lines changed: 80 additions & 216 deletions

src/components/battery/BatteryController.cpp

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ void Battery::Update() {
2323
return;
2424
}
2525
// Non blocking read
26-
samples = 0;
2726
isReading = true;
2827
SaadcInit();
2928

@@ -40,9 +39,9 @@ void Battery::SaadcInit() {
4039

4140
nrf_saadc_channel_config_t adcChannelConfig = {.resistor_p = NRF_SAADC_RESISTOR_DISABLED,
4241
.resistor_n = NRF_SAADC_RESISTOR_DISABLED,
43-
.gain = NRF_SAADC_GAIN1_5,
42+
.gain = NRF_SAADC_GAIN1_4,
4443
.reference = NRF_SAADC_REFERENCE_INTERNAL,
45-
.acq_time = NRF_SAADC_ACQTIME_3US,
44+
.acq_time = NRF_SAADC_ACQTIME_40US,
4645
.mode = NRF_SAADC_MODE_SINGLE_ENDED,
4746
.burst = NRF_SAADC_BURST_ENABLED,
4847
.pin_p = batteryVoltageAdcInput,
@@ -60,22 +59,21 @@ void Battery::SaadcEventHandler(nrfx_saadc_evt_t const* p_event) {
6059
APP_ERROR_CHECK(nrfx_saadc_buffer_convert(&saadc_value, 1));
6160

6261
// A hardware voltage divider divides the battery voltage by 2
63-
// ADC gain is 1/5
64-
// thus adc_voltage = battery_voltage / 2 * gain = battery_voltage / 10
65-
// reference_voltage is 0.6V
62+
// ADC gain is 1/4
63+
// thus adc_voltage = battery_voltage / 2 * gain = battery_voltage / 8
64+
// reference_voltage is 600mV
6665
// p_event->data.done.p_buffer[0] = (adc_voltage / reference_voltage) * 1024
67-
voltage = p_event->data.done.p_buffer[0] * 6000 / 1024;
68-
percentRemaining = (voltage - battery_min) * 100 / (battery_max - battery_min);
69-
percentRemaining = std::max(percentRemaining, 0);
70-
percentRemaining = std::min(percentRemaining, 100);
71-
percentRemainingBuffer.Insert(percentRemaining);
72-
73-
samples++;
74-
if (samples > percentRemainingSamples) {
75-
nrfx_saadc_uninit();
76-
isReading = false;
66+
voltage = p_event->data.done.p_buffer[0] * (8 * 600) / 1024;
67+
68+
if (voltage > battery_max) {
69+
percentRemaining = 100;
70+
} else if (voltage < battery_min) {
71+
percentRemaining = 0;
7772
} else {
78-
nrfx_saadc_sample();
73+
percentRemaining = (voltage - battery_min) * 100 / (battery_max - battery_min);
7974
}
75+
76+
nrfx_saadc_uninit();
77+
isReading = false;
8078
}
8179
}

src/components/battery/BatteryController.h

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -7,38 +7,6 @@
77
namespace Pinetime {
88
namespace Controllers {
99

10-
/** A simple circular buffer that can be used to average
11-
out the sensor values. The total capacity of the CircBuffer
12-
is given as the template parameter N.
13-
*/
14-
template <int N> class CircBuffer {
15-
public:
16-
CircBuffer() : arr {}, sz {}, cap {N}, head {} {
17-
}
18-
/**
19-
insert member function overwrites the next data to the current
20-
HEAD and moves the HEAD to the newly inserted value.
21-
*/
22-
void Insert(const uint8_t num) {
23-
head %= cap;
24-
arr[head++] = num;
25-
if (sz != cap) {
26-
sz++;
27-
}
28-
}
29-
30-
uint8_t GetAverage() const {
31-
int sum = std::accumulate(arr.begin(), arr.end(), 0);
32-
return static_cast<uint8_t>(sum / sz);
33-
}
34-
35-
private:
36-
std::array<uint8_t, N> arr; /**< internal array used to store the values*/
37-
uint8_t sz; /**< The current size of the array.*/
38-
uint8_t cap; /**< Total capacity of the CircBuffer.*/
39-
uint8_t head; /**< The current head of the CircBuffer*/
40-
};
41-
4210
class Battery {
4311
public:
4412
Battery();
@@ -47,10 +15,7 @@ namespace Pinetime {
4715
void Update();
4816

4917
uint8_t PercentRemaining() const {
50-
auto avg = percentRemainingBuffer.GetAverage();
51-
avg = std::min(avg, static_cast<uint8_t>(100));
52-
avg = std::max(avg, static_cast<uint8_t>(0));
53-
return avg;
18+
return percentRemaining;
5419
}
5520

5621
uint16_t Voltage() const {
@@ -69,14 +34,11 @@ namespace Pinetime {
6934
static Battery* instance;
7035
nrf_saadc_value_t saadc_value;
7136

72-
static constexpr uint8_t percentRemainingSamples = 5;
73-
CircBuffer<percentRemainingSamples> percentRemainingBuffer {};
74-
7537
static constexpr uint32_t chargingPin = 12;
7638
static constexpr uint32_t powerPresentPin = 19;
7739
static constexpr nrf_saadc_input_t batteryVoltageAdcInput = NRF_SAADC_INPUT_AIN7;
7840
uint16_t voltage = 0;
79-
int percentRemaining = -1;
41+
uint8_t percentRemaining = 0;
8042

8143
bool isCharging = false;
8244
bool isPowerPresent = false;
@@ -87,7 +49,6 @@ namespace Pinetime {
8749
static void AdcCallbackStatic(nrfx_saadc_evt_t const* event);
8850

8951
bool isReading = false;
90-
uint8_t samples = 0;
9152
};
9253
}
9354
}

src/components/datetime/DateTimeController.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ void DateTime::UpdateTime(uint32_t systickCounter) {
5555
auto time = date::make_time(currentDateTime - dp);
5656
auto yearMonthDay = date::year_month_day(dp);
5757

58-
year = (int) yearMonthDay.year();
59-
month = static_cast<Months>((unsigned) yearMonthDay.month());
60-
day = (unsigned) yearMonthDay.day();
58+
year = static_cast<int>(yearMonthDay.year());
59+
month = static_cast<Months>(static_cast<unsigned>(yearMonthDay.month()));
60+
day = static_cast<unsigned>(yearMonthDay.day());
6161
dayOfWeek = static_cast<Days>(date::weekday(yearMonthDay).iso_encoding());
6262

6363
hour = time.hours().count();
@@ -75,31 +75,31 @@ void DateTime::UpdateTime(uint32_t systickCounter) {
7575
}
7676

7777
const char* DateTime::MonthShortToString() {
78-
return DateTime::MonthsString[(uint8_t) month];
78+
return DateTime::MonthsString[static_cast<uint8_t>(month)];
7979
}
8080

8181
const char* DateTime::MonthShortToStringLow() {
82-
return DateTime::MonthsStringLow[(uint8_t) month];
82+
return DateTime::MonthsStringLow[static_cast<uint8_t>(month)];
8383
}
8484

8585
const char* DateTime::MonthsToStringLow() {
86-
return DateTime::MonthsLow[(uint8_t) month];
86+
return DateTime::MonthsLow[static_cast<uint8_t>(month)];
8787
}
8888

8989
const char* DateTime::DayOfWeekToString() {
90-
return DateTime::DaysString[(uint8_t) dayOfWeek];
90+
return DateTime::DaysString[static_cast<uint8_t>(dayOfWeek)];
9191
}
9292

9393
const char* DateTime::DayOfWeekShortToString() {
94-
return DateTime::DaysStringShort[(uint8_t) dayOfWeek];
94+
return DateTime::DaysStringShort[static_cast<uint8_t>(dayOfWeek)];
9595
}
9696

9797
const char* DateTime::DayOfWeekToStringLow() {
98-
return DateTime::DaysStringLow[(uint8_t) dayOfWeek];
98+
return DateTime::DaysStringLow[static_cast<uint8_t>(dayOfWeek)];
9999
}
100100

101101
const char* DateTime::DayOfWeekShortToStringLow() {
102-
return DateTime::DaysStringShortLow[(uint8_t) dayOfWeek];
102+
return DateTime::DaysStringShortLow[static_cast<uint8_t>(dayOfWeek)];
103103
}
104104

105105
void DateTime::Register(Pinetime::System::SystemTask* systemTask) {

src/displayapp/screens/BatteryIcon.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
using namespace Pinetime::Applications::Screens;
66

77
const char* BatteryIcon::GetBatteryIcon(uint8_t batteryPercent) {
8-
if (batteryPercent > 90)
8+
if (batteryPercent > 87)
99
return Symbols::batteryFull;
10-
if (batteryPercent > 75)
10+
if (batteryPercent > 62)
1111
return Symbols::batteryThreeQuarter;
12-
if (batteryPercent > 50)
12+
if (batteryPercent > 37)
1313
return Symbols::batteryHalf;
14-
if (batteryPercent > 25)
14+
if (batteryPercent > 12)
1515
return Symbols::batteryOneQuarter;
1616
return Symbols::batteryEmpty;
1717
}

src/displayapp/screens/Clock.cpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@
22

33
#include <date/date.h>
44
#include <lvgl/lvgl.h>
5-
#include <cstdio>
6-
#include "BatteryIcon.h"
7-
#include "BleIcon.h"
8-
#include "NotificationIcon.h"
9-
#include "Symbols.h"
105
#include "components/battery/BatteryController.h"
116
#include "components/motion/MotionController.h"
127
#include "components/ble/BleController.h"
@@ -84,16 +79,3 @@ std::unique_ptr<Screen> Clock::PineTimeStyleScreen() {
8479
settingsController,
8580
motionController);
8681
}
87-
88-
/*
89-
// Examples for more watch faces
90-
std::unique_ptr<Screen> Clock::WatchFaceMinimalScreen() {
91-
return std::make_unique<Screens::WatchFaceMinimal>(app, dateTimeController, batteryController, bleController, notificatioManager,
92-
settingsController);
93-
}
94-
95-
std::unique_ptr<Screen> Clock::WatchFaceCustomScreen() {
96-
return std::make_unique<Screens::WatchFaceCustom>(app, dateTimeController, batteryController, bleController, notificatioManager,
97-
settingsController);
98-
}
99-
*/

src/displayapp/screens/Clock.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
#include "components/datetime/DateTimeController.h"
1010

1111
namespace Pinetime {
12-
namespace Drivers {
13-
class BMA421;
14-
}
1512
namespace Controllers {
1613
class Settings;
1714
class Battery;
@@ -49,10 +46,6 @@ namespace Pinetime {
4946
std::unique_ptr<Screen> WatchFaceDigitalScreen();
5047
std::unique_ptr<Screen> WatchFaceAnalogScreen();
5148
std::unique_ptr<Screen> PineTimeStyleScreen();
52-
53-
// Examples for more watch faces
54-
// std::unique_ptr<Screen> WatchFaceMinimalScreen();
55-
// std::unique_ptr<Screen> WatchFaceCustomScreen();
5649
};
5750
}
5851
}

0 commit comments

Comments
 (0)