This commit is contained in:
wgzAIIT
2022-07-28 14:31:48 +08:00
32 changed files with 18116 additions and 16 deletions
+6 -1
View File
@@ -64,6 +64,7 @@ config SENSOR_ZG09
endif
endif
config SENSOR_G8S
bool "Using g8-s"
default n
@@ -99,7 +100,11 @@ config SENSOR_G8S
endif
if ADD_NUTTX_FETURES
config SENSOR_DEVICE_G8S_DEV
string "CO2 device name"
default "/dev/ttyS3"
---help---
If USART1 is selected, then fill in /dev/ttyS1 here.
endif
if ADD_RTTHREAD_FETURES
@@ -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
@@ -1,3 +1,13 @@
SRC_FILES := g8s.c
include $(KERNEL_ROOT)/.config
ifeq ($(CONFIG_ADD_NUTTX_FETURES),y)
include $(APPDIR)/Make.defs
CSRCS += g8s.c
include $(APPDIR)/Application.mk
endif
ifeq ($(CONFIG_ADD_XIZI_FETURES),y)
SRC_FILES := g8s.c
include $(KERNEL_ROOT)/compiler.mk
endif
include $(KERNEL_ROOT)/compiler.mk
+34 -11
View File
@@ -37,6 +37,7 @@ static struct SensorProductInfo info =
* @param sdev - sensor device pointer
* @return success: 1 , failure: other
*/
#ifdef ADD_NUTTX_FETURES
static int SensorDeviceOpen(struct SensorDevice *sdev)
{
int result = 0;
@@ -46,7 +47,20 @@ static int SensorDeviceOpen(struct SensorDevice *sdev)
printf("open %s error\n", SENSOR_DEVICE_G8S_DEV);
return -1;
}
}
#else
static int SensorDeviceOpen(struct SensorDevice *sdev)
{
int result = 0;
sdev->fd = PrivOpen(SENSOR_DEVICE_G8S_DEV, O_RDWR);
if (sdev->fd < 0) {
printf("open %s error\n", SENSOR_DEVICE_G8S_DEV);
return -1;
}
struct SerialDataCfg cfg;
cfg.serial_baud_rate = BAUD_RATE_9600;
cfg.serial_data_bits = DATA_BITS_8;
@@ -67,7 +81,7 @@ static int SensorDeviceOpen(struct SensorDevice *sdev)
return result;
}
#endif
/**
* @description: Read sensor device
* @param sdev - sensor device pointer
@@ -76,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;
@@ -140,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) {