forked from xuos/xiuos
				
			add g8s sensor support Nuttx on stm32f407-discovery
This commit is contained in:
		
							parent
							
								
									21dce4f25e
								
							
						
					
					
						commit
						0b0b4c24ed
					
				|  | @ -22,10 +22,11 @@ ifeq ($(CONFIG_ADD_NUTTX_FETURES),y) | ||||||
|     ifeq ($(CONFIG_APPLICATION_SENSOR_CO2_ZG09), y) |     ifeq ($(CONFIG_APPLICATION_SENSOR_CO2_ZG09), y) | ||||||
|         CSRCS += co2_zg09.c |         CSRCS += co2_zg09.c | ||||||
|     endif |     endif | ||||||
| 
 |      | ||||||
|     ifeq ($(CONFIG_APPLICATION_SENSOR_CO2_G8S), y) |     ifeq ($(CONFIG_APPLICATION_SENSOR_CO2_G8S), y) | ||||||
|         CSRCS += co2_g8s.c |         CSRCS += co2_g8s.c | ||||||
|     endif |     endif | ||||||
|  |      | ||||||
| 
 | 
 | ||||||
|     ifeq ($(CONFIG_APPLICATION_SENSOR_PM1_0_PS5308), y) |     ifeq ($(CONFIG_APPLICATION_SENSOR_PM1_0_PS5308), y) | ||||||
|         CSRCS += pm1_0_ps5308.c |         CSRCS += pm1_0_ps5308.c | ||||||
|  |  | ||||||
|  | @ -102,29 +102,12 @@ config SENSOR_G8S | ||||||
|                 if ADD_NUTTX_FETURES |                 if ADD_NUTTX_FETURES | ||||||
|                        config SENSOR_DEVICE_G8S_DEV |                        config SENSOR_DEVICE_G8S_DEV | ||||||
|                                string "CO2 device name" |                                string "CO2 device name" | ||||||
|                                default "/dev/ttyS1" |                                default "/dev/ttyS3" | ||||||
|                                ---help--- |                                ---help--- | ||||||
|                                    If USART1 is selected, then fill in /dev/ttyS1 here. |                                    If USART1 is selected, then fill in /dev/ttyS1 here. | ||||||
|                 endif |                 endif | ||||||
| 
 | 
 | ||||||
|                 if ADD_RTTHREAD_FETURES |                 if ADD_RTTHREAD_FETURES | ||||||
|                         config SENSOR_G8S_DRIVER_EXTUART |  | ||||||
|                                 bool "Using extra uart to support g8-s" |  | ||||||
|                                 default y |  | ||||||
| 
 | 
 | ||||||
|                         config SENSOR_DEVICE_G8S_DEV |  | ||||||
|                                 string "g8-s device uart path" |  | ||||||
|                                 default "/dev/uart2_dev2" |  | ||||||
|                                 depends on !SENSOR_G8S_DRIVER_EXTUART |  | ||||||
| 
 |  | ||||||
|                         if SENSOR_G8S_DRIVER_EXTUART |  | ||||||
|                                 config SENSOR_DEVICE_G8S_DEV |  | ||||||
|                                         string "g8-s device extra uart path" |  | ||||||
|                                         default "/dev/extuart_dev4" |  | ||||||
| 
 |  | ||||||
|                                 config SENSOR_DEVICE_G8S_DEV_EXT_PORT |  | ||||||
|                                         int "if G8S device using extuart, choose port" |  | ||||||
|                                         default "4" |  | ||||||
|                         endif |  | ||||||
|                 endif                 |                 endif                 | ||||||
|         endif |         endif | ||||||
|  |  | ||||||
|  | @ -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 | ||||||
|  | @ -47,15 +47,8 @@ static int SensorDeviceOpen(struct SensorDevice *sdev) | ||||||
|         printf("open %s error\n", SENSOR_DEVICE_G8S_DEV); |         printf("open %s error\n", SENSOR_DEVICE_G8S_DEV); | ||||||
|         return -1; |         return -1; | ||||||
|     } |     } | ||||||
|      |  | ||||||
| 
 |  | ||||||
|     result = sdev->done->ioctl(sdev, SENSOR_DEVICE_PASSIVE); |  | ||||||
|     if (result != 0){ |  | ||||||
|         printf("SensorDeviceOpen:ioctl failed, status=%d\n", result); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     return result; |  | ||||||
| } | } | ||||||
|  | 
 | ||||||
| #else | #else | ||||||
| static int SensorDeviceOpen(struct SensorDevice *sdev) | 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) | static int SensorDeviceRead(struct SensorDevice *sdev, size_t len) | ||||||
| { | { | ||||||
|     uint8_t tmp = 0; |  | ||||||
| 
 | 
 | ||||||
|     PrivWrite(sdev->fd, g8s_read_instruction, sizeof(g8s_read_instruction)); |     PrivWrite(sdev->fd, g8s_read_instruction, sizeof(g8s_read_instruction)); | ||||||
| 
 |     PrivTaskDelay(500); | ||||||
|     if (PrivRead(sdev->fd, sdev->buffer, len) < 0) |     if (PrivRead(sdev->fd, sdev->buffer, len) < 0) | ||||||
|         return -1; |         return -1; | ||||||
| 
 | 
 | ||||||
|  | @ -161,16 +153,26 @@ static int32_t QuantityRead(struct SensorQuantity *quant) | ||||||
|                 result_ascii[i] = quant->sdev->buffer[i]; |                 result_ascii[i] = quant->sdev->buffer[i]; | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             if (8 == ascii_length) { |             if (ascii_length == 0){ | ||||||
|                 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 { |  | ||||||
|                 printf("This reading is wrong\n"); |                 printf("This reading is wrong\n"); | ||||||
|  | 
 | ||||||
|                 result = SENSOR_QUANTITY_VALUE_ERROR; |                 result = SENSOR_QUANTITY_VALUE_ERROR; | ||||||
|  | 
 | ||||||
|                 return result; |                 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) { |         if (quant->sdev->status == SENSOR_DEVICE_ACTIVE) { | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue