move all hardware init to boards

This commit is contained in:
Terrence
2024-11-06 06:18:56 +08:00
parent 55ff4e1f74
commit 3575448373
34 changed files with 1150 additions and 669 deletions

View File

@@ -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() {