6 changed files with 218 additions and 8 deletions
@ -0,0 +1,124 @@ |
|||||
|
#include "deviceservice.h" |
||||
|
#ifdef Q_OS_LINUX |
||||
|
#include <wiringPi.h> |
||||
|
#else |
||||
|
#include <QtDebug> |
||||
|
#endif |
||||
|
|
||||
|
#define WIRING_PIN_LED 4 //GPIO.4
|
||||
|
#define WIRING_PIN_KEY 3 //GPIO.3
|
||||
|
|
||||
|
DeviceService::DeviceService(QObject *parent) : QObject(parent) |
||||
|
{ |
||||
|
key.flag = None; |
||||
|
key.lastState = None; |
||||
|
m_ledStatus = 0; |
||||
|
m_keyStatus = 0; |
||||
|
|
||||
|
#ifdef Q_OS_LINUX |
||||
|
wiringPiSetup(); |
||||
|
pinMode(WIRING_PIN_LED,OUTPUT);//LED输出模式 可选值:INPUT、OUTPUT、PWM_OUTPUT,GPIO_CLOCK
|
||||
|
pinMode(WIRING_PIN_KEY,INPUT); //KEY输入模式
|
||||
|
pullUpDnControl(WIRING_PIN_KEY,PUD_UP); //KEY设置上拉
|
||||
|
#else |
||||
|
qDebug() << "wiringPiSetup()"; |
||||
|
qDebug() << "pinMode(WIRING_PIN_LED,OUTPUT)"; |
||||
|
qDebug() << "pinMode(WIRING_PIN_BTN,INPUT)"; |
||||
|
#endif |
||||
|
|
||||
|
timer1.setInterval(1000); |
||||
|
timer1.start(); |
||||
|
connect(&timer1,&QTimer::timeout,[=](){ |
||||
|
m_ledStatus ^= 1; |
||||
|
ledSet(m_ledStatus); |
||||
|
}); |
||||
|
|
||||
|
timer2.setInterval(10); |
||||
|
timer2.start(); |
||||
|
connect(&timer2,&QTimer::timeout,[=](){ |
||||
|
quint8 keyStatus = keyReadOnce(); |
||||
|
if(keyStatus != m_keyStatus){ |
||||
|
m_keyStatus = keyStatus; |
||||
|
qDebug() << "m_keyStatus " << m_keyStatus; |
||||
|
} |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
void DeviceService::ledSet(int status) |
||||
|
{ |
||||
|
#ifdef Q_OS_LINUX |
||||
|
digitalWrite(WIRING_PIN_LED,status == 1 ? LOW : HIGH);//'HIGH'代表高电平,’LOW‘则为低电平
|
||||
|
#else |
||||
|
qDebug() << "LED set: " << status; |
||||
|
#endif |
||||
|
} |
||||
|
|
||||
|
quint8 DeviceService::keyReadOnce() |
||||
|
{ |
||||
|
#ifdef Q_OS_LINUX |
||||
|
return digitalRead(WIRING_PIN_KEY); |
||||
|
#else |
||||
|
qDebug() << "keyReadOnce()"; |
||||
|
return 0; |
||||
|
#endif |
||||
|
} |
||||
|
|
||||
|
//quint8 DeviceService::keyDetection()
|
||||
|
//{
|
||||
|
// key.flag = None; //清空按键标志
|
||||
|
// if ((keyReadOnce() == KEY_Up) && (key.lastState == KEY_Down))
|
||||
|
// {
|
||||
|
// uint16_t i = Click_Overtime;
|
||||
|
// uint16_t j = Press_Overtime;
|
||||
|
// key.flag = Click; //先确定按键标志为单击
|
||||
|
// key.lastState = KEY_Up;
|
||||
|
// //判断是否为长按
|
||||
|
// while ((tls_gpio_read(gpio_pin) == KEY_Up)&&(j--))
|
||||
|
// {
|
||||
|
// //printf("j = %d\r\n", j);
|
||||
|
// if (j == 1)
|
||||
|
// {
|
||||
|
// KEY3.KEY_Flag = Press; //按键标志为长按
|
||||
|
// KEY3.KEY_LastState = KEY_Up;
|
||||
|
// break;
|
||||
|
// }
|
||||
|
// delay_ms(50);
|
||||
|
// }
|
||||
|
// //在确定标志已经为单击的前提下,判断是否为双击
|
||||
|
// if (KEY3.KEY_Flag == Click)
|
||||
|
// {
|
||||
|
// while (i--)
|
||||
|
// {
|
||||
|
// if ((tls_gpio_read(gpio_pin) == KEY_Up))
|
||||
|
// {
|
||||
|
// KEY3.KEY_Flag = Dbl_Click;
|
||||
|
// KEY3.KEY_LastState = KEY_Up;
|
||||
|
// while (tls_gpio_read(gpio_pin) == KEY_Up);
|
||||
|
// break;
|
||||
|
// }
|
||||
|
// delay_ms(50);
|
||||
|
// }
|
||||
|
// }
|
||||
|
// //在确定标志为已经为双击的前提下,判断是否为三击
|
||||
|
// if (KEY3.KEY_Flag == Dbl_Click)
|
||||
|
// {
|
||||
|
// while (i--)
|
||||
|
// {
|
||||
|
// if (tls_gpio_read(gpio_pin) == KEY_Up)
|
||||
|
// {
|
||||
|
// KEY3.KEY_Flag = Tri_Click;
|
||||
|
// KEY3.KEY_LastState = KEY_Up;
|
||||
|
// while (tls_gpio_read(gpio_pin) == KEY_Up);
|
||||
|
// break;
|
||||
|
// }
|
||||
|
// delay_ms(50);
|
||||
|
// }
|
||||
|
// }
|
||||
|
// }
|
||||
|
// //将按键置为松开状态,以供下一次检测
|
||||
|
// if (tls_gpio_read(gpio_pin) == KEY_Down)
|
||||
|
// {
|
||||
|
// KEY3.KEY_LastState = KEY_Down;
|
||||
|
// }
|
||||
|
// return KEY3.KEY_Flag;
|
||||
|
//}
|
@ -0,0 +1,45 @@ |
|||||
|
#ifndef DEVICESERVICE_H |
||||
|
#define DEVICESERVICE_H |
||||
|
|
||||
|
#include <QObject> |
||||
|
#include <QTimer.h> |
||||
|
|
||||
|
typedef enum{ |
||||
|
GPIO_PIN_RESET = 0u, |
||||
|
GPIO_PIN_SET |
||||
|
} GPIO_PinState; |
||||
|
|
||||
|
typedef enum{ |
||||
|
None = (uint8_t)0, |
||||
|
Click = (uint8_t)1, |
||||
|
Dbl_Click = (uint8_t)2, |
||||
|
Tri_Click = (uint8_t)3, |
||||
|
Press = (uint8_t)4, |
||||
|
}KeyFlag; |
||||
|
|
||||
|
#define KEY_Up GPIO_PIN_SET |
||||
|
#define KEY_Down GPIO_PIN_RESET |
||||
|
|
||||
|
typedef struct{ |
||||
|
KeyFlag flag; |
||||
|
quint8 lastState; |
||||
|
}KeyType; |
||||
|
|
||||
|
class DeviceService : public QObject |
||||
|
{ |
||||
|
Q_OBJECT |
||||
|
public: |
||||
|
explicit DeviceService(QObject *parent = 0); |
||||
|
private: |
||||
|
KeyType key; |
||||
|
int m_ledStatus,m_keyStatus; |
||||
|
QTimer timer1,timer2; |
||||
|
signals: |
||||
|
|
||||
|
public slots: |
||||
|
void ledSet(int status); |
||||
|
quint8 keyReadOnce(); |
||||
|
//quint8 keyDetection();
|
||||
|
}; |
||||
|
|
||||
|
#endif // DEVICESERVICE_H
|
@ -0,0 +1,27 @@ |
|||||
|
[MAIN] |
||||
|
;最大患者数量 |
||||
|
maxPatientNum = 5 |
||||
|
;切换病人时间(s) |
||||
|
switchPatientInterval = 5 |
||||
|
|
||||
|
[USER] |
||||
|
;登录用户名 |
||||
|
username = shoufeichu |
||||
|
;登录密码 |
||||
|
password = 123456 |
||||
|
|
||||
|
[HTTP] |
||||
|
;登录请求URL |
||||
|
loginUrl = http://test.tall.wiki/gateway/tall3/v3.0/users/signin |
||||
|
;发送身份证信息URL |
||||
|
sendUserInfoUrl = https://test.tall.wiki/gateway/qcp/v3.0/button/idCardDiscern |
||||
|
;一键启动URL |
||||
|
oneKeyStartUrl = https://test.tall.wiki/gateway/qcp/v3.0/button/buttonStart |
||||
|
;服务状态改变URL(rgb) |
||||
|
serviceStatusChangedUrl = https://test.tall.wiki/gateway/qcp/v3.0/button/updateStatus |
||||
|
|
||||
|
[WEBSOCKET] |
||||
|
;Websocket URL |
||||
|
wsUrl = wss://test.tall.wiki/websocket/message/v4.0/ws |
||||
|
;Websocket心跳间隔(s) |
||||
|
wsHeartInterval = 10 |
Loading…
Reference in new issue