Skip to content

Commit cf8ca3a

Browse files
authored
Merge pull request #35 from zRCrackiiN/main
Platform.io Integration
2 parents 84f52fb + 8882747 commit cf8ca3a

20 files changed

+2146
-0
lines changed

VScode Platformio/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.pio
2+
.vscode/.browse.c_cpp.db*
3+
.vscode/c_cpp_properties.json
4+
.vscode/launch.json
5+
.vscode/ipch
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
// See http://go.microsoft.com/fwlink/?LinkId=827846
3+
// for the documentation about the extensions.json format
4+
"recommendations": [
5+
"platformio.platformio-ide"
6+
],
7+
"unwantedRecommendations": [
8+
"ms-vscode.cpptools-extension-pack"
9+
]
10+
}

VScode Platformio/include/README

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
This directory is intended for project header files.
3+
4+
A header file is a file containing C declarations and macro definitions
5+
to be shared between several project source files. You request the use of a
6+
header file in your project source file (C, C++, etc) located in `src` folder
7+
by including it, with the C preprocessing directive `#include'.
8+
9+
```src/main.c
10+
11+
#include "header.h"
12+
13+
int main (void)
14+
{
15+
...
16+
}
17+
```
18+
19+
Including a header file produces the same results as copying the header file
20+
into each source file that needs it. Such copying would be time-consuming
21+
and error-prone. With a header file, the related declarations appear
22+
in only one place. If they need to be changed, they can be changed in one
23+
place, and programs that include the header file will automatically use the
24+
new version when next recompiled. The header file eliminates the labor of
25+
finding and changing all the copies as well as the risk that a failure to
26+
find one copy will result in inconsistencies within a program.
27+
28+
In C, the usual convention is to give header files names that end with `.h'.
29+
It is most portable to use only letters, digits, dashes, and underscores in
30+
header file names, and at most one dot.
31+
32+
Read more about using header files in official GCC documentation:
33+
34+
* Include Syntax
35+
* Include Operation
36+
* Once-Only Headers
37+
* Computed Includes
38+
39+
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html

VScode Platformio/lib/README

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
2+
This directory is intended for project specific (private) libraries.
3+
PlatformIO will compile them to static libraries and link into executable file.
4+
5+
The source code of each library should be placed in an own separate directory
6+
("lib/your_library_name/[here are source files]").
7+
8+
For example, see a structure of the following two libraries `Foo` and `Bar`:
9+
10+
|--lib
11+
| |
12+
| |--Bar
13+
| | |--docs
14+
| | |--examples
15+
| | |--src
16+
| | |- Bar.c
17+
| | |- Bar.h
18+
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
19+
| |
20+
| |--Foo
21+
| | |- Foo.c
22+
| | |- Foo.h
23+
| |
24+
| |- README --> THIS FILE
25+
|
26+
|- platformio.ini
27+
|--src
28+
|- main.c
29+
30+
and a contents of `src/main.c`:
31+
```
32+
#include <Foo.h>
33+
#include <Bar.h>
34+
35+
int main (void)
36+
{
37+
...
38+
}
39+
40+
```
41+
42+
PlatformIO Library Dependency Finder will find automatically dependent
43+
libraries scanning project source files.
44+
45+
More information about PlatformIO Library Dependency Finder
46+
- https://docs.platformio.org/page/librarymanager/ldf.html

VScode Platformio/platformio.ini

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
; PlatformIO Project Configuration File
2+
;
3+
; Build options: build flags, source filter
4+
; Upload options: custom upload port, speed and extra flags
5+
; Library options: dependencies, extra library storages
6+
; Advanced options: extra scripting
7+
;
8+
; Please visit documentation for the other options and examples
9+
; https://docs.platformio.org/page/projectconf.html
10+
11+
[env:esp32dev]
12+
platform = espressif32
13+
board = esp32dev
14+
framework = arduino
15+
lib_deps =
16+
nrf24/RF24@^1.4.10
17+
olikraus/U8g2@^2.36.2
18+
adafruit/Adafruit NeoPixel@^1.12.3
19+
board_build.partitions = min_spiffs.csv

VScode Platformio/src/analyzer.cpp

Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
/* ____________________________
2+
This software is licensed under the MIT License:
3+
https://github.com/cifertech/nrfbox
4+
________________________________________ */
5+
6+
#include <Arduino.h>
7+
#include "analyzer.h"
8+
9+
extern U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2;
10+
11+
#define NRF24_CONFIG 0x00
12+
#define NRF24_EN_AA 0x01
13+
#define NRF24_RF_CH 0x05
14+
#define NRF24_RF_SETUP 0x06
15+
#define NRF24_RPD 0x09
16+
17+
#define SCREEN_WIDTH 128
18+
#define SCREEN_HEIGHT 64
19+
20+
#define N 128
21+
uint8_t values[N];
22+
23+
#define CE 5
24+
#define CSN 17
25+
26+
#define CHANNELS 64
27+
int CHannel[CHANNELS];
28+
29+
30+
byte getregister(byte r) {
31+
byte c;
32+
33+
digitalWrite(CSN, LOW);
34+
SPI.transfer(r & 0x1F);
35+
c = SPI.transfer(0);
36+
digitalWrite(CSN, HIGH);
37+
38+
return c;
39+
}
40+
41+
void setregister(byte r, byte v) {
42+
digitalWrite(CSN, LOW);
43+
SPI.transfer((r & 0x1F) | 0x20);
44+
SPI.transfer(v);
45+
digitalWrite(CSN, HIGH);
46+
}
47+
48+
void powerup(void) {
49+
setregister(NRF24_CONFIG, getregister(NRF24_CONFIG) | 0x02);
50+
delayMicroseconds(130);
51+
}
52+
53+
void powerdown(void) {
54+
setregister(NRF24_CONFIG, getregister(NRF24_CONFIG) & ~0x02);
55+
}
56+
57+
void ENable(void) {
58+
digitalWrite(CE, HIGH);
59+
}
60+
61+
void DIsable(void) {
62+
digitalWrite(CE, LOW);
63+
}
64+
65+
void setrx(void) {
66+
setregister(NRF24_CONFIG, getregister(NRF24_CONFIG) | 0x01);
67+
ENable();
68+
delayMicroseconds(100);
69+
}
70+
71+
void ScanChannels(void) {
72+
DIsable();
73+
// for (int j = 0; j < 10; j++) {
74+
for (int i = 0; i < CHANNELS; i++) {
75+
setregister(NRF24_RF_CH, (128 * i) / CHANNELS);
76+
setrx();
77+
delayMicroseconds(40);
78+
DIsable();
79+
if (getregister(NRF24_RPD) > 0) CHannel[i]++;
80+
}
81+
// }
82+
}
83+
84+
85+
void writeRegister(uint8_t reg, uint8_t value) {
86+
digitalWrite(CSN, LOW);
87+
SPI.transfer(reg | 0x20);
88+
SPI.transfer(value);
89+
digitalWrite(CSN, HIGH);
90+
}
91+
92+
uint8_t readRegister(uint8_t reg) {
93+
digitalWrite(CSN, LOW);
94+
SPI.transfer(reg & 0x1F);
95+
uint8_t result = SPI.transfer(0x00);
96+
digitalWrite(CSN, HIGH);
97+
return result;
98+
}
99+
100+
void setChannel(uint8_t CHannel) {
101+
writeRegister(NRF24_RF_CH, CHannel);
102+
}
103+
104+
void powerUP() {
105+
uint8_t config = readRegister(NRF24_CONFIG);
106+
writeRegister(NRF24_CONFIG, config | 0x02);
107+
delay(5);
108+
}
109+
110+
void powerDOWN() {
111+
uint8_t config = readRegister(NRF24_CONFIG);
112+
writeRegister(NRF24_CONFIG, config & ~0x02);
113+
}
114+
115+
void startListening() {
116+
digitalWrite(CE, HIGH);
117+
}
118+
119+
void stopListening() {
120+
digitalWrite(CE, LOW);
121+
}
122+
123+
bool carrierDetected() {
124+
return readRegister(NRF24_RPD) & 0x01;
125+
}
126+
127+
128+
void analyzerSetup(){
129+
130+
Serial.begin(115200);
131+
132+
esp_bt_controller_deinit();
133+
esp_wifi_stop();
134+
esp_wifi_deinit();
135+
136+
pinMode(CE, OUTPUT);
137+
pinMode(CSN, OUTPUT);
138+
139+
SPI.begin(18, 19, 23, 17);
140+
SPI.setDataMode(SPI_MODE0);
141+
SPI.setFrequency(10000000);
142+
SPI.setBitOrder(MSBFIRST);
143+
144+
u8g2.begin();
145+
u8g2.clearBuffer();
146+
u8g2.sendBuffer();
147+
148+
digitalWrite(CSN, HIGH);
149+
digitalWrite(CE, LOW);
150+
151+
DIsable();
152+
153+
powerUP();
154+
writeRegister(NRF24_EN_AA, 0x00);
155+
writeRegister(NRF24_RF_SETUP, 0x0F);
156+
157+
}
158+
159+
void analyzerLoop(){
160+
161+
ScanChannels();
162+
163+
memset(values, 0, sizeof(values));
164+
165+
int n = 50;
166+
while (n--) {
167+
int i = N;
168+
while (i--) {
169+
setChannel(i);
170+
startListening();
171+
delayMicroseconds(128);
172+
stopListening();
173+
if (carrierDetected()) {
174+
++values[i];
175+
}
176+
}
177+
}
178+
179+
u8g2.clearBuffer();
180+
int barWidth = SCREEN_WIDTH / N;
181+
int x = 0;
182+
for (int i = 0; i < N; ++i) {
183+
int v = 63 - values[i] * 3;
184+
if (v < 0) {
185+
v = 0;
186+
}
187+
u8g2.drawVLine(x, v - 10, 64 - v);
188+
x += barWidth;
189+
}
190+
191+
u8g2.setFont(u8g2_font_ncenB08_tr);
192+
u8g2.setCursor(0, 64);
193+
u8g2.print("1...5...10...25..50...80...128");
194+
u8g2.sendBuffer();
195+
196+
delay(50);
197+
198+
}

VScode Platformio/src/analyzer.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/* ____________________________
2+
This software is licensed under the MIT License:
3+
https://github.com/cifertech/nrfbox
4+
________________________________________ */
5+
6+
#ifndef analyzer_H
7+
#define analyzer_H
8+
9+
#include <SPI.h>
10+
#include <U8g2lib.h>
11+
#include "esp_bt.h"
12+
#include "esp_wifi.h"
13+
14+
void analyzerSetup();
15+
void analyzerLoop();
16+
17+
#endif

0 commit comments

Comments
 (0)