|
@ -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); |
|
|
|
|
|
} |
|
|
|
|
|
} |