diff --git a/README.md b/README.md index 53126e7..882d436 100644 --- a/README.md +++ b/README.md @@ -174,6 +174,15 @@ int readAllInputs(); >the bit in the byte is set to 1, if the input is open the bit in the byte is set to 0. 256 will be >returned if an error has occured(generally due to lack of communciation with controller). +```cpp +byte setPullUp(byte pullup); +``` +>This method accepts one byte. Valid byte arguments 0x00 to 0xFC. A call to this method will set or remove the pull-up +>resistors on the inputs. Setting the bit corresponding to the MCP23008 input pin will internally pull the pin high +>through a 100Kohm resistor. By default the pull-up resistors are all enabled. Bit 7-0 corresponds to PU7:PU0 +>excluding bits 0 and 1 as they are the relay driver pins. +>Example: default setting byte is 0XFC, to turn off the pull-up resistor for input 1 the byte value would be +>0xF8 (remeber that 0 and 1 are for relay control). ###Public accessible variables ```cpp @@ -188,4 +197,4 @@ License ---- GNU -[sparkIncludeLibrary]:https://docs.particle.io/guide/getting-started/build/photon/ \ No newline at end of file +[sparkIncludeLibrary]:https://docs.particle.io/guide/getting-started/build/photon/ diff --git a/firmware/NCD2Relay.cpp b/firmware/NCD2Relay.cpp index e6e3148..51f479c 100644 --- a/firmware/NCD2Relay.cpp +++ b/firmware/NCD2Relay.cpp @@ -449,3 +449,37 @@ int NCD2Relay::readAllInputs(){ byte shifted = inverted >> 2; return shifted; } + +void NCD2Relay::setPullUp(byte pullup){ + // twoRelayMask = 0x03; // becuase this is the two relay board don't touch GPIO 1 and 2 + if((pullup & twoRelayMask) > 0x00){ + skippedPullup = 1; + return; + } + byte registerAddress = 0x06; + setPullUpRetry: + Wire.beginTransmission(address); + Wire.write(registerAddress); + Wire.write(pullup); + byte status = Wire.endTransmission(); + if(status !=0){ + if(retrys < 3){ + #ifdef LOGGING + Serial.println("Retry set pull-up"); + #endif + retrys++; + goto setPullUpRetry; + }else{ + #ifdef LOGGING + Serial.println("Set Pull Up failed"); + #endif + initialized = false; + retrys = 0; + } + + }else{ + initialized = true; + retrys = 0; + readStatus(); + } +} diff --git a/firmware/NCD2Relay.h b/firmware/NCD2Relay.h index 6d51358..6b7ada6 100644 --- a/firmware/NCD2Relay.h +++ b/firmware/NCD2Relay.h @@ -28,6 +28,8 @@ class NCD2Relay{ int readInputStatus(int input); //Read status of all inputs int readAllInputs(); + //Set input pull-up resistors on or off + void setPullUp(byte pullup); //User Accessible Variables //Whether or not the controller is ready to accept commands