| 123456789101112131415161718192021222324 |
- #include "gas_sensor.h"
- #include "bsp/bsp.h"
- #include "bsp/adc.h"
- #include "libs/utils.h"
- static gas_t _gas;
- void gas_sensor_init(void){
- _gas.voltage = 0;
- _gas.lowpass = 5;
- gas_sample_voltage();
- }
- float gas_sample_voltage(void){
- u32 vadc = adc_sample_regular_channel(HANDLERBAR_CHAN, 16);
- _gas.voltage = vadc * ADC_REFERENCE_VOLTAGE /4096.0f;
-
- return MAX(min(_gas.voltage, MIN_GAS_VALUE), MAX_GAS_VALUE);
- }
- /* 检测到有效转把信号 */
- bool gas_detect_speed_signal(void) {
- return _gas.voltage > MIN_GAS_VALUE;
- }
|