Skip to content

Commit a931de0

Browse files
committed
Otto:增加boot按键打断;电量修改区间
1 parent 0f0cbd7 commit a931de0

File tree

2 files changed

+22
-29
lines changed

2 files changed

+22
-29
lines changed

main/boards/ottoRobot/ottoRobot.cc

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@
99
#include "Otto.h"
1010
#include "application.h"
1111
#include "audio_codecs/no_audio_codec.h"
12+
#include "button.h"
1213
#include "config.h"
1314
#include "display/lcd_display.h"
1415
#include "iot/thing_manager.h"
16+
#include "ml307_board.h"
1517
#include "power_manager.h"
1618
#include "system_reset.h"
1719
#include "wifi_board.h"
18-
1920
#define TAG "OttoRobot"
2021

2122
LV_FONT_DECLARE(font_puhui_16_4);
@@ -25,6 +26,7 @@ class OttoRobot : public WifiBoard {
2526
private:
2627
LcdDisplay* display_;
2728
PowerManager* power_manager_;
29+
Button boot_button_;
2830

2931
void InitializePowerManager() {
3032
power_manager_ =
@@ -81,6 +83,17 @@ class OttoRobot : public WifiBoard {
8183
});
8284
}
8385

86+
void InitializeButtons() {
87+
boot_button_.OnClick([this]() {
88+
auto& app = Application::GetInstance();
89+
if (app.GetDeviceState() == kDeviceStateStarting &&
90+
!WifiStation::GetInstance().IsConnected()) {
91+
ResetWifiConfiguration();
92+
}
93+
app.ToggleChatState();
94+
});
95+
}
96+
8497
void InitializeIot() {
8598
auto& thing_manager = iot::ThingManager::GetInstance();
8699
thing_manager.AddThing(iot::CreateThing("Speaker"));
@@ -90,9 +103,10 @@ class OttoRobot : public WifiBoard {
90103
}
91104

92105
public:
93-
OttoRobot() : display_(nullptr) {
106+
OttoRobot() : boot_button_(BOOT_BUTTON_GPIO) {
94107
InitializeSpi();
95108
InitializeLcdDisplay();
109+
InitializeButtons();
96110
InitializeIot();
97111
InitializePowerManager();
98112
if (DISPLAY_BACKLIGHT_PIN != GPIO_NUM_NC) {

main/boards/ottoRobot/power_manager.h

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,8 @@ class PowerManager {
1212
static constexpr struct {
1313
uint16_t adc;
1414
uint8_t level;
15-
} BATTERY_LEVELS[] = {
16-
{1861, 0}, // 3.00V
17-
{2140, 5}, // 3.45V
18-
{2283, 10}, // 3.68V
19-
{2320, 20}, // 3.74V
20-
{2339, 30}, // 3.77V
21-
{2351, 40}, // 3.79V
22-
{2370, 50}, // 3.82V
23-
{2401, 60}, // 3.87V
24-
{2432, 70}, // 3.92V
25-
{2469, 80}, // 3.98V
26-
{2519, 90}, // 4.06V
27-
{2605, 100} // 4.20V
28-
};
29-
static constexpr size_t BATTERY_LEVELS_COUNT = 12;
15+
} BATTERY_LEVELS[] = {{2150, 0}, {2450, 100}};
16+
static constexpr size_t BATTERY_LEVELS_COUNT = 2;
3017
static constexpr size_t ADC_VALUES_COUNT = 10;
3118

3219
esp_timer_handle_t timer_handle_ = nullptr;
@@ -69,22 +56,14 @@ class PowerManager {
6956
}
7057

7158
void CalculateBatteryLevel(uint32_t average_adc) {
72-
if (average_adc < BATTERY_LEVELS[0].adc) {
59+
if (average_adc <= BATTERY_LEVELS[0].adc) {
7360
battery_level_ = 0;
7461
} else if (average_adc >= BATTERY_LEVELS[BATTERY_LEVELS_COUNT - 1].adc) {
7562
battery_level_ = 100;
7663
} else {
77-
for (size_t i = 0; i < BATTERY_LEVELS_COUNT - 1; i++) {
78-
if (average_adc >= BATTERY_LEVELS[i].adc &&
79-
average_adc < BATTERY_LEVELS[i + 1].adc) {
80-
float ratio = static_cast<float>(average_adc - BATTERY_LEVELS[i].adc) /
81-
(BATTERY_LEVELS[i + 1].adc - BATTERY_LEVELS[i].adc);
82-
battery_level_ =
83-
BATTERY_LEVELS[i].level +
84-
ratio * (BATTERY_LEVELS[i + 1].level - BATTERY_LEVELS[i].level);
85-
break;
86-
}
87-
}
64+
float ratio = static_cast<float>(average_adc - BATTERY_LEVELS[0].adc) /
65+
(BATTERY_LEVELS[1].adc - BATTERY_LEVELS[0].adc);
66+
battery_level_ = ratio * 100;
8867
}
8968
}
9069

0 commit comments

Comments
 (0)