gas_sensor.c 529 B

123456789101112131415161718192021222324
  1. #include "gas_sensor.h"
  2. #include "bsp/bsp.h"
  3. #include "bsp/adc.h"
  4. #include "libs/utils.h"
  5. static gas_t _gas;
  6. void gas_sensor_init(void){
  7. _gas.voltage = 0;
  8. _gas.lowpass = 5;
  9. gas_sample_voltage();
  10. }
  11. float gas_sample_voltage(void){
  12. u32 vadc = adc_sample_regular_channel(HANDLERBAR_CHAN, 16);
  13. _gas.voltage = vadc * ADC_REFERENCE_VOLTAGE /4096.0f;
  14. return MAX(min(_gas.voltage, MIN_GAS_VALUE), MAX_GAS_VALUE);
  15. }
  16. /* 检测到有效转把信号 */
  17. bool gas_detect_speed_signal(void) {
  18. return _gas.voltage > MIN_GAS_VALUE;
  19. }