Repo restyled using astyle (#683)
The rules are in .tools/astyle/config/style.cfg and can also be reviewed at https://www.mysensors.org/view/260#coding-guidelines-core-library
This commit is contained in:
@@ -57,28 +57,29 @@ MyMessage dimmerMsg(CHILD_ID_LIGHT, V_DIMMER);
|
||||
|
||||
void setup()
|
||||
{
|
||||
//Retreive our last light state from the eprom
|
||||
int LightState=loadState(EPROM_LIGHT_STATE);
|
||||
if (LightState<=1) {
|
||||
LastLightState=LightState;
|
||||
int DimValue=loadState(EPROM_DIMMER_LEVEL);
|
||||
if ((DimValue>0)&&(DimValue<=100)) {
|
||||
//There should be no Dim value of 0, this would mean LIGHT_OFF
|
||||
LastDimValue=DimValue;
|
||||
}
|
||||
}
|
||||
//Retreive our last light state from the eprom
|
||||
int LightState=loadState(EPROM_LIGHT_STATE);
|
||||
if (LightState<=1) {
|
||||
LastLightState=LightState;
|
||||
int DimValue=loadState(EPROM_DIMMER_LEVEL);
|
||||
if ((DimValue>0)&&(DimValue<=100)) {
|
||||
//There should be no Dim value of 0, this would mean LIGHT_OFF
|
||||
LastDimValue=DimValue;
|
||||
}
|
||||
}
|
||||
|
||||
//Here you actualy switch on/off the light with the last known dim level
|
||||
SetCurrentState2Hardware();
|
||||
//Here you actualy switch on/off the light with the last known dim level
|
||||
SetCurrentState2Hardware();
|
||||
|
||||
Serial.println( "Node ready to receive messages..." );
|
||||
Serial.println( "Node ready to receive messages..." );
|
||||
}
|
||||
|
||||
void presentation() {
|
||||
// Send the Sketch Version Information to the Gateway
|
||||
sendSketchInfo(SN, SV);
|
||||
void presentation()
|
||||
{
|
||||
// Send the Sketch Version Information to the Gateway
|
||||
sendSketchInfo(SN, SV);
|
||||
|
||||
present(CHILD_ID_LIGHT, S_DIMMER );
|
||||
present(CHILD_ID_LIGHT, S_DIMMER );
|
||||
}
|
||||
|
||||
void loop()
|
||||
@@ -87,74 +88,69 @@ void loop()
|
||||
|
||||
void receive(const MyMessage &message)
|
||||
{
|
||||
if (message.type == V_LIGHT) {
|
||||
Serial.println( "V_LIGHT command received..." );
|
||||
if (message.type == V_LIGHT) {
|
||||
Serial.println( "V_LIGHT command received..." );
|
||||
|
||||
int lstate= atoi( message.data );
|
||||
if ((lstate<0)||(lstate>1)) {
|
||||
Serial.println( "V_LIGHT data invalid (should be 0/1)" );
|
||||
return;
|
||||
}
|
||||
LastLightState=lstate;
|
||||
saveState(EPROM_LIGHT_STATE, LastLightState);
|
||||
int lstate= atoi( message.data );
|
||||
if ((lstate<0)||(lstate>1)) {
|
||||
Serial.println( "V_LIGHT data invalid (should be 0/1)" );
|
||||
return;
|
||||
}
|
||||
LastLightState=lstate;
|
||||
saveState(EPROM_LIGHT_STATE, LastLightState);
|
||||
|
||||
if ((LastLightState==LIGHT_ON)&&(LastDimValue==0)) {
|
||||
//In the case that the Light State = On, but the dimmer value is zero,
|
||||
//then something (probably the controller) did something wrong,
|
||||
//for the Dim value to 100%
|
||||
LastDimValue=100;
|
||||
saveState(EPROM_DIMMER_LEVEL, LastDimValue);
|
||||
}
|
||||
if ((LastLightState==LIGHT_ON)&&(LastDimValue==0)) {
|
||||
//In the case that the Light State = On, but the dimmer value is zero,
|
||||
//then something (probably the controller) did something wrong,
|
||||
//for the Dim value to 100%
|
||||
LastDimValue=100;
|
||||
saveState(EPROM_DIMMER_LEVEL, LastDimValue);
|
||||
}
|
||||
|
||||
//When receiving a V_LIGHT command we switch the light between OFF and the last received dimmer value
|
||||
//This means if you previously set the lights dimmer value to 50%, and turn the light ON
|
||||
//it will do so at 50%
|
||||
}
|
||||
else if (message.type == V_DIMMER) {
|
||||
Serial.println( "V_DIMMER command received..." );
|
||||
int dimvalue= atoi( message.data );
|
||||
if ((dimvalue<0)||(dimvalue>100)) {
|
||||
Serial.println( "V_DIMMER data invalid (should be 0..100)" );
|
||||
return;
|
||||
}
|
||||
if (dimvalue==0) {
|
||||
LastLightState=LIGHT_OFF;
|
||||
}
|
||||
else {
|
||||
LastLightState=LIGHT_ON;
|
||||
LastDimValue=dimvalue;
|
||||
saveState(EPROM_DIMMER_LEVEL, LastDimValue);
|
||||
}
|
||||
}
|
||||
else {
|
||||
Serial.println( "Invalid command received..." );
|
||||
return;
|
||||
}
|
||||
//When receiving a V_LIGHT command we switch the light between OFF and the last received dimmer value
|
||||
//This means if you previously set the lights dimmer value to 50%, and turn the light ON
|
||||
//it will do so at 50%
|
||||
} else if (message.type == V_DIMMER) {
|
||||
Serial.println( "V_DIMMER command received..." );
|
||||
int dimvalue= atoi( message.data );
|
||||
if ((dimvalue<0)||(dimvalue>100)) {
|
||||
Serial.println( "V_DIMMER data invalid (should be 0..100)" );
|
||||
return;
|
||||
}
|
||||
if (dimvalue==0) {
|
||||
LastLightState=LIGHT_OFF;
|
||||
} else {
|
||||
LastLightState=LIGHT_ON;
|
||||
LastDimValue=dimvalue;
|
||||
saveState(EPROM_DIMMER_LEVEL, LastDimValue);
|
||||
}
|
||||
} else {
|
||||
Serial.println( "Invalid command received..." );
|
||||
return;
|
||||
}
|
||||
|
||||
//Here you set the actual light state/level
|
||||
SetCurrentState2Hardware();
|
||||
//Here you set the actual light state/level
|
||||
SetCurrentState2Hardware();
|
||||
}
|
||||
|
||||
void SetCurrentState2Hardware()
|
||||
{
|
||||
if (LastLightState==LIGHT_OFF) {
|
||||
Serial.println( "Light state: OFF" );
|
||||
}
|
||||
else {
|
||||
Serial.print( "Light state: ON, Level: " );
|
||||
Serial.println( LastDimValue );
|
||||
}
|
||||
if (LastLightState==LIGHT_OFF) {
|
||||
Serial.println( "Light state: OFF" );
|
||||
} else {
|
||||
Serial.print( "Light state: ON, Level: " );
|
||||
Serial.println( LastDimValue );
|
||||
}
|
||||
|
||||
//Send current state to the controller
|
||||
SendCurrentState2Controller();
|
||||
//Send current state to the controller
|
||||
SendCurrentState2Controller();
|
||||
}
|
||||
|
||||
void SendCurrentState2Controller()
|
||||
{
|
||||
if ((LastLightState==LIGHT_OFF)||(LastDimValue==0)) {
|
||||
send(dimmerMsg.set((int16_t)0));
|
||||
}
|
||||
else {
|
||||
send(dimmerMsg.set(LastDimValue));
|
||||
}
|
||||
if ((LastLightState==LIGHT_OFF)||(LastDimValue==0)) {
|
||||
send(dimmerMsg.set((int16_t)0));
|
||||
} else {
|
||||
send(dimmerMsg.set(LastDimValue));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user