diff --git a/docs/en/api/power.md b/docs/en/api/power.md index a0801bf2..ca886bc3 100644 --- a/docs/en/api/power.md +++ b/docs/en/api/power.md @@ -4,11 +4,21 @@ **Syntax:** -bool setPowerBoostKeepOn(bool en); +bool setPowerBoostKeepOn(bool en) **Description:** -This function sets enable/disable power mode. +This function sets/unsets always boost output mode. + +**Function argument** + +true: Turn on always boost output mode, +false: Turn off always boost output mode. + +**Function return value** + +true: Control success, +false: Control failure. **Definition:** @@ -26,29 +36,83 @@ bool setPowerBoostKeepOn(bool en){ Wire.beginTransmission(IP5306_ADDR); Wire.write(IP5306_REG_SYS_CTL0); if (en) Wire.write(data | BOOST_OUT_BIT); - else Wire.write(data &(~BOOST_OUT_BIT)); + else Wire.write(data &(~BOOST_OUT_BIT)); + Wire.endTransmission(); + return true; + } + return false; +} +``` + +## setKeepLightLoad() + +**Syntax:** + +bool setKeepLightLoad(bool en) + +**Description:** + +This function sets/unsets to disable the automatic shutdown. + +**Function argument** + +true: When the current is too small, IP5306 will *not* automatically shutdown, +false: When the current is too small, IP5306 will automatically shutdown. + +**Function return value** + +true: Control success, +false: Control failure. + + +**Definition:** + +```arduino +bool setKeepLightLoad(bool en) { + uint8_t data; + Wire.beginTransmission(IP5306_ADDR); + Wire.write(IP5306_REG_SYS_CTL0); + Wire.endTransmission(); + + if(Wire.requestFrom(IP5306_ADDR, 1)) + { + data = Wire.read(); + + Wire.beginTransmission(IP5306_ADDR); + Wire.write(IP5306_REG_SYS_CTL0); + if (!en) Wire.write(data | LIGHT_LOAD_BIT); + else Wire.write(data &(~LIGHT_LOAD_BIT)); Wire.endTransmission(); return true; } return false; } -#endif ``` ## setCharge() **Syntax:** -bool setCharge(bool en); +bool setCharge(bool en) **Description:** -This function sets enable/disable charge mode. +This function sets/unsets charge mode. When the battery is fully charged, try set charge enable->disable->enable, It can be recharged. + +**Function argument** + +true: Start charging, +false: Stop charging. + +**Function return value** + +true: Control success, +false: Control failure. **Definition:** ```arduino -bool POWER::setCharge(bool en){ +bool setCharge(bool en){ uint8_t data; Wire.beginTransmission(IP5306_ADDR); Wire.write(IP5306_REG_SYS_CTL0); @@ -61,7 +125,7 @@ bool POWER::setCharge(bool en){ Wire.beginTransmission(IP5306_ADDR); Wire.write(IP5306_REG_SYS_CTL0); if (en) Wire.write(data | CHARGE_OUT_BIT); - else Wire.write(data &(~CHARGE_OUT_BIT)); + else Wire.write(data &(~CHARGE_OUT_BIT)); Wire.endTransmission(); return true; } @@ -73,11 +137,20 @@ bool POWER::setCharge(bool en){ **Syntax:** -bool isChargeFull(bool en); +bool isChargeFull() **Description:** -This function check battery level. +This function checks if the battery is fully charged. + +**Function argument** + +No argument. + +**Function return value** + +true: Full charged, +false: Not full charged. **Definition:** @@ -101,11 +174,20 @@ bool isChargeFull(){ **Syntax:** -bool canControl(); +bool canControl() **Description:** -This function checks the existence of the battery controller +This function checks the existence of the battery controller on I2C. + +**Function argument** + +No argument. + +**Function return value** + +true: Battery controller is found, +false: Battery controller is not found. **Definition:** @@ -122,11 +204,20 @@ bool canControl(){ **Syntax:** -bool isCharging(){ +bool isCharging() **Description:** -This function checks the state of the charge +This function checks the state of the charging. + +**Function argument** + +No argument. + +**Function return value** + +true: In charging, +false: Not in charging. **Definition:** @@ -145,17 +236,55 @@ bool isCharging(){ return false; } ``` +## getBatteryLevel() + +**Syntax:** + +bool getBatteryLevel() + +**Description:** + +This function gets the battery level. + +**Function argument** + +No argument. + +**Function return value** + +Battery remaining percentage. (0-100 %) +Returns -1 if it can not communicate with the controller. + + +**Definition:** + +```arduino +int8_t getBatteryLevel() { + Wire.beginTransmission(0x75); + Wire.write(0x78); + if (Wire.endTransmission(false) == 0 && Wire.requestFrom(0x75, 1)) { + switch (Wire.read() & 0xF0) { + case 0xE0: return 25; + case 0xC0: return 50; + case 0x80: return 75; + case 0x00: return 100; + default: return 0; + } + } + return -1; +} +``` ## setWakeupButton() **Syntax:** -void setWakeupButton(uint8_t button){ +void setWakeupButton(uint8_t button) **Description:** -This function set the port to exit sleep +This function sets the port to exit sleep mode. **Definition:** @@ -173,31 +302,31 @@ void setWakeupButton(uint8_t button) { **Description:** -This function reset the CPU. +This function resets the CPU. **Definition:** ```arduino -void POWER::reset() { +void reset() { esp_restart(); } ``` - + ## deepSleep() @@ -228,7 +357,7 @@ bool boostMode(bool en){ **Description:** -This function shifts to deep sleep mode +This function shifts to deep sleep mode. **Definition:** @@ -252,4 +381,4 @@ void deepSleep(){ } esp_deep_sleep_start(); } -``` \ No newline at end of file +``` diff --git a/docs/ja/api/power.md b/docs/ja/api/power.md index 56334387..b78ac331 100644 --- a/docs/ja/api/power.md +++ b/docs/ja/api/power.md @@ -4,13 +4,23 @@ **構文:** -bool setPowerBoostKeepOn(bool en); +bool setPowerBoostKeepOn(bool en) **説明:** 電源供給状態を設定します。 -**定義:** +**引数** + +true: 常時供給モードon。 +false: 常時供給モードoff。 + +**戻り値** + +true: 制御成功。 +false: 制御失敗。 + +**定義** ```arduino bool setPowerBoostKeepOn(bool en){ @@ -26,24 +36,78 @@ bool setPowerBoostKeepOn(bool en){ Wire.beginTransmission(IP5306_ADDR); Wire.write(IP5306_REG_SYS_CTL0); if (en) Wire.write(data | BOOST_OUT_BIT); - else Wire.write(data &(~BOOST_OUT_BIT)); + else Wire.write(data &(~BOOST_OUT_BIT)); + Wire.endTransmission(); + return true; + } + return false; +} +``` + +## setKeepLightLoad() + +**構文:** + +bool setKeepLightLoad(bool en) + +**説明:** + +自動シャットダウン無効化機能を設定します。 + +**引数** + +true: 軽負荷時に自動シャットダウンしません。 +false: 軽負荷時に自動シャットダウンします。 + +**戻り値** + +true: 制御成功。 +false: 制御失敗。 + +**定義:** + +```arduino +bool setKeepLightLoad(bool en) { + uint8_t data; + Wire.beginTransmission(IP5306_ADDR); + Wire.write(IP5306_REG_SYS_CTL0); + Wire.endTransmission(); + + if(Wire.requestFrom(IP5306_ADDR, 1)) + { + data = Wire.read(); + + Wire.beginTransmission(IP5306_ADDR); + Wire.write(IP5306_REG_SYS_CTL0); + if (!en) Wire.write(data | LIGHT_LOAD_BIT); + else Wire.write(data &(~LIGHT_LOAD_BIT)); Wire.endTransmission(); return true; } return false; } -#endif ``` ## setCharge() **構文:** -bool setCharge(bool en); +bool setCharge(bool en) **説明:** -充電状態を設定します。 +充電制御状態を指示します。 +満充電時は、有効→無効→有効とセットすることで再充電ができます。 + +**引数** + +true: 充電開始指示。 +false: 充電中止指示。 + +**戻り値** + +true: 制御成功。 +false: 制御失敗。 **定義:** @@ -61,7 +125,7 @@ bool POWER::setCharge(bool en){ Wire.beginTransmission(IP5306_ADDR); Wire.write(IP5306_REG_SYS_CTL0); if (en) Wire.write(data | CHARGE_OUT_BIT); - else Wire.write(data &(~CHARGE_OUT_BIT)); + else Wire.write(data &(~CHARGE_OUT_BIT)); Wire.endTransmission(); return true; } @@ -70,14 +134,22 @@ bool POWER::setCharge(bool en){ ``` ## isChargeFull() - **構文:** -bool isChargeFull(bool en); +bool isChargeFull() **説明:** -満充電かを判定します +満充電かを判断します。 + +**引数** + +なし。 + +**戻り値** + +true: 満充電。 +false: 満充電ではない。 **定義:** @@ -101,11 +173,20 @@ bool isChargeFull(){ **構文:** -bool canControl(); +bool canControl() **説明:** -電源コントローラが使用可能かを判断します +電源コントローラが制御可能かどうかを判断します。 + +**引数** + +なし。 + +**戻り値** + +true: 電源コントローラーを制御可能。 +false: 電源コントローラーを制御不可能。 **定義:** @@ -122,11 +203,20 @@ bool canControl(){ **構文:** -bool isCharging(){ +bool isCharging() **説明:** -充電中かを返答します +充電状態かどうかを判断します。 + +**引数** + +なし。 + +**戻り値** + +true: 充電中。 +false: 充電中ではない。 **定義:** @@ -146,16 +236,53 @@ bool isCharging(){ } ``` +## getBatteryLevel() + +**構文:** + +bool getBatteryLevel() + +**説明:** + +バッテリー残量(%)を返します。 + +**引数** + +なし + +**戻り値** + +バッテリーレベルを(0-100)の範囲で返します。(単位:%) +もし残量が確認できる状態になければ-1を返します。 + +**定義:** + +```arduino +int8_t getBatteryLevel() { + Wire.beginTransmission(0x75); + Wire.write(0x78); + if (Wire.endTransmission(false) == 0 && Wire.requestFrom(0x75, 1)) { + switch (Wire.read() & 0xF0) { + case 0xE0: return 25; + case 0xC0: return 50; + case 0x80: return 75; + case 0x00: return 100; + default: return 0; + } + } + return -1; +} +``` ## setWakeupButton() **構文:** -void setWakeupButton(uint8_t button){ +void setWakeupButton(uint8_t button) **説明:** -スリープ復帰信号ポートを設定します +スリープ復帰信号ポートを設定します。 **定義:** @@ -169,39 +296,39 @@ void setWakeupButton(uint8_t button) { **構文:** -void reset() +void reset(); **説明:** -CPUをリセットします +CPUをリセットします。 **定義:** ```arduino -void POWER::reset() { +void reset() { esp_restart(); } ``` - + ## deepSleep() @@ -228,7 +355,7 @@ bool boostMode(bool en){ **説明:** -省エネモードに移行します +deep sleepモードに移行します。 **定義:** @@ -252,4 +379,4 @@ void deepSleep(){ } esp_deep_sleep_start(); } -``` \ No newline at end of file +``` diff --git a/docs/zh_CN/api/power.md b/docs/zh_CN/api/power.md index df774a8c..e31b8f36 100644 --- a/docs/zh_CN/api/power.md +++ b/docs/zh_CN/api/power.md @@ -4,11 +4,22 @@ **函数原型:** -bool setPowerBoostKeepOn(bool en); +bool setPowerBoostKeepOn(bool en) **功能:BOOST输出常开功能** -**函数实现:** +**参数** + +true: 始终供应 +false: 通常關閉 + +**返回值** + +true: 控制成功 +false: 控制失败 + + +**函数实现** ```arduino bool setPowerBoostKeepOn(bool en){ @@ -33,15 +44,69 @@ bool setPowerBoostKeepOn(bool en){ #endif ``` +## setKeepLightLoad() + +**函数原型:** + +bool setKeepLightLoad(bool en) + +**功能:** + +设置自动关机功能。 + +**参数** + +true:当电流消耗低时,不会发生自动关闭 +false:电流消耗低时自动关闭 + +**返回值** + +true: 控制成功 +false: 控制失败 + +**函数实现** + +```arduino +bool setKeepLightLoad(bool en) { + uint8_t data; + Wire.beginTransmission(IP5306_ADDR); + Wire.write(IP5306_REG_SYS_CTL0); + Wire.endTransmission(); + + if(Wire.requestFrom(IP5306_ADDR, 1)) + { + data = Wire.read(); + + Wire.beginTransmission(IP5306_ADDR); + Wire.write(IP5306_REG_SYS_CTL0); + if (!en) Wire.write(data | LIGHT_LOAD_BIT); + else Wire.write(data &(~LIGHT_LOAD_BIT)); + Wire.endTransmission(); + return true; + } + return false; +} +``` + + ## setCharge() **函数原型:** -bool setCharge(bool en); +bool setCharge(bool en) **功能:设置充电状态** -**函数实现:** +true:充电开始指令 +false:充电停止指令 + +**返回值** + +true: 控制成功 +false: 控制失败 + + +**定義:** ```arduino bool POWER::setCharge(bool en){ @@ -69,9 +134,20 @@ bool POWER::setCharge(bool en){ **函数原型:** -bool isChargeFull(bool en); +bool isChargeFull() -**功能:确认完全充电** +**説明:** + +确认完全充电. + +**引数** + +なし. + +**戻り値** + +true:完全充电 +false:没有完全充电 **函数实现:** @@ -95,9 +171,20 @@ bool isChargeFull(){ **函数原型:** -bool canControl(); +bool canControl() -**功能:确认可以使用电源控制器** +**功能:** + +确认完全充电 + +**参数** + +无. + +**返回值** + +true: 电源控制器发现 +false:找不到电源控制器 **函数实现:** @@ -114,10 +201,19 @@ bool canControl(){ **函数原型:** -bool isCharging(){ +bool isCharging() **功能:确认是否正在充电** +**参数** + +无. + +**返回值** + +true: 在充电过程中 +false: 不收费 + **函数实现:** ```arduino @@ -135,13 +231,51 @@ bool isCharging(){ return false; } ``` +## getBatteryLevel() + +**函数原型:** + +bool getBatteryLevel() + +**功能:** + +返回电池电量 + +**参数** + +无 + +**返回值** + +返回0到100范围内的电池电量.(单位:%) +如果无法检查剩余金额,则返回-1 + + +**函数实现:** + +```arduino +int8_t getBatteryLevel() { + Wire.beginTransmission(0x75); + Wire.write(0x78); + if (Wire.endTransmission(false) == 0 && Wire.requestFrom(0x75, 1)) { + switch (Wire.read() & 0xF0) { + case 0xE0: return 25; + case 0xC0: return 50; + case 0x80: return 75; + case 0x00: return 100; + default: return 0; + } + } + return -1; +} +``` ## setWakeupButton() **函数原型:** -void setWakeupButton(uint8_t button){ +void setWakeupButton(uint8_t button) **功能:设置睡眠返回端口** @@ -164,24 +298,24 @@ void setWakeupButton(uint8_t button) { **函数实现:** ```arduino -void POWER::reset() { +void reset() { esp_restart(); } ``` - -## boostMode() + ## deepSleep() @@ -234,4 +368,4 @@ void deepSleep(){ } esp_deep_sleep_start(); } -``` \ No newline at end of file +```