Bug in Relay Code
Posted: Wed Sep 26, 2012 7:20 am
Hi,
I think I have found a bug in the current (1.0.1) Relay code.
I had the following snippet of code in my sketch:
But I found that my UV was always on. I couldn't figure out why at first till I realized that FANS is defined as follows:
And Box1_Port8 is defined in Globals.h as:
Finally I looked at the code for Status in Relay.h. It is defined as:
Clearly this won't work. It is trying to read bit 18 of the main RelayData instead of reading the expansion relay data. I think the function needs to be more like this:
However, this wouldn't return what I really want either, so I think there needs to be two functions. The one above should probably be called OverrideStatus and the Status function should be as follows:
One function would return status including overrides, the other just plain status. In any case the current function doesn't work.
Thanks,
Don
I think I have found a bug in the current (1.0.1) Relay code.
I had the following snippet of code in my sketch:
Code: Select all
// turn the UV off when the fans are on.
ReefAngel.Relay.Set (UV, !ReefAngel.Relay.Status(FANS));
Code: Select all
#define FANS Box1_Port8
Code: Select all
#define Box1_Port8 18
Code: Select all
inline boolean Status(byte Port) { return bitRead((RelayData & RelayMaskOff) | RelayMaskOn,Port-1); }
Code: Select all
boolean RelayClass::Status(byte ID)
{
if ( ID < 9 ) return bitRead((RelayData & RelayMaskOff) | RelayMaskOn, ID-1);
#ifdef RelayExp
if ( (ID > 10) && (ID < 89) )
{
byte EID = byte(ID/10);
return bitRead((RelayDataE[EID-1] & RelayMaskOffE[EID-1]) | RelayMaskOnE[EID-1], (ID%10)-1);
}
#endif // RelayExp
return false;
}
Code: Select all
boolean RelayClass::Status(byte ID)
{
if ( ID < 9 ) return bitRead(RelayData, ID-1);
#ifdef RelayExp
if ( (ID > 10) && (ID < 89) )
{
byte EID = byte(ID/10);
return bitRead(RelayDataE[EID-1], (ID%10)-1);
}
#endif // RelayExp
return false;
}
Thanks,
Don