add g8s sensor support Nuttx on stm32f407-discovery

This commit is contained in:
zhr
2022-07-28 14:21:49 +08:00
parent 21dce4f25e
commit 0b0b4c24ed
4 changed files with 28 additions and 36 deletions
@@ -0,0 +1,6 @@
############################################################################
# APP_Framework/Framework/sensor/co2/g8s/Make.defs
############################################################################
ifneq ($(CONFIG_SENSOR_G8S),)
CONFIGURED_APPS += $(APPDIR)/../../../APP_Framework/Framework/sensor/co2/g8s
endif
+19 -17
View File
@@ -47,15 +47,8 @@ static int SensorDeviceOpen(struct SensorDevice *sdev)
printf("open %s error\n", SENSOR_DEVICE_G8S_DEV);
return -1;
}
result = sdev->done->ioctl(sdev, SENSOR_DEVICE_PASSIVE);
if (result != 0){
printf("SensorDeviceOpen:ioctl failed, status=%d\n", result);
}
return result;
}
#else
static int SensorDeviceOpen(struct SensorDevice *sdev)
{
@@ -97,10 +90,9 @@ static int SensorDeviceOpen(struct SensorDevice *sdev)
*/
static int SensorDeviceRead(struct SensorDevice *sdev, size_t len)
{
uint8_t tmp = 0;
PrivWrite(sdev->fd, g8s_read_instruction, sizeof(g8s_read_instruction));
PrivTaskDelay(500);
if (PrivRead(sdev->fd, sdev->buffer, len) < 0)
return -1;
@@ -161,16 +153,26 @@ static int32_t QuantityRead(struct SensorQuantity *quant)
result_ascii[i] = quant->sdev->buffer[i];
}
if (8 == ascii_length) {
for (i = 0; i < ascii_length; i ++) {
result_hex[i] = result_ascii[i] - 0x30;
result += result_hex[i] * pow(10, ascii_length - 1 - i);
}
return result;
} else {
if (ascii_length == 0){
printf("This reading is wrong\n");
result = SENSOR_QUANTITY_VALUE_ERROR;
return result;
}else{
for (i = 0; i < ascii_length; i ++) {
result_hex[i] = result_ascii[i] - 0x30;
result += result_hex[i] * pow(10, ascii_length - 1 - i);
}
return result;
}
}
if (quant->sdev->status == SENSOR_DEVICE_ACTIVE) {