#pragma once #include "Gpio.h" #include #include #include "BlockingQueue.h" #include "FsmState.h" #include "Pwm.h" class Sensor { public: Sensor(BlockingQueue& sysEvents); ~Sensor(); void enableDoubleSensor(bool enable) { doubleEnablePin.setValue((Gpio::GpioLevel)enable); } void resetPaperPin(); //是否扫描仪盖关上 bool isCoverClosed(); //是否纸张准备好 bool isPaperStandby(); //扫描时是否有纸张 bool isPaperAtScan(); //是否双张 bool isDoublePaper(); //等纸进来 bool waitPaperIn(int timeout_ms); //等纸出去 bool waitPaperOut(int timeout_ms); //纸在里面吗 bool isPaperIn(){return scanPin.getValue();} //等纸,待命 bool waitPaperStandBy(int timeout_ms); //取消等待纸张 void cancelWaitPaper(); private: Gpio coverPin; //开盖 Gpio paperPin; //有无纸 Gpio scanPin; //扫描传感器 Gpio double_out0_Pin; Gpio double_out1_Pin; Gpio doubleEnablePin; Gpio sensor_power; Pwm pwm2; BlockingQueue& events; std::mutex cv_m; std::condition_variable cv_cover_opened; std::condition_variable cv_cover_closed; std::condition_variable cv_paper_on; std::condition_variable cv_paper_off; std::condition_variable cv_scan_at; std::condition_variable cv_scan_not_at; std::condition_variable cv_double; std::thread thread_monitor; std::thread thread_monitor2; volatile bool bMonitor = true; volatile bool bMonitor2 = true; void monitor(); void monitor2(); };