Browse Source

Support to set on/off state per channel using switches (#457)

i18n
Xose Pérez 6 years ago
parent
commit
789e834c55
2 changed files with 34 additions and 2 deletions
  1. +11
    -1
      code/espurna/light.ino
  2. +23
    -1
      code/espurna/relay.ino

+ 11
- 1
code/espurna/light.ino View File

@ -27,6 +27,7 @@ Ticker _light_transition_ticker;
typedef struct {
unsigned char pin;
bool reverse;
bool state;
unsigned char value; // target or nominal value
unsigned char shadow; // represented value
double current; // transition value
@ -381,7 +382,7 @@ void _shadow() {
// Transitions
unsigned char target;
for (unsigned int i=0; i < _light_channel.size(); i++) {
if (_light_state) {
if (_light_state && _light_channel[i].state) {
target = _light_channel[i].value;
if ((_light_brightness < LIGHT_MAX_BRIGHTNESS) && _light_has_color && (i < 3)) {
target *= ((float) _light_brightness / LIGHT_MAX_BRIGHTNESS);
@ -659,6 +660,14 @@ void lightSave() {
}
#endif
void lightState(unsigned char i, bool state) {
_light_channel[i].state = state;
}
bool lightState(unsigned char i) {
return _light_channel[i].state;
}
void lightState(bool state) {
_light_state = state;
}
@ -1027,6 +1036,7 @@ void lightSetup() {
io_info[i][1] = getIOFunc(_light_channel[i].pin);
io_info[i][2] = _light_channel[i].pin;
pinMode(_light_channel[i].pin, OUTPUT);
_light_channel[i].state = true;
}
pwm_init(LIGHT_MAX_PWM, pwm_duty_init, PWM_CHANNEL_NUM_MAX, io_info);
pwm_start();


+ 23
- 1
code/espurna/relay.ino View File

@ -78,8 +78,30 @@ void _relayProviderStatus(unsigned char id, bool status) {
#endif
#if RELAY_PROVIDER == RELAY_PROVIDER_LIGHT
lightState(status);
// If the number of relays matches the number of light channels
// assume each relay controls one channel.
// If the number of relays is the number of channels plus 1
// assume the first one controls all the channels and
// the rest one channel each.
// Otherwise every relay controls all channels.
// TODO: this won't work with a mixed of dummy and real relays
// but this option is not allowed atm (YANGNI)
if (_relays.size() == lightChannels()) {
lightState(id, status);
lightState(true);
} else if (_relays.size() == lightChannels() + 1) {
if (id == 0) {
lightState(status);
} else {
lightState(id-1, status);
}
} else {
lightState(status);
}
lightUpdate(true, true);
#endif
#if RELAY_PROVIDER == RELAY_PROVIDER_RELAY


Loading…
Cancel
Save