Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into feature/new-can
Browse files Browse the repository at this point in the history
  • Loading branch information
thankthemaker committed Nov 9, 2022
2 parents 0c5cf8f + 575aef4 commit 3f969e2
Show file tree
Hide file tree
Showing 16 changed files with 200 additions and 189 deletions.
4 changes: 2 additions & 2 deletions src/AppConfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ void AppConfiguration::readPreferences() {
config.lightFadingDuration = doc["lightFadingDuration"] | 220;
config.lightMaxBrightness = doc["lightMaxBrightness"] | MAX_BRIGHTNESS;
config.brakeLightEnabled = doc["brakeLightEnabled"] | true;
config.authToken = doc["authToken"] | BLYNK_AUTH_TOKEN;
#if defined(CANBUS_ENABLED)
config.vescId = doc["vescId"] | VESC_CAN_ID;
#endif
config.numberPixelLight = doc["numberPixelLight"] | NUMPIXELS;
config.numberPixelBatMon = doc["numberPixelBatMon"] | LIGHT_BAR_NUMPIXELS;
// calculate RGB values for primary and secondary color
Expand Down Expand Up @@ -88,7 +89,6 @@ void AppConfiguration::savePreferences() {
doc["lightFadingDuration"] = config.lightFadingDuration;
doc["lightMaxBrightness"] = config.lightMaxBrightness;
doc["brakeLightEnabled"] = config.brakeLightEnabled;
doc["authToken"] = config.authToken;
doc["vescId"] = config.vescId;
doc["numberPixelLight"] = config.numberPixelLight;
doc["numberPixelBatMon"] = config.numberPixelBatMon;
Expand Down
7 changes: 2 additions & 5 deletions src/BatteryMonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,9 @@ int batteryReadings[numBatReadings]; // the batteryReadings from the analog in
double currentReadings[numCurReadings];


BatteryMonitor::BatteryMonitor() {}
#ifdef CANBUS_ENABLED
BatteryMonitor::BatteryMonitor(CanBus::VescData *vescData) {
BatteryMonitor::BatteryMonitor(VescData *vescData) {
this->vescData = vescData;
}
#endif


void BatteryMonitor::init() {
Expand All @@ -44,7 +41,7 @@ float BatteryMonitor::readValues() {
int adc = smoothAnalogReading(); // read the sensor and smooth the value
float sensorValue = ( adc * 3.3 ) / (4096); // calculate the voltage at the ESP32 GPIO
float voltage = sensorValue * VOLTAGE_DIVIDER_CONSTANT; // calculate the battery voltage
voltage = vescData->inputVoltage + AppConfiguration::getInstance()->config.batteryDrift;
voltage = voltage+ AppConfiguration::getInstance()->config.batteryDrift;
#else
float voltage = vescData->inputVoltage;
float current = abs(vescData->current);
Expand Down
9 changes: 2 additions & 7 deletions src/BatteryMonitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@

class BatteryMonitor {
public:
BatteryMonitor();
#ifdef CANBUS_ENABLED
BatteryMonitor(CanBus::VescData *vescData);
#endif
BatteryMonitor(VescData *vescData);
void init();
float readValues();
void checkValues();
Expand All @@ -26,9 +23,7 @@ class BatteryMonitor {
int max_voltage = 0;
int warn_voltage = 0;
double max_current = 0;
#ifdef CANBUS_ENABLED
CanBus::VescData *vescData;
#endif
VescData *vescData;
int smoothAnalogReading();
void updateCurrentArray(double value);
double getAverageCurrent();
Expand Down
2 changes: 2 additions & 0 deletions src/BleCanProxy.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "BleCanProxy.h"

#if defined(CANBUS_ENABLED)
BleCanProxy::BleCanProxy(CanDevice *candevice, Stream *stream, uint8_t vesc_id, uint8_t ble_proxy_can_id) {
this->candevice = candevice;
this->stream = stream;
Expand Down Expand Up @@ -179,3 +180,4 @@ void BleCanProxy::proxyOut(uint8_t *data, unsigned int size, uint8_t crc1, uint8

//Serial.println("");
}
#endif
12 changes: 9 additions & 3 deletions src/BleServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,11 @@ void BleServer::onMTUChange(uint16_t MTU, ble_gap_conn_desc* desc) {
BLE_PACKET_SIZE = MTU_SIZE - 3;
}

#if defined(CANBUS_ENABLED)
void BleServer::init(Stream *vesc, CanBus *canbus) {
#else
void BleServer::init(Stream *vesc) {
#endif
vescSerial = vesc;

// Create the BLE Device
Expand All @@ -146,7 +150,9 @@ void BleServer::init(Stream *vesc, CanBus *canbus) {
char buf[128];
snprintf(buf, 128, "Initial MTU size %d", mtu_size);
Logger::notice(LOG_TAG_BLESERVER, buf);
#if defined(CANBUD_ENABLED)
this->canbus = canbus;
#endif

// Create the BLE Server
pServer = NimBLEDevice::createServer();
Expand Down Expand Up @@ -224,7 +230,7 @@ void BleServer::init(Stream *vesc, CanBus *canbus) {

#ifdef CANBUS_ENABLED

void BleServer::loop(CanBus::VescData *vescData, long loopTime, long maxLoopTime) {
void BleServer::loop(VescData *vescData, long loopTime, long maxLoopTime) {
#else
void BleServer::loop() {
#endif
Expand Down Expand Up @@ -464,6 +470,8 @@ void BleServer::updateRescueApp(long loopTime, long maxLoopTime) {
*/
}

#endif //CANBUS_ENABLED

template<typename TYPE>
void BleServer::sendValue(std::string key, TYPE value) {
std::stringstream ss;
Expand Down Expand Up @@ -510,5 +518,3 @@ struct BleServer::sendConfigValue {
void BleServer::sendConfig() {
visit_struct::for_each(AppConfiguration::getInstance()->config, sendConfigValue(pCharacteristicConf));
}

#endif //CANBUS_ENABLED
19 changes: 11 additions & 8 deletions src/BleServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#define LOG_TAG_BLESERVER "BleServer"

#define VESC_SERVICE_UUID "6E400001-B5A3-F393-E0A9-E50E24DCCA9E"
#define VESC_SERVICE_UUID "6E400001-B5A3-F393-E0A9-E50E24DCCA9E"
#define VESC_CHARACTERISTIC_UUID_RX "6E400002-B5A3-F393-E0A9-E50E24DCCA9E"
#define VESC_CHARACTERISTIC_UUID_TX "6E400003-B5A3-F393-E0A9-E50E24DCCA9E"

Expand All @@ -22,15 +22,16 @@
#define RESCUE_CHARACTERISTIC_UUID_HW_VERSION "99EB1515-A9E9-4024-B0A4-3DC4B4FABFB0"

class BleServer :
public NimBLEServerCallbacks,
public NimBLEServerCallbacks,
public BLECharacteristicCallbacks {
public:
BleServer();
void init(Stream *vesc, CanBus *canbus);
#ifdef CANBUS_ENABLED
void loop(CanBus::VescData *vescData, long loopTime, long maxLoopTime);
void init(Stream *vesc, CanBus *canbus);
void loop(VescData *vescData, long loopTime, long maxLoopTime);
#else
void loop();
void init(Stream *vesc);
void loop();
#endif

// NimBLEServerCallbacks
Expand All @@ -43,15 +44,17 @@ class BleServer :
void onSubscribe(NimBLECharacteristic* pCharacteristic, ble_gap_conn_desc* desc, uint16_t subValue);
void onStatus(NimBLECharacteristic* pCharacteristic, Status status, int code);
void sendConfig();
template<typename TYPE>
void sendValue(std::string key, TYPE value);

#ifdef CANBUS_ENABLED
#if defined(CANBUS_ENABLED)
void updateRescueApp(long loopTime, long maxLoopTime);
template<typename TYPE>
void sendValue(std::string key, TYPE value);
#endif

private:
#if defined(CANBUS_ENABLED)
CanBus *canbus{};
#endif
struct sendConfigValue;
void dumpBuffer(std::string header, std::string buffer);
};
Expand Down
Loading

0 comments on commit 3f969e2

Please sign in to comment.