Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -188,4 +197,4 @@ License
----

GNU
[sparkIncludeLibrary]:https://docs.particle.io/guide/getting-started/build/photon/
[sparkIncludeLibrary]:https://docs.particle.io/guide/getting-started/build/photon/
34 changes: 34 additions & 0 deletions firmware/NCD2Relay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
2 changes: 2 additions & 0 deletions firmware/NCD2Relay.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down