-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppBleScannerResultList.cpp
More file actions
125 lines (102 loc) · 3.18 KB
/
Copy pathAppBleScannerResultList.cpp
File metadata and controls
125 lines (102 loc) · 3.18 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
//
// Created by johan on 26.05.2026.
//
#include "AppBleScannerResultList.h"
#include <memory>
#include <vector>
#include "GC9A01_LTSM.hpp"
float AppBleScannerResultList::calculateDistance(const int rssi, const int txPower) {
float pathLossExponent = 2.5; // Anpassen an deine Umgebung!
return pow(10.0, static_cast<float>(txPower - rssi) / (10 * pathLossExponent));
}
void AppBleScannerResultList::drawItems() {
if (!_items) {
return;
}
int posX = 25;
int posY = 60;
int countFindings = static_cast<int>(_items->size());
_tft->setFont(FontDefault);
_tft->setTextColor(_colorOn, _tft->C_BLACK);
_tft->setCursor(70, 190);
_tft->print("Page: ");
char buffer[12];
sprintf(buffer, "%d", (_page + 1));
_tft->print(buffer);
_tft->print(" / ");
sprintf(buffer, "%d", (_pageCount + 1));
_tft->print(buffer);
bool hasDrawItems = false;
for (int i = 0; i < _itemsPerPage; i++) {
int wlanItemIndex = _page * _itemsPerPage + i;
if (wlanItemIndex >= countFindings) {
break;
}
drawItem(posX, posY, i, wlanItemIndex);
hasDrawItems = true;
}
if (!hasDrawItems) {
_tft->drawRoundRect(posX, posY, 190, 30, 5, _tft->C_RED);
_tft->setTextColor(_tft->C_RED, _tft->C_BLACK);
_tft->setCursor(posX + 4, posY + 4);
_tft->print("No other Bluetooth");
_tft->setCursor(posX + 4, posY + 19);
_tft->print("networks found.");
}
}
void AppBleScannerResultList::drawItem(const int16_t x, const int16_t y, const int16_t index, const int16_t itemIndex) {
BleItem* item = (*_items)[itemIndex];
const int16_t posY = y + 30 * index;
if (item->HasDevUUID) {
_tft->drawCircle(x + 195, posY + 7, 2, _tft->C_YELLOW);
}
if (item->HasManufacturerData) {
_tft->drawCircle(x + 195, posY + 15, 2, _tft->C_GREEN);
}
_tft->drawRoundRect(x, posY, 190, 30, 5, _colorOff);
int textPosX = x + 4;
int textPosY = posY + 4;
_tft->setCursor(textPosX, textPosY);
_tft->print(item->Name.c_str());
textPosY += 15;
_tft->setCursor(textPosX, textPosY);
//_tft->print(item->Address.c_str());
float distance = calculateDistance(item->Rssi, _txPower);
char buffer[10];
sprintf(buffer, "%02d", static_cast<int>(distance));
_tft->print("Distance: ");
_tft->print(buffer);
_tft->print("m");
_tft->setCursor(textPosX + 110, textPosY);
_tft->print("RSSI: ");
sprintf(buffer, "%02d", item->Rssi);
}
void AppBleScannerResultList::addItem(BleItem *item) {
if (!_items) {
_items = std::make_unique<std::vector<BleItem*>>();
}
_items->push_back(item);
_pageCount = static_cast<int>(_items->size()) / _itemsPerPage;
}
void AppBleScannerResultList::drawUpdate() {
if (_hasDraw) {
return;
}
_tft->fillRect(0, 55, 240, 135, _tft->C_BLACK);
drawItems();
_hasDraw = true;
}
void AppBleScannerResultList::setButton2() {
_items.reset();
_pageCount = 0;
_page = 0;
_hasDraw = false;
}
void AppBleScannerResultList::setButton1() {
_hasDraw = false;
if (_page < _pageCount) {
_page++;
return;
}
_page = 0;
}