zynq_7010/zynq_7010_code/DevUtil.h

79 lines
2.5 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#pragma once
#include <string>
#include <fstream>
#include <memory>
#include "scanservices_utils.h"
template<typename ... Args>
std::string string_format(const std::string& format, Args ... args) {
size_t size = snprintf(nullptr, 0, format.c_str(), args ...) + 1;
std::unique_ptr<char[]> buf(new char[size]);
snprintf(buf.get(), size, format.c_str(), args ...);
return std::string(buf.get(), buf.get() + size - 1);
}
template<typename T>
void write_dev(std::string path, T value) {
std::ofstream ofout(path);
ofout << value;
}
extern int read_dev_i(std::string path);
extern std::string read_dev_s(std::string path);
enum PIN_PORT_7010
{
//通道0-------------START
SCAN_SENSOR = 0 + 1019, //扫描传感器
HAVE_OR_NO_PAPER = 3 + 1019, //有无纸(0无纸1有纸)
OPEN_COVER_SENSOR = 4 + 1019, //是否开盖0未开盖1开盖
ULTRASONIC_SENSORS_OUT0 = 18 + 901,
ULTRASONIC_SENSORS_OUT1 = 17 + 901,
ULTRASONIC_SENSORS_ON = 20 + 901,
ULTRASONIC_SENSORS_ADJ = 19 + 901,
//通道0-------------END
SENSOR_POWER = 66 + 1019,
//通道1-------------START
BUTTON_1_POWER = 21+1019, //按键1 电源
BUTTON_2 = 22+1019, //按键2
BUTTON_3 = 23+1019, //按键3
LED_0_GREEN = 24+1019,
LED_1_WHITE = 25+1019,
LED_2_RED = 26+1019,
//PWM0 电机1-START
CUOZHI_PIN_DIR = 54+901, //方向0
CUOZHI_PIN_ENABEL = 55+901, //使能有效0
CUOZHI_PIN_RESET = 56+901, //重启 1电机转动一般默认为1
CUOZHI_PIN_SLEEP = 57+901, //睡眠 1电机转动一般默认为1
//PWM0 电机1-END
//PWM1 电机2-START
ZOUZHI_PIN_DIR = 59+901, //方向0
ZOUZHI_PIN_ENABEL = 60+901, //使能有效0
ZOUZHI_PIN_RESET = 61+901, //重启 1电机转动一般默认为1
ZOUZHI_PIN_SLEEP = 62+901, //睡眠 1电机转动一般默认为1
//PWM1 电机2-END
//通道1-------------END
MOTOR_POWER_1 = 64 + 901, //电机1 电源开关
MOTOR_POWER_2 = 65 + 901, //电机2 电源开关
};
class DeviceExport
{
public:
DeviceExport();
private:
const int ports[17] = { MOTOR_POWER_1, CUOZHI_PIN_RESET, CUOZHI_PIN_SLEEP,CUOZHI_PIN_ENABEL, CUOZHI_PIN_DIR,
MOTOR_POWER_2, ZOUZHI_PIN_RESET, ZOUZHI_PIN_SLEEP,ZOUZHI_PIN_ENABEL, ZOUZHI_PIN_DIR,
SCAN_SENSOR,HAVE_OR_NO_PAPER, OPEN_COVER_SENSOR,ULTRASONIC_SENSORS_OUT0,ULTRASONIC_SENSORS_OUT1,ULTRASONIC_SENSORS_ON};
const int pwms[3] = { 0, 1 ,2};
};