From 87358da3ced1063fb698fe375075c9791089a29c Mon Sep 17 00:00:00 2001 From: Reine <92717560+reineabs@users.noreply.github.com> Date: Thu, 2 May 2024 13:40:06 +0200 Subject: [PATCH 1/2] =?UTF-8?q?Ajout=20des=20commandes=20pour=20allumer=20?= =?UTF-8?q?et=20=C3=A9teindre=20la=20batterie?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/ajax/luna.ajax.php | 1 - core/class/luna.class.php | 72 +++++++++++++++++++++++++++++++++++++++ desktop/js/luna.js | 1 - desktop/php/luna.php | 3 +- docs/fr_FR/changelog.md | 4 +++ 5 files changed, 77 insertions(+), 4 deletions(-) diff --git a/core/ajax/luna.ajax.php b/core/ajax/luna.ajax.php index 6ed5500..e68ebfc 100644 --- a/core/ajax/luna.ajax.php +++ b/core/ajax/luna.ajax.php @@ -124,7 +124,6 @@ ajax::success(luna::configurationPortSms()); } - throw new Exception(__('Aucune méthode correspondante à : ', __FILE__) . init('action')); /* * *********Catch exeption*************** */ } catch (Exception $e) { diff --git a/core/class/luna.class.php b/core/class/luna.class.php index a452713..74721f6 100644 --- a/core/class/luna.class.php +++ b/core/class/luna.class.php @@ -238,6 +238,7 @@ public static function cron5() { $ssid2 = $luna->getConfiguration('wifi2Ssid', null); $luna->checkAndUpdateCmd('battery', luna::batteryPourcentage()); $luna->checkAndUpdateCmd('status', luna::batteryStatusLuna()); + $luna->checkAndUpdateCmd('activationBattery', luna::activationBattery()); $luna->checkAndUpdateCmd('tempBattery', luna::batteryTemp()); $luna->checkAndUpdateCmd('ssid', $luna->getConfiguration('wifi1Ssid')); if ($ssid != null) { @@ -542,6 +543,26 @@ public static function batteryPresent() { return exec('sudo cat /sys/class/power_supply/bq27546-0/present'); } + public static function activationBattery() { + $battery = exec('sudo i2cget -f -y 0 0x6a 0x09'); + if($battery == '0x44') { + // ON + return 1; + } + else if($battery == '0x20') { + // OFF + return 0; + } + } + + public static function onBattery() { + return exec('sudo i2cset -f -y 0 0x6a 0x09 0x44'); + } + + public static function offBattery() { + return exec('sudo i2cset -f -y 0 0x6a 0x09 0x20'); + } + /* ----- FIN BATTERY ----- */ /* root etc Patch */ @@ -1211,6 +1232,49 @@ public function postSave() { $tempBattery->setType('info'); $tempBattery->setSubType('string'); $tempBattery->save(); + + $activationBattery = $this->getCmd(null, 'activationBattery'); + if (!is_object($activationBattery)) { + $activationBattery = new lunaCmd(); + $activationBattery->setName(__('Etat batterie', __FILE__)); + $activationBattery->setOrder(1); + } + $activationBattery->setEqLogic_id($this->getId()); + $activationBattery->setLogicalId('activationBattery'); + $activationBattery->setType('info'); + $activationBattery->setSubType('binary'); + $activationBattery->save(); + $activationBatteryId = $activationBattery->getId(); + + $onBattery = $this->getCmd(null, 'onBattery'); + if (!is_object($onBattery)) { + $onBattery = new lunaCmd(); + $onBattery->setName(__('Allumer la batterie', __FILE__)); + $onBattery->setOrder(1); + } + $onBattery->setIsVisible(1); + $onBattery->setEqLogic_id($this->getId()); + $onBattery->setLogicalId('onBattery'); + $onBattery->setType('action'); + $onBattery->setSubType('other'); + $onBattery->save(); + + + $offBattery = $this->getCmd(null, 'offBattery'); + if (!is_object($offBattery)) { + $offBattery = new lunaCmd(); + $offBattery->setName(__('Eteindre la batterie', __FILE__)); + $offBattery->setOrder(1); + } + $offBattery->setIsVisible(1); + $offBattery->setEqLogic_id($this->getId()); + $offBattery->setLogicalId('offBattery'); + $offBattery->setType('action'); + $offBattery->setSubType('other'); + $offBattery->save(); + + + } public function postAjax() { @@ -1241,6 +1305,14 @@ public function execute($_options = array()) { case 'dsled': luna::dsLed($_options['select']); break; + case 'onBattery': + luna::onBattery(); + break; + case 'offBattery': + luna::offBattery(); + break; + default: + break; } luna::cron5($eqLogic->getId()); } diff --git a/desktop/js/luna.js b/desktop/js/luna.js index 3d689d0..85a7c4e 100644 --- a/desktop/js/luna.js +++ b/desktop/js/luna.js @@ -268,7 +268,6 @@ $('#saveLuna').off('click').on('click', function() { }else{ location.reload(); } - } }) jeedom.eqLogic.save({ diff --git a/desktop/php/luna.php b/desktop/php/luna.php index 0783b4a..341feab 100644 --- a/desktop/php/luna.php +++ b/desktop/php/luna.php @@ -224,8 +224,7 @@ ?>