zynq_7010/zynq_7010_code/Sensor.h

73 lines
1.9 KiB
C
Raw Normal View History

2023-07-17 03:29:37 +00:00
#pragma once
#include "Gpio.h"
#include <thread>
#include <condition_variable>
#include "BlockingQueue.h"
#include "FsmState.h"
#include "Pwm.h"
class Sensor
{
public:
Sensor(BlockingQueue<ScanEvent>& sysEvents);
~Sensor();
2023-09-01 01:51:35 +00:00
//出现双张或者在没有双张时并且结束扫描需要关闭超声波检测,
2023-07-17 03:29:37 +00:00
void enableDoubleSensor(bool enable) {
2023-09-01 01:51:35 +00:00
enbale_double_ = enable;
2023-07-17 03:29:37 +00:00
doubleEnablePin.setValue((Gpio::GpioLevel)enable);
2023-09-01 01:51:35 +00:00
printf("是否使能超声波:%s\r\n",enable?"true":"false");
2023-07-17 03:29:37 +00:00
}
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();
2023-08-31 08:37:05 +00:00
//双张使能
2023-07-17 03:29:37 +00:00
private:
Gpio coverPin; //开盖
Gpio paperPin; //有无纸
Gpio scanPin; //扫描传感器
Gpio double_out0_Pin;
Gpio double_out1_Pin;
Gpio doubleEnablePin;
Gpio sensor_power;
Pwm pwm2;
BlockingQueue<ScanEvent>& 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;
2023-08-31 08:37:05 +00:00
volatile bool double_1 = false;
volatile bool double_2 = false;
2023-09-01 01:51:35 +00:00
volatile bool enbale_double_=false;
volatile bool is_open_cover = false;
2023-07-17 03:29:37 +00:00
void monitor();
void monitor2();
2023-08-31 08:37:05 +00:00
int readfile(int fd,int num , char* buf);
2023-07-17 03:29:37 +00:00
};