Loop once per 5 seconds.
Clean up CRC8 functions (style, no caps).
This commit is contained in:
@ -90,7 +90,7 @@ int main() {
|
||||
for (;;) {
|
||||
do_sht31(sht31);
|
||||
do_si7021(si7021);
|
||||
sleep(1);
|
||||
sleep(5);
|
||||
}
|
||||
|
||||
mgos_sht31_destroy(&sht31);
|
||||
|
@ -38,13 +38,13 @@ static bool mgos_sht31_cmd(struct mgos_sht31 *sensor, uint16_t cmd) {
|
||||
|
||||
static uint8_t crc8(const uint8_t *data, int len)
|
||||
{
|
||||
const uint8_t POLYNOMIAL=0x31;
|
||||
const uint8_t poly=0x31;
|
||||
uint8_t crc=0xFF;
|
||||
|
||||
for (int j=len; j; --j ) {
|
||||
crc ^= *data++;
|
||||
for ( int i = 8; i; --i )
|
||||
crc = ( crc & 0x80 ) ? (crc << 1) ^ POLYNOMIAL : (crc << 1);
|
||||
for (int j=len; j; --j) {
|
||||
crc^=*data++;
|
||||
for (int i=8; i; --i)
|
||||
crc=(crc & 0x80) ? (crc << 1) ^ poly : (crc << 1);
|
||||
}
|
||||
return crc;
|
||||
}
|
||||
|
@ -34,13 +34,13 @@ static bool mgos_si7021_cmd(struct mgos_si7021 *sensor, uint8_t cmd) {
|
||||
|
||||
static uint8_t crc8(const uint8_t *data, int len)
|
||||
{
|
||||
const uint8_t POLYNOMIAL=0x31;
|
||||
const uint8_t poly=0x31;
|
||||
uint8_t crc=0x00;
|
||||
|
||||
for (int j=len; j; --j ) {
|
||||
crc ^= *data++;
|
||||
for ( int i = 8; i; --i )
|
||||
crc = ( crc & 0x80 ) ? (crc << 1) ^ POLYNOMIAL : (crc << 1);
|
||||
for (int j=len; j; --j) {
|
||||
crc^=*data++;
|
||||
for (int i=8; i; --i)
|
||||
crc=(crc & 0x80) ? (crc << 1) ^ poly : (crc << 1);
|
||||
}
|
||||
return crc;
|
||||
}
|
||||
|
Reference in New Issue
Block a user