forked from xiaozhi/xiaozhi-esp32
move all hardware init to boards
This commit is contained in:
@@ -27,13 +27,32 @@ static std::string csq_to_string(int csq) {
|
||||
}
|
||||
|
||||
|
||||
Ml307Board::Ml307Board() : modem_(ML307_TX_PIN, ML307_RX_PIN, 4096) {
|
||||
Ml307Board::Ml307Board(gpio_num_t tx_pin, gpio_num_t rx_pin, size_t rx_buffer_size) : modem_(tx_pin, rx_pin, rx_buffer_size) {
|
||||
}
|
||||
|
||||
void Ml307Board::StartNetwork() {
|
||||
auto display = Board::GetInstance().GetDisplay();
|
||||
display->SetText(std::string("Starting modem"));
|
||||
modem_.SetDebug(false);
|
||||
modem_.SetBaudRate(921600);
|
||||
|
||||
auto& application = Application::GetInstance();
|
||||
auto& display = application.GetDisplay();
|
||||
display.SetText(std::string("Wait for network\n"));
|
||||
// If low power, the material ready event will be triggered by the modem because of a reset
|
||||
modem_.OnMaterialReady([this, &application]() {
|
||||
ESP_LOGI(TAG, "ML307 material ready");
|
||||
application.Schedule([this, &application]() {
|
||||
application.SetChatState(kChatStateIdle);
|
||||
WaitForNetworkReady();
|
||||
});
|
||||
});
|
||||
|
||||
WaitForNetworkReady();
|
||||
}
|
||||
|
||||
void Ml307Board::WaitForNetworkReady() {
|
||||
auto& application = Application::GetInstance();
|
||||
auto display = Board::GetInstance().GetDisplay();
|
||||
display->SetText(std::string("Wait for network\n"));
|
||||
int result = modem_.WaitForNetworkReady();
|
||||
if (result == -1) {
|
||||
application.Alert("Error", "PIN is not ready");
|
||||
@@ -52,26 +71,8 @@ void Ml307Board::StartNetwork() {
|
||||
ESP_LOGI(TAG, "ML307 ICCID: %s", iccid.c_str());
|
||||
}
|
||||
|
||||
void Ml307Board::StartModem() {
|
||||
auto& display = Application::GetInstance().GetDisplay();
|
||||
display.SetText(std::string("Starting modem"));
|
||||
modem_.SetDebug(false);
|
||||
modem_.SetBaudRate(921600);
|
||||
|
||||
auto& application = Application::GetInstance();
|
||||
// If low power, the material ready event will be triggered by the modem because of a reset
|
||||
modem_.OnMaterialReady([this, &application]() {
|
||||
ESP_LOGI(TAG, "ML307 material ready");
|
||||
application.Schedule([this, &application]() {
|
||||
application.SetChatState(kChatStateIdle);
|
||||
StartNetwork();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
void Ml307Board::Initialize() {
|
||||
ESP_LOGI(TAG, "Initializing Ml307Board");
|
||||
StartModem();
|
||||
}
|
||||
|
||||
Http* Ml307Board::CreateHttp() {
|
||||
|
||||
Reference in New Issue
Block a user