Browse Source

add zlight ctrl service

master
zhaohe 2 years ago
parent
commit
5b3ffc280c
  1. 45
      components/light_ctrl/zlight_ctrl_service.cpp
  2. 41
      components/light_ctrl/zlight_ctrl_service.hpp

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

41
components/light_ctrl/zlight_ctrl_service.hpp

@ -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
Loading…
Cancel
Save