Loop once per 5 seconds.

Clean up CRC8 functions (style, no caps).
This commit is contained in:
Pim van Pelt
2018-04-02 21:50:30 +02:00
parent 97310e3e03
commit e4ed4d005d
3 changed files with 11 additions and 11 deletions

View File

@ -90,7 +90,7 @@ int main() {
for (;;) { for (;;) {
do_sht31(sht31); do_sht31(sht31);
do_si7021(si7021); do_si7021(si7021);
sleep(1); sleep(5);
} }
mgos_sht31_destroy(&sht31); mgos_sht31_destroy(&sht31);

View File

@ -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) static uint8_t crc8(const uint8_t *data, int len)
{ {
const uint8_t POLYNOMIAL=0x31; const uint8_t poly=0x31;
uint8_t crc=0xFF; uint8_t crc=0xFF;
for (int j=len; j; --j ) { for (int j=len; j; --j) {
crc ^= *data++; crc^=*data++;
for ( int i = 8; i; --i ) for (int i=8; i; --i)
crc = ( crc & 0x80 ) ? (crc << 1) ^ POLYNOMIAL : (crc << 1); crc=(crc & 0x80) ? (crc << 1) ^ poly : (crc << 1);
} }
return crc; return crc;
} }

View File

@ -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) static uint8_t crc8(const uint8_t *data, int len)
{ {
const uint8_t POLYNOMIAL=0x31; const uint8_t poly=0x31;
uint8_t crc=0x00; uint8_t crc=0x00;
for (int j=len; j; --j ) { for (int j=len; j; --j) {
crc ^= *data++; crc^=*data++;
for ( int i = 8; i; --i ) for (int i=8; i; --i)
crc = ( crc & 0x80 ) ? (crc << 1) ^ POLYNOMIAL : (crc << 1); crc=(crc & 0x80) ? (crc << 1) ^ poly : (crc << 1);
} }
return crc; return crc;
} }