bump to 0.8.0
This commit is contained in:
@ -10,16 +10,11 @@
|
||||
#include <esp_spiffs.h>
|
||||
#include <driver/gpio.h>
|
||||
#include <driver/i2c_master.h>
|
||||
#include <esp_adc/adc_oneshot.h>
|
||||
#include <esp_adc/adc_cali.h>
|
||||
#include <esp_adc/adc_cali_scheme.h>
|
||||
|
||||
static const char *TAG = "KevinBoxBoard";
|
||||
|
||||
class KevinBoxBoard : public Ml307Board {
|
||||
private:
|
||||
adc_oneshot_unit_handle_t adc1_handle_;
|
||||
adc_cali_handle_t adc1_cali_handle_;
|
||||
i2c_master_bus_handle_t display_i2c_bus_;
|
||||
i2c_master_bus_handle_t codec_i2c_bus_;
|
||||
Button boot_button_;
|
||||
@ -50,27 +45,6 @@ private:
|
||||
gpio_set_level(GPIO_NUM_15, 1);
|
||||
}
|
||||
|
||||
void InitializeADC() {
|
||||
adc_oneshot_unit_init_cfg_t init_config1 = {};
|
||||
init_config1.unit_id = ADC_UNIT_1;
|
||||
ESP_ERROR_CHECK(adc_oneshot_new_unit(&init_config1, &adc1_handle_));
|
||||
|
||||
//-------------ADC1 Config---------------//
|
||||
adc_oneshot_chan_cfg_t config = {
|
||||
.atten = ADC_ATTEN_DB_12,
|
||||
.bitwidth = ADC_BITWIDTH_DEFAULT,
|
||||
};
|
||||
ESP_ERROR_CHECK(adc_oneshot_config_channel(adc1_handle_, ADC_CHANNEL_0, &config));
|
||||
|
||||
adc_cali_curve_fitting_config_t cali_config = {
|
||||
.unit_id = ADC_UNIT_1,
|
||||
.chan = ADC_CHANNEL_0,
|
||||
.atten = ADC_ATTEN_DB_12,
|
||||
.bitwidth = ADC_BITWIDTH_DEFAULT,
|
||||
};
|
||||
ESP_ERROR_CHECK(adc_cali_create_scheme_curve_fitting(&cali_config, &adc1_cali_handle_));
|
||||
}
|
||||
|
||||
void InitializeDisplayI2c() {
|
||||
i2c_master_bus_config_t bus_config = {
|
||||
.i2c_port = I2C_NUM_0,
|
||||
@ -153,7 +127,6 @@ public:
|
||||
ESP_LOGI(TAG, "Initializing KevinBoxBoard");
|
||||
InitializeDisplayI2c();
|
||||
InitializeCodecI2c();
|
||||
InitializeADC();
|
||||
MountStorage();
|
||||
Enable4GModule();
|
||||
|
||||
@ -178,14 +151,6 @@ public:
|
||||
static Ssd1306Display display(display_i2c_bus_, DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y);
|
||||
return &display;
|
||||
}
|
||||
|
||||
virtual bool GetBatteryVoltage(int &voltage, bool& charging) override {
|
||||
ESP_ERROR_CHECK(adc_oneshot_get_calibrated_result(adc1_handle_, adc1_cali_handle_, ADC_CHANNEL_0, &voltage));
|
||||
voltage *= 3;
|
||||
charging = false;
|
||||
ESP_LOGI(TAG, "Battery voltage: %d, Charging: %d", voltage, charging);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
DECLARE_BOARD(KevinBoxBoard);
|
||||
@ -10,16 +10,11 @@
|
||||
#include <esp_spiffs.h>
|
||||
#include <driver/gpio.h>
|
||||
#include <driver/i2c_master.h>
|
||||
#include <esp_adc/adc_oneshot.h>
|
||||
#include <esp_adc/adc_cali.h>
|
||||
#include <esp_adc/adc_cali_scheme.h>
|
||||
|
||||
static const char *TAG = "KevinBoxBoard";
|
||||
|
||||
class KevinBoxBoard : public Ml307Board {
|
||||
private:
|
||||
adc_oneshot_unit_handle_t adc1_handle_;
|
||||
adc_cali_handle_t adc1_cali_handle_;
|
||||
i2c_master_bus_handle_t display_i2c_bus_;
|
||||
i2c_master_bus_handle_t codec_i2c_bus_;
|
||||
Button boot_button_;
|
||||
@ -51,27 +46,6 @@ private:
|
||||
gpio_set_level(GPIO_NUM_18, 1);
|
||||
}
|
||||
|
||||
void InitializeADC() {
|
||||
adc_oneshot_unit_init_cfg_t init_config1 = {};
|
||||
init_config1.unit_id = ADC_UNIT_1;
|
||||
ESP_ERROR_CHECK(adc_oneshot_new_unit(&init_config1, &adc1_handle_));
|
||||
|
||||
//-------------ADC1 Config---------------//
|
||||
adc_oneshot_chan_cfg_t config = {
|
||||
.atten = ADC_ATTEN_DB_12,
|
||||
.bitwidth = ADC_BITWIDTH_DEFAULT,
|
||||
};
|
||||
ESP_ERROR_CHECK(adc_oneshot_config_channel(adc1_handle_, ADC_CHANNEL_0, &config));
|
||||
|
||||
adc_cali_curve_fitting_config_t cali_config = {
|
||||
.unit_id = ADC_UNIT_1,
|
||||
.chan = ADC_CHANNEL_0,
|
||||
.atten = ADC_ATTEN_DB_12,
|
||||
.bitwidth = ADC_BITWIDTH_DEFAULT,
|
||||
};
|
||||
ESP_ERROR_CHECK(adc_cali_create_scheme_curve_fitting(&cali_config, &adc1_cali_handle_));
|
||||
}
|
||||
|
||||
void InitializeDisplayI2c() {
|
||||
i2c_master_bus_config_t bus_config = {
|
||||
.i2c_port = I2C_NUM_0,
|
||||
@ -154,19 +128,9 @@ public:
|
||||
ESP_LOGI(TAG, "Initializing KevinBoxBoard");
|
||||
InitializeDisplayI2c();
|
||||
InitializeCodecI2c();
|
||||
InitializeADC();
|
||||
MountStorage();
|
||||
Enable4GModule();
|
||||
|
||||
gpio_config_t charging_io = {
|
||||
.pin_bit_mask = (1ULL << 2),
|
||||
.mode = GPIO_MODE_INPUT,
|
||||
.pull_up_en = GPIO_PULLUP_ENABLE,
|
||||
.pull_down_en = GPIO_PULLDOWN_DISABLE,
|
||||
.intr_type = GPIO_INTR_DISABLE,
|
||||
};
|
||||
gpio_config(&charging_io);
|
||||
|
||||
InitializeButtons();
|
||||
|
||||
Ml307Board::Initialize();
|
||||
@ -188,14 +152,6 @@ public:
|
||||
static Ssd1306Display display(display_i2c_bus_, DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y);
|
||||
return &display;
|
||||
}
|
||||
|
||||
virtual bool GetBatteryVoltage(int &voltage, bool& charging) override {
|
||||
ESP_ERROR_CHECK(adc_oneshot_get_calibrated_result(adc1_handle_, adc1_cali_handle_, ADC_CHANNEL_0, &voltage));
|
||||
voltage *= 3;
|
||||
charging = gpio_get_level(GPIO_NUM_2) == 0;
|
||||
ESP_LOGI(TAG, "Battery voltage: %d, Charging: %d", voltage, charging);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
DECLARE_BOARD(KevinBoxBoard);
|
||||
84
main/boards/kevin-box-2/axp2101.cc
Normal file
84
main/boards/kevin-box-2/axp2101.cc
Normal file
@ -0,0 +1,84 @@
|
||||
#include "axp2101.h"
|
||||
|
||||
#include <esp_log.h>
|
||||
|
||||
static const char *TAG = "AXP2101";
|
||||
|
||||
bool Axp2101::Initialize(i2c_master_bus_handle_t i2c_bus, int i2c_device_address) {
|
||||
i2c_device_config_t axp2101_cfg = {
|
||||
.dev_addr_length = I2C_ADDR_BIT_LEN_7,
|
||||
.device_address = (uint16_t)i2c_device_address,
|
||||
.scl_speed_hz = 100000,
|
||||
.scl_wait_us = 0,
|
||||
.flags = {
|
||||
.disable_ack_check = 0,
|
||||
},
|
||||
};
|
||||
ESP_ERROR_CHECK(i2c_master_bus_add_device(i2c_bus, &axp2101_cfg, &i2c_device_));
|
||||
|
||||
WriteReg(0x93, 0x1c); // 配置aldo2输出为3.3v
|
||||
|
||||
uint8_t value = ReadReg(0x90); // XPOWERS_AXP2101_LDO_ONOFF_CTRL0
|
||||
value = value | 0x02; // set bit 1 (ALDO2)
|
||||
WriteReg(0x90, value); // and power channels now enabled
|
||||
|
||||
WriteReg(0x64, 0x03); // CV charger voltage setting to 42V
|
||||
value = ReadReg(0x62);
|
||||
ESP_LOGI(TAG, "axp2101 read 0x62 get: 0x%X", value);
|
||||
|
||||
WriteReg(0x61, 0x05); // set Main battery precharge current to 125mA
|
||||
WriteReg(0x62, 0x10); // set Main battery charger current to 900mA ( 0x08-200mA, 0x09-300mA, 0x0A-400mA )
|
||||
WriteReg(0x63, 0x15); // set Main battery term charge current to 125mA
|
||||
value = ReadReg(0x62);
|
||||
ESP_LOGI(TAG, "axp2101 read 0x62 get: 0x%X", value);
|
||||
|
||||
value = ReadReg(0x18);
|
||||
ESP_LOGI(TAG, "axp2101 read 0x18 get: 0x%X", value);
|
||||
value = value & 0b11100000;
|
||||
value = value | 0b00001110;
|
||||
WriteReg(0x18, value);
|
||||
value = ReadReg(0x18);
|
||||
ESP_LOGI(TAG, "axp2101 read 0x18 get: 0x%X", value);
|
||||
|
||||
WriteReg(0x14, 0x00); // set minimum system voltage to 4.1V (default 4.7V), for poor USB cables
|
||||
WriteReg(0x15, 0x00); // set input voltage limit to 3.88v, for poor USB cables
|
||||
WriteReg(0x16, 0x05); // set input voltage limit to 3.88v, for poor USB cables
|
||||
|
||||
WriteReg(0x24, 0x01); // set Vsys for PWROFF threshold to 3.2V (default - 2.6V and kill battery)
|
||||
WriteReg(0x50, 0x14); // set TS pin to EXTERNAL input (not temperature)
|
||||
return true;
|
||||
}
|
||||
|
||||
void Axp2101::WriteReg(uint8_t reg, uint8_t value) {
|
||||
uint8_t buffer[2];
|
||||
buffer[0] = reg;
|
||||
buffer[1] = value;
|
||||
ESP_ERROR_CHECK(i2c_master_transmit(i2c_device_, buffer, 2, 100));
|
||||
}
|
||||
|
||||
uint8_t Axp2101::ReadReg(uint8_t reg) {
|
||||
uint8_t buffer[1];
|
||||
ESP_ERROR_CHECK(i2c_master_transmit_receive(i2c_device_, ®, 1, buffer, 1, 100));
|
||||
return buffer[0];
|
||||
}
|
||||
|
||||
bool Axp2101::IsCharging() {
|
||||
uint8_t value = ReadReg(0x01);
|
||||
return (value & 0b01100000) == 0b00100000;
|
||||
}
|
||||
|
||||
bool Axp2101::IsChargingDone() {
|
||||
uint8_t value = ReadReg(0x01);
|
||||
return (value & 0b00000111) == 0b00000100;
|
||||
}
|
||||
|
||||
int Axp2101::GetBatteryLevel() {
|
||||
uint8_t value = ReadReg(0xA4);
|
||||
return value;
|
||||
}
|
||||
|
||||
void Axp2101::PowerOff() {
|
||||
uint8_t value = ReadReg(0x10);
|
||||
value = value | 0x01;
|
||||
WriteReg(0x10, value);
|
||||
}
|
||||
22
main/boards/kevin-box-2/axp2101.h
Normal file
22
main/boards/kevin-box-2/axp2101.h
Normal file
@ -0,0 +1,22 @@
|
||||
#ifndef __AXP2101_H__
|
||||
#define __AXP2101_H__
|
||||
|
||||
#include <driver/i2c_master.h>
|
||||
|
||||
class Axp2101 {
|
||||
public:
|
||||
Axp2101() = default;
|
||||
bool Initialize(i2c_master_bus_handle_t i2c_bus, int i2c_device_address);
|
||||
bool IsCharging();
|
||||
bool IsChargingDone();
|
||||
int GetBatteryLevel();
|
||||
void PowerOff();
|
||||
|
||||
private:
|
||||
i2c_master_dev_handle_t i2c_device_ = nullptr;
|
||||
|
||||
void WriteReg(uint8_t reg, uint8_t value);
|
||||
uint8_t ReadReg(uint8_t reg);
|
||||
};
|
||||
|
||||
#endif
|
||||
41
main/boards/kevin-box-2/config.h
Normal file
41
main/boards/kevin-box-2/config.h
Normal file
@ -0,0 +1,41 @@
|
||||
#ifndef _BOARD_CONFIG_H_
|
||||
#define _BOARD_CONFIG_H_
|
||||
|
||||
#include <driver/gpio.h>
|
||||
|
||||
#define AUDIO_INPUT_SAMPLE_RATE 24000
|
||||
#define AUDIO_OUTPUT_SAMPLE_RATE 24000
|
||||
|
||||
#define AUDIO_INPUT_REFERENCE true
|
||||
|
||||
#define AUDIO_I2S_GPIO_MCLK GPIO_NUM_40
|
||||
#define AUDIO_I2S_GPIO_WS GPIO_NUM_47
|
||||
#define AUDIO_I2S_GPIO_BCLK GPIO_NUM_38
|
||||
#define AUDIO_I2S_GPIO_DIN GPIO_NUM_39
|
||||
#define AUDIO_I2S_GPIO_DOUT GPIO_NUM_48
|
||||
|
||||
#define AUDIO_CODEC_PA_PIN GPIO_NUM_9
|
||||
#define AUDIO_CODEC_I2C_SDA_PIN GPIO_NUM_42
|
||||
#define AUDIO_CODEC_I2C_SCL_PIN GPIO_NUM_41
|
||||
#define AUDIO_CODEC_ES8311_ADDR ES8311_CODEC_DEFAULT_ADDR
|
||||
#define AUDIO_CODEC_ES7210_ADDR ES7210_CODEC_DEFAULT_ADDR
|
||||
|
||||
#define BUILTIN_LED_GPIO GPIO_NUM_3
|
||||
#define BOOT_BUTTON_GPIO GPIO_NUM_0
|
||||
#define VOLUME_UP_BUTTON_GPIO GPIO_NUM_1
|
||||
#define VOLUME_DOWN_BUTTON_GPIO GPIO_NUM_2
|
||||
|
||||
#define DISPLAY_SDA_PIN GPIO_NUM_7
|
||||
#define DISPLAY_SCL_PIN GPIO_NUM_8
|
||||
#define DISPLAY_WIDTH 128
|
||||
#define DISPLAY_HEIGHT 64
|
||||
#define DISPLAY_MIRROR_X false
|
||||
#define DISPLAY_MIRROR_Y false
|
||||
|
||||
#define ML307_RX_PIN GPIO_NUM_5
|
||||
#define ML307_TX_PIN GPIO_NUM_6
|
||||
|
||||
#define AXP2101_I2C_ADDR 0x34
|
||||
|
||||
|
||||
#endif // _BOARD_CONFIG_H_
|
||||
168
main/boards/kevin-box-2/kevin_box_board.cc
Normal file
168
main/boards/kevin-box-2/kevin_box_board.cc
Normal file
@ -0,0 +1,168 @@
|
||||
#include "boards/ml307_board.h"
|
||||
#include "audio_codecs/box_audio_codec.h"
|
||||
#include "display/ssd1306_display.h"
|
||||
#include "application.h"
|
||||
#include "button.h"
|
||||
#include "led.h"
|
||||
#include "config.h"
|
||||
#include "axp2101.h"
|
||||
|
||||
#include <esp_log.h>
|
||||
#include <esp_spiffs.h>
|
||||
#include <driver/gpio.h>
|
||||
#include <driver/i2c_master.h>
|
||||
|
||||
static const char *TAG = "KevinBoxBoard";
|
||||
|
||||
class KevinBoxBoard : public Ml307Board {
|
||||
private:
|
||||
i2c_master_bus_handle_t display_i2c_bus_;
|
||||
i2c_master_bus_handle_t codec_i2c_bus_;
|
||||
Axp2101 axp2101_;
|
||||
Button boot_button_;
|
||||
Button volume_up_button_;
|
||||
Button volume_down_button_;
|
||||
uint8_t _data_buffer[2];
|
||||
|
||||
void MountStorage() {
|
||||
// Mount the storage partition
|
||||
esp_vfs_spiffs_conf_t conf = {
|
||||
.base_path = "/storage",
|
||||
.partition_label = "storage",
|
||||
.max_files = 5,
|
||||
.format_if_mount_failed = true,
|
||||
};
|
||||
esp_vfs_spiffs_register(&conf);
|
||||
}
|
||||
|
||||
void Enable4GModule() {
|
||||
// Make GPIO HIGH to enable the 4G module
|
||||
gpio_config_t ml307_enable_config = {
|
||||
.pin_bit_mask = (1ULL << 4),
|
||||
.mode = GPIO_MODE_OUTPUT,
|
||||
.pull_up_en = GPIO_PULLUP_DISABLE,
|
||||
.pull_down_en = GPIO_PULLDOWN_DISABLE,
|
||||
.intr_type = GPIO_INTR_DISABLE,
|
||||
};
|
||||
gpio_config(&ml307_enable_config);
|
||||
gpio_set_level(GPIO_NUM_4, 1);
|
||||
}
|
||||
|
||||
void InitializeDisplayI2c() {
|
||||
i2c_master_bus_config_t bus_config = {
|
||||
.i2c_port = I2C_NUM_0,
|
||||
.sda_io_num = DISPLAY_SDA_PIN,
|
||||
.scl_io_num = DISPLAY_SCL_PIN,
|
||||
.clk_source = I2C_CLK_SRC_DEFAULT,
|
||||
.glitch_ignore_cnt = 7,
|
||||
.intr_priority = 0,
|
||||
.trans_queue_depth = 0,
|
||||
.flags = {
|
||||
.enable_internal_pullup = 1,
|
||||
},
|
||||
};
|
||||
ESP_ERROR_CHECK(i2c_new_master_bus(&bus_config, &display_i2c_bus_));
|
||||
}
|
||||
|
||||
void InitializeCodecI2c() {
|
||||
// Initialize I2C peripheral
|
||||
i2c_master_bus_config_t i2c_bus_cfg = {
|
||||
.i2c_port = I2C_NUM_1,
|
||||
.sda_io_num = AUDIO_CODEC_I2C_SDA_PIN,
|
||||
.scl_io_num = AUDIO_CODEC_I2C_SCL_PIN,
|
||||
.clk_source = I2C_CLK_SRC_DEFAULT,
|
||||
.glitch_ignore_cnt = 7,
|
||||
.intr_priority = 0,
|
||||
.trans_queue_depth = 0,
|
||||
.flags = {
|
||||
.enable_internal_pullup = 1,
|
||||
},
|
||||
};
|
||||
ESP_ERROR_CHECK(i2c_new_master_bus(&i2c_bus_cfg, &codec_i2c_bus_));
|
||||
}
|
||||
|
||||
void InitializeButtons() {
|
||||
boot_button_.OnClick([this]() {
|
||||
Application::GetInstance().ToggleChatState();
|
||||
});
|
||||
|
||||
volume_up_button_.OnClick([this]() {
|
||||
auto codec = GetAudioCodec();
|
||||
auto volume = codec->output_volume() + 10;
|
||||
if (volume > 100) {
|
||||
volume = 100;
|
||||
}
|
||||
codec->SetOutputVolume(volume);
|
||||
GetDisplay()->ShowNotification("Volume\n" + std::to_string(volume));
|
||||
});
|
||||
|
||||
volume_up_button_.OnLongPress([this]() {
|
||||
auto codec = GetAudioCodec();
|
||||
codec->SetOutputVolume(100);
|
||||
GetDisplay()->ShowNotification("Volume\n100");
|
||||
});
|
||||
|
||||
volume_down_button_.OnClick([this]() {
|
||||
auto codec = GetAudioCodec();
|
||||
auto volume = codec->output_volume() - 10;
|
||||
if (volume < 0) {
|
||||
volume = 0;
|
||||
}
|
||||
codec->SetOutputVolume(volume);
|
||||
GetDisplay()->ShowNotification("Volume\n" + std::to_string(volume));
|
||||
});
|
||||
|
||||
volume_down_button_.OnLongPress([this]() {
|
||||
auto codec = GetAudioCodec();
|
||||
codec->SetOutputVolume(0);
|
||||
GetDisplay()->ShowNotification("Volume\n0");
|
||||
});
|
||||
}
|
||||
|
||||
public:
|
||||
KevinBoxBoard() : Ml307Board(ML307_TX_PIN, ML307_RX_PIN, 4096),
|
||||
boot_button_(BOOT_BUTTON_GPIO),
|
||||
volume_up_button_(VOLUME_UP_BUTTON_GPIO),
|
||||
volume_down_button_(VOLUME_DOWN_BUTTON_GPIO) {
|
||||
}
|
||||
|
||||
virtual void Initialize() override {
|
||||
ESP_LOGI(TAG, "Initializing KevinBoxBoard");
|
||||
InitializeDisplayI2c();
|
||||
InitializeCodecI2c();
|
||||
axp2101_.Initialize(codec_i2c_bus_, AXP2101_I2C_ADDR);
|
||||
|
||||
MountStorage();
|
||||
Enable4GModule();
|
||||
|
||||
InitializeButtons();
|
||||
|
||||
Ml307Board::Initialize();
|
||||
}
|
||||
|
||||
virtual Led* GetBuiltinLed() override {
|
||||
static Led led(BUILTIN_LED_GPIO);
|
||||
return &led;
|
||||
}
|
||||
|
||||
virtual AudioCodec* GetAudioCodec() override {
|
||||
static BoxAudioCodec audio_codec(codec_i2c_bus_, AUDIO_INPUT_SAMPLE_RATE, AUDIO_OUTPUT_SAMPLE_RATE,
|
||||
AUDIO_I2S_GPIO_MCLK, AUDIO_I2S_GPIO_BCLK, AUDIO_I2S_GPIO_WS, AUDIO_I2S_GPIO_DOUT, AUDIO_I2S_GPIO_DIN,
|
||||
AUDIO_CODEC_PA_PIN, AUDIO_CODEC_ES8311_ADDR, AUDIO_CODEC_ES7210_ADDR, AUDIO_INPUT_REFERENCE);
|
||||
return &audio_codec;
|
||||
}
|
||||
|
||||
virtual Display* GetDisplay() override {
|
||||
static Ssd1306Display display(display_i2c_bus_, DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y);
|
||||
return &display;
|
||||
}
|
||||
|
||||
virtual bool GetBatteryLevel(int &level, bool& charging) override {
|
||||
level = axp2101_.GetBatteryLevel();
|
||||
charging = axp2101_.IsCharging();
|
||||
ESP_LOGI(TAG, "Battery level: %d, Charging: %d", level, charging);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
DECLARE_BOARD(KevinBoxBoard);
|
||||
@ -6,6 +6,8 @@
|
||||
#include <ml307_http.h>
|
||||
#include <ml307_ssl_transport.h>
|
||||
#include <web_socket.h>
|
||||
#include <ml307_mqtt.h>
|
||||
#include <ml307_udp.h>
|
||||
|
||||
static const char *TAG = "Ml307Board";
|
||||
|
||||
@ -83,6 +85,14 @@ WebSocket* Ml307Board::CreateWebSocket() {
|
||||
return new WebSocket(new Ml307SslTransport(modem_, 0));
|
||||
}
|
||||
|
||||
Mqtt* Ml307Board::CreateMqtt() {
|
||||
return new Ml307Mqtt(modem_, 0);
|
||||
}
|
||||
|
||||
Udp* Ml307Board::CreateUdp() {
|
||||
return new Ml307Udp(modem_, 0);
|
||||
}
|
||||
|
||||
bool Ml307Board::GetNetworkState(std::string& network_name, int& signal_quality, std::string& signal_quality_text) {
|
||||
if (!modem_.network_ready()) {
|
||||
return false;
|
||||
@ -96,16 +106,11 @@ bool Ml307Board::GetNetworkState(std::string& network_name, int& signal_quality,
|
||||
std::string Ml307Board::GetBoardJson() {
|
||||
// Set the board type for OTA
|
||||
std::string board_type = BOARD_TYPE;
|
||||
std::string module_name = modem_.GetModuleName();
|
||||
std::string carrier_name = modem_.GetCarrierName();
|
||||
std::string imei = modem_.GetImei();
|
||||
std::string iccid = modem_.GetIccid();
|
||||
int csq = modem_.GetCsq();
|
||||
std::string board_json = std::string("{\"type\":\"" + board_type + "\",");
|
||||
board_json += "\"revision\":\"" + module_name + "\",";
|
||||
board_json += "\"carrier\":\"" + carrier_name + "\",";
|
||||
board_json += "\"csq\":\"" + std::to_string(csq) + "\",";
|
||||
board_json += "\"imei\":\"" + imei + "\",";
|
||||
board_json += "\"iccid\":\"" + iccid + "\"}";
|
||||
board_json += "\"revision\":\"" + modem_.GetModuleName() + "\",";
|
||||
board_json += "\"carrier\":\"" + modem_.GetCarrierName() + "\",";
|
||||
board_json += "\"csq\":\"" + std::to_string(modem_.GetCsq()) + "\",";
|
||||
board_json += "\"imei\":\"" + modem_.GetImei() + "\",";
|
||||
board_json += "\"iccid\":\"" + modem_.GetIccid() + "\"}";
|
||||
return board_json;
|
||||
}
|
||||
|
||||
@ -17,6 +17,8 @@ public:
|
||||
virtual void StartNetwork() override;
|
||||
virtual Http* CreateHttp() override;
|
||||
virtual WebSocket* CreateWebSocket() override;
|
||||
virtual Mqtt* CreateMqtt() override;
|
||||
virtual Udp* CreateUdp() override;
|
||||
virtual bool GetNetworkState(std::string& network_name, int& signal_quality, std::string& signal_quality_text) override;
|
||||
};
|
||||
|
||||
|
||||
@ -5,6 +5,8 @@
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/task.h>
|
||||
#include <esp_http.h>
|
||||
#include <esp_mqtt.h>
|
||||
#include <esp_udp.h>
|
||||
#include <tcp_transport.h>
|
||||
#include <tls_transport.h>
|
||||
#include <web_socket.h>
|
||||
@ -39,12 +41,15 @@ void WifiBoard::StartNetwork() {
|
||||
display->SetText(std::string("Connect to WiFi\n") + wifi_station.GetSsid());
|
||||
wifi_station.Start();
|
||||
if (!wifi_station.IsConnected()) {
|
||||
application.Alert("Info", "Configuring WiFi");
|
||||
builtin_led->SetBlue();
|
||||
builtin_led->Blink(1000, 500);
|
||||
auto& wifi_ap = WifiConfigurationAp::GetInstance();
|
||||
wifi_ap.SetSsidPrefix("Xiaozhi");
|
||||
wifi_ap.Start();
|
||||
// 播报配置 WiFi 的提示
|
||||
application.Alert("Info", "Configuring WiFi");
|
||||
// 显示 WiFi 配置 AP 的 SSID 和 Web 服务器 URL
|
||||
display->SetText(wifi_ap.GetSsid() + "\n" + wifi_ap.GetWebServerUrl());
|
||||
// Wait forever until reset after configuration
|
||||
while (true) {
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
@ -69,6 +74,14 @@ WebSocket* WifiBoard::CreateWebSocket() {
|
||||
}
|
||||
}
|
||||
|
||||
Mqtt* WifiBoard::CreateMqtt() {
|
||||
return new EspMqtt();
|
||||
}
|
||||
|
||||
Udp* WifiBoard::CreateUdp() {
|
||||
return new EspUdp();
|
||||
}
|
||||
|
||||
bool WifiBoard::GetNetworkState(std::string& network_name, int& signal_quality, std::string& signal_quality_text) {
|
||||
if (wifi_config_mode_) {
|
||||
auto& wifi_ap = WifiConfigurationAp::GetInstance();
|
||||
|
||||
@ -14,6 +14,8 @@ public:
|
||||
virtual void StartNetwork() override;
|
||||
virtual Http* CreateHttp() override;
|
||||
virtual WebSocket* CreateWebSocket() override;
|
||||
virtual Mqtt* CreateMqtt() override;
|
||||
virtual Udp* CreateUdp() override;
|
||||
virtual bool GetNetworkState(std::string& network_name, int& signal_quality, std::string& signal_quality_text) override;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user