xref: /OK3568_Linux_fs/app/qsetting/qtbt.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 #ifndef QTBT_H
2 #define QTBT_H
3 
4 #include <QDebug>
5 #include <QLabel>
6 #include <QListWidget>
7 #include <QMutex>
8 #include <QPushButton>
9 #include <QProcess>
10 #include <QTextStream>
11 #include <QThread>
12 #include <QTimer>
13 #include <QWidget>
14 #ifdef RKWIFIBTAPP
15 #include <RkBtSource.h>
16 #include <RkBtBase.h>
17 #else
18 
19 typedef enum {
20         RK_BT_STATE_OFF,
21         RK_BT_STATE_ON,
22         RK_BT_STATE_TURNING_ON,
23         RK_BT_STATE_TURNING_OFF,
24 } RK_BT_STATE;
25 
26 typedef enum {
27         RK_BT_BOND_STATE_NONE,
28         RK_BT_BOND_STATE_BONDING,
29         RK_BT_BOND_STATE_BONDED,
30 } RK_BT_BOND_STATE;
31 
32 typedef enum {
33         RK_BT_DISC_STARTED,
34         RK_BT_DISC_STOPPED_AUTO,
35         RK_BT_DISC_START_FAILED,
36         RK_BT_DISC_STOPPED_BY_USER,
37 } RK_BT_DISCOVERY_STATE;
38 
39 typedef enum {
40         BT_SOURCE_EVENT_CONNECT_FAILED,
41         BT_SOURCE_EVENT_CONNECTED,
42         BT_SOURCE_EVENT_DISCONNECTED,
43         BT_SOURCE_EVENT_RC_PLAY,    /* remote control command */
44         BT_SOURCE_EVENT_RC_STOP,
45         BT_SOURCE_EVENT_RC_PAUSE,
46         BT_SOURCE_EVENT_RC_FORWARD,
47         BT_SOURCE_EVENT_RC_BACKWARD,
48         BT_SOURCE_EVENT_RC_VOL_UP,
49         BT_SOURCE_EVENT_RC_VOL_DOWN,
50 } RK_BT_SOURCE_EVENT;
51 #endif
52 
53 class qtBT : public QListWidget
54 {
55     Q_OBJECT
56     struct bt_dev_info{
57         const char *address;
58         const char *name;
59         unsigned int bt_class;
60         int rssi;
61     };
62 public:
63     qtBT(QWidget *parent = nullptr, QLabel *label = nullptr, QPushButton *btn = nullptr, bool on = false);
64     ~qtBT();
65     static qtBT* getInstance(QWidget *parent = nullptr, QLabel *label = nullptr, QPushButton *btn = nullptr, bool on = false)
66     {
67         if (!_instance) {
68             _instance = new qtBT(parent, label, btn, on);
69         }
70         return _instance;
71     }
72     static void state_cb(RK_BT_STATE state);
73     static void bond_cb(const char *bd_addr, const char *name, RK_BT_BOND_STATE state);
74     static void scan_status_cb(RK_BT_DISCOVERY_STATE status);
75     static void source_connect_cb(void *userdata, const char *bd_addr, const char *name, const RK_BT_SOURCE_EVENT enEvent);
76     static void scan_cb(const char *address,const char *name, unsigned int bt_class, int rssi, int change);
77     void open();
78     void close();
79     bool isOn();
80     void turnOn();
81     void turnOff();
82 
83 public slots:
84     void on_btnClicked();
85     void on_itemClicked(QListWidgetItem *item);
86 private:
87 #ifdef RKWIFIBTAPP
88     RkBtContent bt_content;
89 #endif
90     QList<struct bt_dev_info*> dev_list;
91     QMutex btmutex;
92     static class qtBT* _instance;
93     QLabel *text;
94     QPushButton *switchBtn;
95 };
96 
97 #endif // QTBT_H
98