Skip to content

Commit 7797849

Browse files
committed
Migrate to v2 of ESP32 core.
1 parent 8a21d89 commit 7797849

File tree

10 files changed

+590
-21
lines changed

10 files changed

+590
-21
lines changed

Firmware/RTK_Surveyor/Begin.ino

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ void beginSD()
161161
//Max current is 200mA average across 1s, peak 300mA
162162
delay(10);
163163

164-
if (sd.begin(SdSpiConfig(pin_microSD_CS, DEDICATED_SPI, SD_SCK_MHZ(settings.spiFrequency), &spi)) == false)
164+
// if (sd.begin(SdSpiConfig(pin_microSD_CS, DEDICATED_SPI, SD_SCK_MHZ(settings.spiFrequency))) == false)
165+
if (sd.begin(SdSpiConfig(pin_microSD_CS, SHARED_SPI, SD_SCK_MHZ(settings.spiFrequency))) == false)
165166
{
166167
int tries = 0;
167168
int maxTries = 2;
@@ -170,7 +171,8 @@ void beginSD()
170171
Serial.printf("SD init failed. Trying again %d out of %d\n\r", tries + 1, maxTries);
171172

172173
delay(250); //Give SD more time to power up, then try again
173-
if (sd.begin(SdSpiConfig(pin_microSD_CS, DEDICATED_SPI, SD_SCK_MHZ(settings.spiFrequency), &spi)) == true) break;
174+
// if (sd.begin(SdSpiConfig(pin_microSD_CS, DEDICATED_SPI, SD_SCK_MHZ(settings.spiFrequency))) == true) break;
175+
if (sd.begin(SdSpiConfig(pin_microSD_CS, SHARED_SPI, SD_SCK_MHZ(settings.spiFrequency))) == true) break;
174176
}
175177

176178
if (tries == maxTries)

Firmware/RTK_Surveyor/RTK_Surveyor.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
and communicates with the ZED-F9P.
88
99
Compiled with Arduino v1.8.13 with ESP32 core v1.0.6.
10+
v1.7 Moves to ESP32 core v2.0.0.
1011
1112
Select the ESP32 Dev Module from the boards list. This maps the same pins to the ESP32-WROOM module.
1213
Select 'Minimal SPIFFS (1.9MB App)' from the partition list. This will enable SD firmware updates.
@@ -45,7 +46,7 @@ const int FIRMWARE_VERSION_MINOR = 7;
4546

4647
#define COMPILE_WIFI //Comment out to remove all WiFi functionality
4748
#define COMPILE_BT //Comment out to disable all Bluetooth
48-
//#define ENABLE_DEVELOPER //Uncomment this line to enable special developer modes (don't check power button at startup)
49+
#define ENABLE_DEVELOPER //Uncomment this line to enable special developer modes (don't check power button at startup)
4950

5051
//Define the RTK board identifier:
5152
// This is an int which is unique to this variant of the RTK Surveyor hardware which allows us
@@ -106,7 +107,6 @@ ESP32Time rtc;
106107
#include "SdFat.h"
107108

108109
SdFat sd;
109-
SPIClass spi = SPIClass(VSPI); //We need to pass the class into SD.begin so we can set the SPI freq in beginSD()
110110

111111
char platformFilePrefix[40] = "SFE_Surveyor"; //Sets the prefix for logs and settings files
112112

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/*
2+
* BTAddress.cpp
3+
*
4+
* Created on: Jul 2, 2017
5+
* Author: kolban
6+
* Ported on: Feb 5, 2021
7+
* Author: Thomas M. (ArcticSnowSky)
8+
*/
9+
#include "sdkconfig.h"
10+
#if defined(CONFIG_BT_ENABLED)
11+
12+
#include "BTAddress.h"
13+
#include <string>
14+
#include <sstream>
15+
#include <iomanip>
16+
#include <string.h>
17+
#include <stdio.h>
18+
#include <malloc.h>
19+
#ifdef ARDUINO_ARCH_ESP32
20+
#include "esp32-hal-log.h"
21+
#endif
22+
23+
24+
/**
25+
* @brief Create an address from the native ESP32 representation.
26+
* @param [in] address The native representation.
27+
*/
28+
BTAddress::BTAddress(esp_bd_addr_t address) {
29+
memcpy(m_address, address, ESP_BD_ADDR_LEN);
30+
} // BTAddress
31+
32+
33+
/**
34+
* @brief Create an address from a hex string
35+
*
36+
* A hex string is of the format:
37+
* ```
38+
* 00:00:00:00:00:00
39+
* ```
40+
* which is 17 characters in length.
41+
*
42+
* @param [in] stringAddress The hex representation of the address.
43+
*/
44+
BTAddress::BTAddress(std::string stringAddress) {
45+
if (stringAddress.length() != 17) return;
46+
47+
int data[6];
48+
sscanf(stringAddress.c_str(), "%x:%x:%x:%x:%x:%x", &data[0], &data[1], &data[2], &data[3], &data[4], &data[5]);
49+
m_address[0] = (uint8_t) data[0];
50+
m_address[1] = (uint8_t) data[1];
51+
m_address[2] = (uint8_t) data[2];
52+
m_address[3] = (uint8_t) data[3];
53+
m_address[4] = (uint8_t) data[4];
54+
m_address[5] = (uint8_t) data[5];
55+
} // BTAddress
56+
57+
58+
/**
59+
* @brief Determine if this address equals another.
60+
* @param [in] otherAddress The other address to compare against.
61+
* @return True if the addresses are equal.
62+
*/
63+
bool BTAddress::equals(BTAddress otherAddress) {
64+
return memcmp(otherAddress.getNative(), m_address, 6) == 0;
65+
} // equals
66+
67+
68+
/**
69+
* @brief Return the native representation of the address.
70+
* @return The native representation of the address.
71+
*/
72+
esp_bd_addr_t *BTAddress::getNative() {
73+
return &m_address;
74+
} // getNative
75+
76+
77+
/**
78+
* @brief Convert a BT address to a string.
79+
*
80+
* A string representation of an address is in the format:
81+
*
82+
* ```
83+
* xx:xx:xx:xx:xx:xx
84+
* ```
85+
*
86+
* @return The string representation of the address.
87+
*/
88+
std::string BTAddress::toString() {
89+
auto size = 18;
90+
char *res = (char*)malloc(size);
91+
snprintf(res, size, "%02x:%02x:%02x:%02x:%02x:%02x", m_address[0], m_address[1], m_address[2], m_address[3], m_address[4], m_address[5]);
92+
std::string ret(res);
93+
free(res);
94+
return ret;
95+
} // toString
96+
#endif
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* BTAddress.h
3+
*
4+
* Created on: Jul 2, 2017
5+
* Author: kolban
6+
* Ported on: Feb 5, 2021
7+
* Author: Thomas M. (ArcticSnowSky)
8+
*/
9+
10+
#ifndef COMPONENTS_CPP_UTILS_BTADDRESS_H_
11+
#define COMPONENTS_CPP_UTILS_BTADDRESS_H_
12+
#include "sdkconfig.h"
13+
#if defined(CONFIG_BT_ENABLED)
14+
#include <esp_gap_bt_api.h> // ESP32 BT
15+
#include <string>
16+
17+
18+
/**
19+
* @brief A %BT device address.
20+
*
21+
* Every %BT device has a unique address which can be used to identify it and form connections.
22+
*/
23+
class BTAddress {
24+
public:
25+
BTAddress(esp_bd_addr_t address);
26+
BTAddress(std::string stringAddress);
27+
bool equals(BTAddress otherAddress);
28+
esp_bd_addr_t* getNative();
29+
std::string toString();
30+
31+
private:
32+
esp_bd_addr_t m_address;
33+
};
34+
35+
#endif /* CONFIG_BT_ENABLED */
36+
#endif /* COMPONENTS_CPP_UTILS_BTADDRESS_H_ */
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* BTAdvertisedDevice.h
3+
*
4+
* Created on: Feb 5, 2021
5+
* Author: Thomas M. (ArcticSnowSky)
6+
*/
7+
8+
#ifndef __BTADVERTISEDDEVICE_H__
9+
#define __BTADVERTISEDDEVICE_H__
10+
11+
#include "BTAddress.h"
12+
13+
14+
class BTAdvertisedDevice {
15+
public:
16+
virtual ~BTAdvertisedDevice() = default;
17+
18+
virtual BTAddress getAddress();
19+
virtual uint32_t getCOD();
20+
virtual std::string getName();
21+
virtual int8_t getRSSI();
22+
23+
24+
virtual bool haveCOD();
25+
virtual bool haveName();
26+
virtual bool haveRSSI();
27+
28+
virtual std::string toString();
29+
};
30+
31+
class BTAdvertisedDeviceSet : public virtual BTAdvertisedDevice {
32+
public:
33+
BTAdvertisedDeviceSet();
34+
//~BTAdvertisedDeviceSet() = default;
35+
36+
37+
BTAddress getAddress();
38+
uint32_t getCOD();
39+
std::string getName();
40+
int8_t getRSSI();
41+
42+
43+
bool haveCOD();
44+
bool haveName();
45+
bool haveRSSI();
46+
47+
std::string toString();
48+
49+
void setAddress(BTAddress address);
50+
void setCOD(uint32_t cod);
51+
void setName(std::string name);
52+
void setRSSI(int8_t rssi);
53+
54+
bool m_haveCOD;
55+
bool m_haveName;
56+
bool m_haveRSSI;
57+
58+
59+
BTAddress m_address = BTAddress((uint8_t*)"\0\0\0\0\0\0");
60+
uint32_t m_cod;
61+
std::string m_name;
62+
int8_t m_rssi;
63+
};
64+
65+
#endif
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* BTAdvertisedDeviceSet.cpp
3+
*
4+
* Created on: Feb 5, 2021
5+
* Author: Thomas M. (ArcticSnowSky)
6+
*/
7+
8+
#include "sdkconfig.h"
9+
#if defined(CONFIG_BT_ENABLED)
10+
11+
//#include <map>
12+
13+
#include "BTAdvertisedDevice.h"
14+
//#include "BTScan.h"
15+
16+
17+
BTAdvertisedDeviceSet::BTAdvertisedDeviceSet() {
18+
m_cod = 0;
19+
m_name = "";
20+
m_rssi = 0;
21+
22+
m_haveCOD = false;
23+
m_haveName = false;
24+
m_haveRSSI = false;
25+
} // BTAdvertisedDeviceSet
26+
27+
BTAddress BTAdvertisedDeviceSet::getAddress() { return m_address; }
28+
uint32_t BTAdvertisedDeviceSet::getCOD() { return m_cod; }
29+
std::string BTAdvertisedDeviceSet::getName() { return m_name; }
30+
int8_t BTAdvertisedDeviceSet::getRSSI() { return m_rssi; }
31+
32+
33+
bool BTAdvertisedDeviceSet::haveCOD() { return m_haveCOD; }
34+
bool BTAdvertisedDeviceSet::haveName() { return m_haveName; }
35+
bool BTAdvertisedDeviceSet::haveRSSI() { return m_haveRSSI; }
36+
37+
/**
38+
* @brief Create a string representation of this device.
39+
* @return A string representation of this device.
40+
*/
41+
std::string BTAdvertisedDeviceSet::toString() {
42+
std::string res = "Name: " + getName() + ", Address: " + getAddress().toString();
43+
if (haveCOD()) {
44+
char val[6];
45+
snprintf(val, sizeof(val), "%d", getCOD());
46+
res += ", cod: ";
47+
res += val;
48+
}
49+
if (haveRSSI()) {
50+
char val[6];
51+
snprintf(val, sizeof(val), "%d", (int8_t)getRSSI());
52+
res += ", rssi: ";
53+
res += val;
54+
}
55+
return res;
56+
} // toString
57+
58+
59+
void BTAdvertisedDeviceSet::setAddress(BTAddress address) {
60+
m_address = address;
61+
}
62+
63+
void BTAdvertisedDeviceSet::setCOD(uint32_t cod) {
64+
m_cod = cod;
65+
m_haveCOD = true;
66+
}
67+
68+
void BTAdvertisedDeviceSet::setName(std::string name) {
69+
m_name = name;
70+
m_haveName = true;
71+
}
72+
73+
void BTAdvertisedDeviceSet::setRSSI(int8_t rssi) {
74+
m_rssi = rssi;
75+
m_haveRSSI = true;
76+
}
77+
78+
#endif /* CONFIG_BT_ENABLED */
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* BTScan.h
3+
*
4+
* Created on: Feb 5, 2021
5+
* Author: Thomas M. (ArcticSnowSky)
6+
*/
7+
8+
#ifndef __BTSCAN_H__
9+
#define __BTSCAN_H__
10+
11+
#include <map>
12+
#include <string>
13+
#include <Print.h>
14+
#include "BTAddress.h"
15+
#include "BTAdvertisedDevice.h"
16+
17+
class BTAdvertisedDevice;
18+
class BTAdvertisedDeviceSet;
19+
20+
21+
class BTScanResults {
22+
public:
23+
virtual ~BTScanResults() = default;
24+
25+
virtual void dump(Print *print = nullptr);
26+
virtual int getCount();
27+
virtual BTAdvertisedDevice* getDevice(uint32_t i);
28+
};
29+
30+
class BTScanResultsSet : public BTScanResults {
31+
public:
32+
void dump(Print *print = nullptr);
33+
int getCount();
34+
BTAdvertisedDevice* getDevice(uint32_t i);
35+
36+
bool add(BTAdvertisedDeviceSet advertisedDevice, bool unique = true);
37+
void clear();
38+
39+
std::map<std::string, BTAdvertisedDeviceSet> m_vectorAdvertisedDevices;
40+
};
41+
42+
#endif

0 commit comments

Comments
 (0)