From 5b3ffc280c0a0c37e52714254e66add1524a6783 Mon Sep 17 00:00:00 2001 From: zhaohe Date: Sat, 26 Aug 2023 11:54:26 +0800 Subject: [PATCH] add zlight ctrl service --- components/light_ctrl/zlight_ctrl_service.cpp | 45 +++++++++++++++++++++++++++ components/light_ctrl/zlight_ctrl_service.hpp | 41 ++++++++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 components/light_ctrl/zlight_ctrl_service.cpp create mode 100644 components/light_ctrl/zlight_ctrl_service.hpp diff --git a/components/light_ctrl/zlight_ctrl_service.cpp b/components/light_ctrl/zlight_ctrl_service.cpp new file mode 100644 index 0000000..4d3f932 --- /dev/null +++ b/components/light_ctrl/zlight_ctrl_service.cpp @@ -0,0 +1,45 @@ +#include "zlight_ctrl_service.hpp" + +using namespace iflytop; +using namespace std; + +/******************************************************************************* + * ZLight * + *******************************************************************************/ +ZLight::ZLight(int id, Pin_t pin, ZGPIO::GPIOMode_t mode, bool mirror) { + this->id = id; + this->pin = pin; + this->mode = mode; + this->mirror = mirror; +} +ZLight::~ZLight() {} + +void ZLight::init() { gpio.initAsOutput(pin, mode, mirror, false); } +void ZLight::setState(bool state) { gpio.setState(state); } + +/******************************************************************************* + * ZLightCtrlService * + *******************************************************************************/ +void ZLightCtrlService::initialize(ZLight* light, int numLight) { + m_light = light; + m_numLight = numLight; + + for (int i = 0; i < m_numLight; i++) { + m_light[i].init(); + } +} +ZLight* ZLightCtrlService::findLightById(int id) { + for (int i = 0; i < m_numLight; i++) { + if (m_light[i].id == id) { + return &m_light[i]; + } + } + return NULL; +} +void ZLightCtrlService::periodicJob() {} +void ZLightCtrlService::setLightState(int id, bool state) { + ZLight* light = findLightById(id); + if (light != NULL) { + light->setState(state); + } +} diff --git a/components/light_ctrl/zlight_ctrl_service.hpp b/components/light_ctrl/zlight_ctrl_service.hpp new file mode 100644 index 0000000..e315d1f --- /dev/null +++ b/components/light_ctrl/zlight_ctrl_service.hpp @@ -0,0 +1,41 @@ +#pragma once +#include + +#include "sdk/os/zos.hpp" +namespace iflytop { +using namespace std; +class LightCtrlService; + +class ZLight { + public: + int id; + Pin_t pin; + ZGPIO::GPIOMode_t mode; + bool mirror; + + ZGPIO gpio; + + ZLight(int id, Pin_t pin, ZGPIO::GPIOMode_t mode, bool mirror); + ~ZLight(); + + void init(); + void setState(bool state); +}; + +class ZLightCtrlService { + private: + ZLight* m_light; + int m_numLight; + + public: + ZLightCtrlService(){}; + ~ZLightCtrlService(){}; + + void initialize(ZLight* light, int numLight); + + void setLightState(int id, bool state); + ZLight* findLightById(int id); + void periodicJob(); +}; + +} // namespace iflytop \ No newline at end of file