mirror of
https://github.com/xreef/PCF8574_library.git
synced 2024-08-30 18:12:18 +00:00
Add return status on begin and digitalWrite
This commit is contained in:
parent
dcf9e35fdc
commit
da251b1363
13
PCF8574.cpp
13
PCF8574.cpp
@ -183,7 +183,8 @@ PCF8574::PCF8574(uint8_t address, uint8_t interruptPin, void (*interruptFunctio
|
||||
/**
|
||||
* wake up i2c controller
|
||||
*/
|
||||
void PCF8574::begin(){
|
||||
bool PCF8574::begin(){
|
||||
this->transmissionStatus = 4;
|
||||
#if !defined(__AVR) && !defined(__STM32F1__) && !defined(TEENSYDUINO)
|
||||
_wire->begin(_sda, _scl);
|
||||
#else
|
||||
@ -215,7 +216,7 @@ void PCF8574::begin(){
|
||||
writeByteBuffered = writeModeUp;
|
||||
|
||||
DEBUG_PRINTLN("Start end trasmission if stop here check pullup resistor.");
|
||||
_wire->endTransmission();
|
||||
this->transmissionStatus = _wire->endTransmission();
|
||||
}
|
||||
|
||||
// // If using interrupt set interrupt value to pin
|
||||
@ -234,6 +235,8 @@ void PCF8574::begin(){
|
||||
|
||||
// inizialize last read
|
||||
lastReadMillis = millis();
|
||||
|
||||
return this->isLastTransmissionSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -630,7 +633,7 @@ uint8_t PCF8574::digitalRead(uint8_t pin, bool forceReadNow){
|
||||
* @param pin
|
||||
* @param value
|
||||
*/
|
||||
void PCF8574::digitalWrite(uint8_t pin, uint8_t value){
|
||||
bool PCF8574::digitalWrite(uint8_t pin, uint8_t value){
|
||||
DEBUG_PRINTLN("Begin trasmission");
|
||||
_wire->beginTransmission(_address); //Begin the transmission to PCF8574
|
||||
DEBUG_PRINT("Value ");
|
||||
@ -671,7 +674,9 @@ void PCF8574::digitalWrite(uint8_t pin, uint8_t value){
|
||||
// byteBuffered = (writeByteBuffered & writeMode) & (byteBuffered & readMode);
|
||||
DEBUG_PRINTLN("Start end trasmission if stop here check pullup resistor.");
|
||||
|
||||
_wire->endTransmission();
|
||||
this->transmissionStatus = _wire->endTransmission();
|
||||
|
||||
return this->isLastTransmissionSuccess();
|
||||
};
|
||||
|
||||
|
||||
|
12
PCF8574.h
12
PCF8574.h
@ -120,7 +120,7 @@ public:
|
||||
PCF8574(TwoWire *pWire, uint8_t address, uint8_t sda, uint8_t scl, uint8_t interruptPin, void (*interruptFunction)());
|
||||
#endif
|
||||
|
||||
void begin();
|
||||
bool begin();
|
||||
void pinMode(uint8_t pin, uint8_t mode, uint8_t output_start = HIGH);
|
||||
|
||||
void encoder(uint8_t pinA, uint8_t pinB);
|
||||
@ -147,7 +147,7 @@ public:
|
||||
#else
|
||||
byte digitalReadAll(void);
|
||||
#endif
|
||||
void digitalWrite(uint8_t pin, uint8_t value);
|
||||
bool digitalWrite(uint8_t pin, uint8_t value);
|
||||
|
||||
bool readEncoderValue(uint8_t pinA, uint8_t pinB, volatile long *encoderValue);
|
||||
int8_t readEncoderValue(uint8_t pinA, uint8_t pinB);
|
||||
@ -160,6 +160,13 @@ public:
|
||||
this->latency = latency;
|
||||
}
|
||||
|
||||
uint8_t getTransmissionStatusCode() const {
|
||||
return transmissionStatus;
|
||||
}
|
||||
|
||||
bool isLastTransmissionSuccess(){
|
||||
return transmissionStatus==0;
|
||||
}
|
||||
private:
|
||||
uint8_t _address;
|
||||
|
||||
@ -207,6 +214,7 @@ private:
|
||||
byte validCW = B01001011;
|
||||
byte validCCW = B11100001;
|
||||
|
||||
uint8_t transmissionStatus = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user