marvinroger / arduino-shutters

Arduino library to control non-smart roller shutters using time
MIT License
60 stars 17 forks source link

Get the state in percent when halted #21

Closed ludodoucet closed 6 years ago

ludodoucet commented 6 years ago

Hello,

I want to get the state in percent when the shutter is halted.

void shuttersWriteStateHandler1(Shutters* shutters, const char* state, byte length) {
  for (byte i = 0; i < length; i++) {
    EEPROM.write(eepromOffset1 + i, state[i]);
  }
  String states = String(state);
  if (debug == true) {Serial.print("shutters1 at ");
  Serial.print(states);
  Serial.println("% write");}
}

where: shutters1 at 00007421703598089056% write when shutter is at 10% shutters1 at 00007421703598081376% write when shutter is at 15%

with:

void onShuttersLevelReached1(Shutters* shutters, byte level) {
  if (debug == true) {Serial.print("shutters1 at ");
  Serial.print(level);
  Serial.println("%");}

the state in percent change at every step, I want to have it only when is halted, can you help me 'stp'?

marvinroger commented 6 years ago

The state value is serialized, it is not meant to be used that way. Just call .getCurrentLevel() and you'll have the level, what's wrong with this?

ludodoucet commented 6 years ago

I look where I can put it in my code and I come back to you. Thanks.

ludodoucet commented 6 years ago

it's work, thank you.

void shuttersWriteStateHandler1(Shutters* shutters, const char* state, byte length) {
  for (byte i = 0; i < length; i++) {
    EEPROM.write(eepromOffset1 + i, state[i]);
  }
  byte level = shutters->getCurrentLevel();
  if (debug == true) {Serial.print("shutters1 at ");
  Serial.print(level);
  Serial.println("% write");}

  if (level != 255)  {  MQTTout(1, level);}

}
marvinroger commented 6 years ago

You're welcome!