-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppBleScanner.cpp
More file actions
127 lines (100 loc) · 3.13 KB
/
Copy pathAppBleScanner.cpp
File metadata and controls
127 lines (100 loc) · 3.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
//
// Created by johan on 26.05.2026.
//
#include "AppBleScanner.h"
void AppBleScanner::initExtend() {
_resultList.init(*_tft, _colorOn, _colorOff, _colorText);
/*
// TODO: Start instance if start this application
BLEDevice::init("");
pBLEScan = BLEDevice::getScan(); //create new scan
pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks());
pBLEScan->setActiveScan(true); //active scan uses more power, but get results faster
pBLEScan->setInterval(100);
pBLEScan->setWindow(99); // less or equal setInterval value
*/
_applicationName = "BLE Scanner";
}
void AppBleScanner::drawUpdate() {
_resultList.drawUpdate();
if (_hasDraw) {
return;
}
drawScanInfo();
_hasDraw = true;
}
void AppBleScanner::reset() {
_hasDraw = false;
_tft->clearBuffer(_tft->C_BLACK);
}
void AppBleScanner::setButton1() {
_resultList.setButton1();
}
void AppBleScanner::drawScanInfo() {
_tft->setFont(FontDefault);
_tft->setTextColor(_colorOn, _tft->C_BLACK);
int countFindings = _resultList.GetCountFindings();
int posX = 40;
int posY = 45;
_tft->setCursor(posX, posY);
_tft->print("Bluetooth Found: ");
char buffer[12];
sprintf(buffer, "%d", countFindings);
_tft->print(buffer);
}
void AppBleScanner::scan() {
int posX = 80;
int posY = 25;
_tft->fillScreen(_tft->C_BLACK);
_tft->setFont(FontDefault);
_tft->setTextColor(_colorOn, _tft->C_BLACK);
_tft->setCursor(posX, posY);
_tft->print("Scan Start");
_tft->writeBuffer();
/*
BLEScanResults* foundDevices = pBLEScan->start(scanTime, false);
int n = foundDevices->getCount();
*/
BleScanResult scanResult = _bleManager->scan(2);
_tft->setCursor(posX, posY);
_tft->print("Scan Done ");
_tft->writeBuffer();
_tft->setCursor(posX, posY + 20);
if (scanResult.CountDevice == 0) {
_tft->print("No Bluetooth");
_tft->writeBuffer();
return;
}
_tft->setCursor(10, 100);
for (int i = 0; i < scanResult.CountDevice; i++) {
/*
BLEAdvertisedDevice device = foundDevices->getDevice(i);
BleItem* item = new BleItem;
item->Name = device.getName().c_str();
item->Address = device.getAddress().toString().c_str();
item->HasDevUUID = false;
if (device.haveServiceUUID()) {
BLEUUID devUUID = device.getServiceUUID();
item->DevUUID = devUUID.toString().c_str();
item->HasDevUUID = true;
}
item->HasManufacturerData = false;
if (device.haveManufacturerData()) {
item->HasManufacturerData = true;
item->ManufacturerData = device.getManufacturerData().c_str();
}
item->Rssi = device.getRSSI();
*/
BleItem* item =_bleManager->getBleItem(i);
_resultList.addItem(item);
_tft->drawFastHLine(50, 118, i, _colorOn);
_tft->drawFastHLine(50, 119, i, _colorOn);
_tft->drawFastHLine(50, 120, i, _colorOn);
_tft->writeBuffer();
}
}
void AppBleScanner::setButton2() {
_resultList.setButton2();
scan();
_hasDraw = false;
}