Added i2c_disconnect to c sdk
* Added closeSerialPort() for Linux build * i2c_disconnect() closes the serial port, and resets the `connected` flag to zero.
This commit is contained in:
parent
6e0696e0bf
commit
801eeb00e4
|
@ -186,6 +186,12 @@ void writeToSerialPort(int fd, const uint8_t *b, size_t s)
|
||||||
printf("\n");
|
printf("\n");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void closeSerialPort(HANDLE hSerial)
|
||||||
|
{
|
||||||
|
close((int)hSerial);
|
||||||
|
}
|
||||||
|
|
||||||
#endif // }
|
#endif // }
|
||||||
|
|
||||||
// ****************************** CCITT CRC *********************************
|
// ****************************** CCITT CRC *********************************
|
||||||
|
@ -268,6 +274,15 @@ void i2c_connect(I2CDriver *sd, const char* portname)
|
||||||
sd->e_ccitt_crc = sd->ccitt_crc;
|
sd->e_ccitt_crc = sd->ccitt_crc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void i2c_disconnect(I2CDriver *sd)
|
||||||
|
{
|
||||||
|
if (sd->connected) {
|
||||||
|
closeSerialPort(sd->port);
|
||||||
|
sd->port = -1;
|
||||||
|
sd->connected = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void charCommand(I2CDriver *sd, char c)
|
static void charCommand(I2CDriver *sd, char c)
|
||||||
{
|
{
|
||||||
writeToSerialPort(sd->port, (uint8_t*)&c, 1);
|
writeToSerialPort(sd->port, (uint8_t*)&c, 1);
|
||||||
|
|
|
@ -29,6 +29,7 @@ typedef struct {
|
||||||
} I2CDriver;
|
} I2CDriver;
|
||||||
|
|
||||||
void i2c_connect(I2CDriver *sd, const char* portname);
|
void i2c_connect(I2CDriver *sd, const char* portname);
|
||||||
|
void i2c_disconnect(I2CDriver *sd);
|
||||||
void i2c_getstatus(I2CDriver *sd);
|
void i2c_getstatus(I2CDriver *sd);
|
||||||
int i2c_write(I2CDriver *sd, const uint8_t bytes[], size_t nn);
|
int i2c_write(I2CDriver *sd, const uint8_t bytes[], size_t nn);
|
||||||
void i2c_read(I2CDriver *sd, uint8_t bytes[], size_t nn);
|
void i2c_read(I2CDriver *sd, uint8_t bytes[], size_t nn);
|
||||||
|
|
Loading…
Reference in New Issue