Add an app console triggered shutdown
This commit is contained in:
@@ -483,7 +483,7 @@ void RegisterBtList() {
|
||||
}
|
||||
|
||||
int CmdSamd(int argc, char** argv) {
|
||||
static const std::string usage = "usage: samd [flash|charge]";
|
||||
static const std::string usage = "usage: samd [flash|charge|off]";
|
||||
if (argc != 2) {
|
||||
std::cout << usage << std::endl;
|
||||
return 1;
|
||||
@@ -493,7 +493,6 @@ int CmdSamd(int argc, char** argv) {
|
||||
if (cmd == "flash") {
|
||||
std::cout << "resetting samd..." << std::endl;
|
||||
vTaskDelay(pdMS_TO_TICKS(5));
|
||||
|
||||
AppConsole::sSamd->ResetToFlashSamd();
|
||||
} else if (cmd == "charge") {
|
||||
auto res = AppConsole::sSamd->GetChargeStatus();
|
||||
@@ -521,6 +520,10 @@ int CmdSamd(int argc, char** argv) {
|
||||
} else {
|
||||
std::cout << "unknown" << std::endl;
|
||||
}
|
||||
} else if (cmd == "off") {
|
||||
std::cout << "bye !!!" << std::endl;
|
||||
vTaskDelay(pdMS_TO_TICKS(5));
|
||||
AppConsole::sSamd->PowerDown();
|
||||
} else {
|
||||
std::cout << usage << std::endl;
|
||||
return 1;
|
||||
|
||||
@@ -52,6 +52,7 @@ class Samd {
|
||||
auto UpdateUsbStatus() -> void;
|
||||
|
||||
auto ResetToFlashSamd() -> void;
|
||||
auto PowerDown() -> void;
|
||||
|
||||
static auto CreateReadPending() -> SemaphoreHandle_t;
|
||||
|
||||
|
||||
@@ -138,6 +138,15 @@ auto Samd::ResetToFlashSamd() -> void {
|
||||
ESP_ERROR_CHECK(transaction.Execute());
|
||||
}
|
||||
|
||||
auto Samd::PowerDown() -> void {
|
||||
I2CTransaction transaction;
|
||||
transaction.start()
|
||||
.write_addr(kAddress, I2C_MASTER_WRITE)
|
||||
.write_ack(Registers::kPowerControl, 0b1)
|
||||
.stop();
|
||||
ESP_ERROR_CHECK(transaction.Execute());
|
||||
}
|
||||
|
||||
auto Samd::CreateReadPending() -> SemaphoreHandle_t {
|
||||
sReadPending = xSemaphoreCreateBinary();
|
||||
return sReadPending;
|
||||
|
||||
Reference in New Issue
Block a user