mirror of https://github.com/IoTcat/sola.git
parent
3573b7c060
commit
75e499ad84
6 changed files with 442 additions and 53 deletions
@ -0,0 +1,107 @@ |
||||
/*
|
||||
* @Author: IoTcat (https://iotcat.me)
|
||||
* @Date: 2019-08-30 13:36:43
|
||||
* @Last Modified by:
|
||||
* @Last Modified time: 2019-08-30 14:17:59 |
||||
*/ |
||||
|
||||
#ifndef __LIGHTCTL_H__ |
||||
#define __LIGHTCTL_H__ |
||||
|
||||
class LightCtl{ |
||||
public: |
||||
LightCtl(Relay* _light, LED* _led, Mode* _mode){ |
||||
light = _light; |
||||
led = _led; |
||||
mode = _mode; |
||||
_fStatus = _status; |
||||
}; |
||||
~LightCtl(){ |
||||
delete light, led, mode; |
||||
}; |
||||
|
||||
void on(){ |
||||
if(mode->isOffline()){ |
||||
if(mode->nightMode() == 0){ |
||||
light->off(); |
||||
led->star(); |
||||
} |
||||
if(mode->nightMode() == 1){ |
||||
light->on(); |
||||
led->star(); |
||||
} |
||||
if(mode->nightMode() == 2){ |
||||
light->off(); |
||||
led->on(); |
||||
} |
||||
}else{ |
||||
if(mode->nightMode() == 0){ |
||||
light->off(); |
||||
led->breath(); |
||||
} |
||||
if(mode->nightMode() == 1){ |
||||
light->on(); |
||||
led->breath(); |
||||
} |
||||
if(mode->nightMode() == 2){ |
||||
light->off(); |
||||
led->on(); |
||||
} |
||||
} |
||||
_status = true; |
||||
} |
||||
void off(){ |
||||
if(mode->isOffline()){ |
||||
if(mode->nightMode() == 0){ |
||||
light->off(); |
||||
led->star(); |
||||
} |
||||
if(mode->nightMode() == 1){ |
||||
light->off(); |
||||
led->star(); |
||||
} |
||||
if(mode->nightMode() == 2){ |
||||
light->off(); |
||||
led->star(); |
||||
} |
||||
}else{ |
||||
light->off(); |
||||
led->off(); |
||||
} |
||||
_status = false; |
||||
} |
||||
|
||||
inline const bool toggle(){ |
||||
if(_status){ |
||||
off(); |
||||
}else{ |
||||
on(); |
||||
} |
||||
return _status; |
||||
} |
||||
|
||||
inline const bool isStateChange(){ |
||||
if(_fStatus != _status){ |
||||
_fStatus = _status; |
||||
return true; |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
inline const bool getStatus(){ |
||||
return _status; |
||||
} |
||||
|
||||
private: |
||||
Relay* light; |
||||
LED* led; |
||||
Mode* mode; |
||||
bool _status, _fStatus; |
||||
|
||||
}; |
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif //__LIGHTCTL_H__
|
@ -0,0 +1,115 @@ |
||||
/*
|
||||
* @Author: IoTcat (https://iotcat.me)
|
||||
* @Date: 2019-08-30 11:14:59
|
||||
* @Last Modified by:
|
||||
* @Last Modified time: 2019-08-30 13:31:16 |
||||
*/ |
||||
|
||||
#ifndef __MODE_H__ |
||||
#define __MODE_H__ |
||||
|
||||
class Mode{ |
||||
public: |
||||
Mode() : _isNight(false), _fIsNight(false), _isAuto(true), _fIsAuto(true), \
|
||||
_isMidnight(false), _fIsMidnight(false), _isOffline(true), _fIsOffline(true){}; |
||||
~Mode(){}; |
||||
|
||||
inline void ini() const{ |
||||
} |
||||
inline void begin() const{ |
||||
this->ini(); |
||||
} |
||||
|
||||
inline void core() const{}; |
||||
inline void loop() const{ |
||||
this->core(); |
||||
}; |
||||
|
||||
inline const bool isNight() const{ |
||||
return this->_isNight; |
||||
} |
||||
inline const bool isNight(const bool& state){ |
||||
this->_isNight = state; |
||||
return this->isNight(); |
||||
} |
||||
inline const bool isNightChange(){ |
||||
if(this->_isNight != this->_fIsNight){ |
||||
this->_fIsNight = this->_isNight; |
||||
return true; |
||||
}else{ |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
inline const bool isAuto() const{ |
||||
return this->_isAuto; |
||||
} |
||||
inline const bool isAuto(const bool& state){ |
||||
this->_isAuto = state; |
||||
return this->isAuto(); |
||||
} |
||||
inline const bool isAutoChange(){ |
||||
if(this->_isAuto != this->_fIsAuto){ |
||||
this->_fIsAuto = this->_isAuto; |
||||
return true; |
||||
}else{ |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
inline const bool isMidnight() const{ |
||||
return this->_isMidnight; |
||||
} |
||||
inline const bool isMidnight(const bool& state){ |
||||
this->_isMidnight = state; |
||||
return this->isMidnight(); |
||||
} |
||||
inline const bool isMidnightChange(){ |
||||
if(this->_isMidnight != this->_fIsMidnight){ |
||||
this->_fIsMidnight = this->_isMidnight; |
||||
return true; |
||||
}else{ |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
inline const bool isOffline() const{ |
||||
return this->_isOffline; |
||||
} |
||||
inline const bool isOffline(const bool& state){ |
||||
this->_isOffline = state; |
||||
return this->isOffline(); |
||||
} |
||||
inline const bool isOfflineChange(){ |
||||
if(this->_isOffline != this->_fIsOffline){ |
||||
this->_fIsOffline = this->_isOffline; |
||||
return true; |
||||
}else{ |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
inline const unsigned short nightMode(){ |
||||
if(!this->isNight() && !this->isMidnight()){ |
||||
return 0; |
||||
} |
||||
if(this->isNight() && !this->isMidnight()){ |
||||
return 1; |
||||
} |
||||
if(this->isMidnight()){ |
||||
return 2; |
||||
} |
||||
return 0; |
||||
} |
||||
|
||||
|
||||
private: |
||||
bool _isNight, _isAuto, _isMidnight, _isOffline; |
||||
bool _fIsNight, _fIsAuto, _fIsMidnight, _fIsOffline; |
||||
|
||||
|
||||
}; |
||||
|
||||
|
||||
|
||||
#endif //__MODE_H__
|
Loading…
Reference in new issue