2 changed files with 86 additions and 0 deletions
@ -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); |
|||
} |
|||
} |
@ -0,0 +1,41 @@ |
|||
#pragma once
|
|||
#include <stdint.h>
|
|||
|
|||
#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
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue