/* * flowSensor.h * * Created on: 1 Mar 2023 * Author: simen */ #ifndef INC_FLOWSENSOR_H_ #define INC_FLOWSENSOR_H_ #include "stm32f7xx_hal.h" #include "iDriver.h" #include "main.h" #include // Define the GPIO pin for the flow sensor signal //#define FLOW_SENSOR_GPIO_PORT GPIOB //#define FLOW_SENSOR_GPIO_PIN FLOW_SENSOR_PIN #define K_FACTOR 6646 //6646 ticks per liter #define ticsinaminute 60000 class FlowSensorDrv : public IDriver { public: FlowSensorDrv(); void send(const char* raw_data); char* decodeAndProcess(char* data){ float literpermin=flow_rate*(runtime/ticsinaminute); snprintf(data,32,"%f",literpermin); return (data); } // Enable the interrupt for the flow sensor void EnableInterrupt(); // Disable the interrupt for the flow sensor void DisableInterrupt(); // Update the pulse count and flow rate based on the current state of the input pin void Update(); void setRuntime(uint32_t new_runtime); static void InterruptHandler(); private: // Define a variable to store the pulse count static volatile uint32_t pulse_count; static volatile float flow_rate; uint32_t runtime=10000; //how long we measure for to find current flowrate void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin); void reset(); }; #endif /* INC_FLOWSENSOR_H_ */