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
|
* wake up i2c controller
|
||||||
*/
|
*/
|
||||||
void PCF8574::begin(){
|
bool PCF8574::begin(){
|
||||||
|
this->transmissionStatus = 4;
|
||||||
#if !defined(__AVR) && !defined(__STM32F1__) && !defined(TEENSYDUINO)
|
#if !defined(__AVR) && !defined(__STM32F1__) && !defined(TEENSYDUINO)
|
||||||
_wire->begin(_sda, _scl);
|
_wire->begin(_sda, _scl);
|
||||||
#else
|
#else
|
||||||
@ -215,7 +216,7 @@ void PCF8574::begin(){
|
|||||||
writeByteBuffered = writeModeUp;
|
writeByteBuffered = writeModeUp;
|
||||||
|
|
||||||
DEBUG_PRINTLN("Start end trasmission if stop here check pullup resistor.");
|
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
|
// // If using interrupt set interrupt value to pin
|
||||||
@ -234,6 +235,8 @@ void PCF8574::begin(){
|
|||||||
|
|
||||||
// inizialize last read
|
// inizialize last read
|
||||||
lastReadMillis = millis();
|
lastReadMillis = millis();
|
||||||
|
|
||||||
|
return this->isLastTransmissionSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -630,7 +633,7 @@ uint8_t PCF8574::digitalRead(uint8_t pin, bool forceReadNow){
|
|||||||
* @param pin
|
* @param pin
|
||||||
* @param value
|
* @param value
|
||||||
*/
|
*/
|
||||||
void PCF8574::digitalWrite(uint8_t pin, uint8_t value){
|
bool PCF8574::digitalWrite(uint8_t pin, uint8_t value){
|
||||||
DEBUG_PRINTLN("Begin trasmission");
|
DEBUG_PRINTLN("Begin trasmission");
|
||||||
_wire->beginTransmission(_address); //Begin the transmission to PCF8574
|
_wire->beginTransmission(_address); //Begin the transmission to PCF8574
|
||||||
DEBUG_PRINT("Value ");
|
DEBUG_PRINT("Value ");
|
||||||
@ -671,7 +674,9 @@ void PCF8574::digitalWrite(uint8_t pin, uint8_t value){
|
|||||||
// byteBuffered = (writeByteBuffered & writeMode) & (byteBuffered & readMode);
|
// byteBuffered = (writeByteBuffered & writeMode) & (byteBuffered & readMode);
|
||||||
DEBUG_PRINTLN("Start end trasmission if stop here check pullup resistor.");
|
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)());
|
PCF8574(TwoWire *pWire, uint8_t address, uint8_t sda, uint8_t scl, uint8_t interruptPin, void (*interruptFunction)());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void begin();
|
bool begin();
|
||||||
void pinMode(uint8_t pin, uint8_t mode, uint8_t output_start = HIGH);
|
void pinMode(uint8_t pin, uint8_t mode, uint8_t output_start = HIGH);
|
||||||
|
|
||||||
void encoder(uint8_t pinA, uint8_t pinB);
|
void encoder(uint8_t pinA, uint8_t pinB);
|
||||||
@ -147,7 +147,7 @@ public:
|
|||||||
#else
|
#else
|
||||||
byte digitalReadAll(void);
|
byte digitalReadAll(void);
|
||||||
#endif
|
#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);
|
bool readEncoderValue(uint8_t pinA, uint8_t pinB, volatile long *encoderValue);
|
||||||
int8_t readEncoderValue(uint8_t pinA, uint8_t pinB);
|
int8_t readEncoderValue(uint8_t pinA, uint8_t pinB);
|
||||||
@ -160,6 +160,13 @@ public:
|
|||||||
this->latency = latency;
|
this->latency = latency;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t getTransmissionStatusCode() const {
|
||||||
|
return transmissionStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isLastTransmissionSuccess(){
|
||||||
|
return transmissionStatus==0;
|
||||||
|
}
|
||||||
private:
|
private:
|
||||||
uint8_t _address;
|
uint8_t _address;
|
||||||
|
|
||||||
@ -207,6 +214,7 @@ private:
|
|||||||
byte validCW = B01001011;
|
byte validCW = B01001011;
|
||||||
byte validCCW = B11100001;
|
byte validCCW = B11100001;
|
||||||
|
|
||||||
|
uint8_t transmissionStatus = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user