File indexing completed on 2025-02-16 06:40:21
0001 /* 0002 SPDX-FileCopyrightText: 2022 Jasem Mutlaq <mutlaqja@ikarustech.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include <basedevice.h> 0008 #include "indilightbox.h" 0009 0010 namespace ISD 0011 { 0012 0013 bool LightBox::isLightOn() 0014 { 0015 auto lightSP = getSwitch("FLAT_LIGHT_CONTROL"); 0016 if (!lightSP) 0017 return false; 0018 0019 auto lightON = lightSP->findWidgetByName("FLAT_LIGHT_ON"); 0020 if (!lightON) 0021 return false; 0022 0023 return lightON->getState() == ISS_ON; 0024 } 0025 0026 bool LightBox::setLightEnabled(bool enable) 0027 { 0028 auto lightSP = getSwitch("FLAT_LIGHT_CONTROL"); 0029 0030 if (!lightSP) 0031 return false; 0032 0033 auto lightON = lightSP->findWidgetByName("FLAT_LIGHT_ON"); 0034 auto lightOFF = lightSP->findWidgetByName("FLAT_LIGHT_OFF"); 0035 0036 if (!lightON || !lightOFF) 0037 return false; 0038 0039 lightSP->reset(); 0040 0041 if (enable) 0042 lightON->setState(ISS_ON); 0043 else 0044 lightOFF->setState(ISS_ON); 0045 0046 sendNewProperty(lightSP); 0047 0048 return true; 0049 } 0050 0051 bool LightBox::setBrightness(uint16_t val) 0052 { 0053 auto lightIntensity = getNumber("FLAT_LIGHT_INTENSITY"); 0054 if (!lightIntensity) 0055 return false; 0056 0057 lightIntensity->at(0)->setValue(val); 0058 sendNewProperty(lightIntensity); 0059 return true; 0060 } 0061 0062 0063 }