Skip to content

Commit

Permalink
Merge pull request #278 from kike-canaries/cli_migration
Browse files Browse the repository at this point in the history
Cli migration
  • Loading branch information
hpsaturn authored Jun 13, 2024
2 parents 0d0ebef + 031cf3b commit 1b897eb
Show file tree
Hide file tree
Showing 34 changed files with 1,041 additions and 1,341 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ esptool.py
md5output.txt
releases/manifest
releases/installer/rev*

lib/easy-preferences
# IDE
.travis.yml
extensions.json
Expand Down
36 changes: 0 additions & 36 deletions include/wifi.hpp

This file was deleted.

3 changes: 3 additions & 0 deletions lib/batterylib/battery_oled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
#elif TTGO_T7S3
#define ADC_PIN 2
int channel_atten = ADC1_CHANNEL_1;
#elif ESP32C3_AIRGRADIENT
#define ADC_PIN 4
int channel_atten = ADC1_CHANNEL_1;
#else
#define ADC_PIN 34
int channel_atten = 0;
Expand Down
41 changes: 22 additions & 19 deletions src/bluetooth.cpp → lib/ble/bluetooth.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#ifndef DISABLE_BLE
#include <bluetooth.hpp>
#include "ConfigApp.hpp"

BLEServer* pServer = NULL;
BLECharacteristic* pCharactData = NULL;
Expand Down Expand Up @@ -58,30 +60,30 @@ void bleServerDataRefresh(){
}

void bleServerConfigRefresh(){
if (FAMILY == "ESP32-C3") return;
cfg.setWifiConnected(WiFi.isConnected()); // for notify on each write
pCharactConfig->setValue(cfg.getCurrentConfig().c_str());
// if (FAMILY == "ESP32-C3") return;
setWifiConnected(WiFi.isConnected()); // for notify on each write
pCharactConfig->setValue(getCurrentConfig().c_str());
}

// Config BLE callbacks
class MyConfigCallbacks : public BLECharacteristicCallbacks {
void onWrite(BLECharacteristic* pCharacteristic) {
if (FAMILY == "ESP32-C3") return;
// if (FAMILY == "ESP32-C3") return;
std::string value = pCharacteristic->getValue();
if (value.length() > 0) {
if (cfg.save(value.c_str())) {
cfg.reload();
if (save(value.c_str())) {
reload();
gui.displayPreferenceSaveIcon();

gui.setWifiMode(cfg.isWifiEnable());
if (!cfg.isWifiEnable()) wifiStop();
gui.setWifiMode(isWifiEnable());
if (!isWifiEnable()) wifiStop();

if(sensors.sample_time != cfg.stime) {
sensors.setSampleTime(cfg.stime);
gui.setSampleTime(cfg.stime);
if(sensors.sample_time != stime) {
sensors.setSampleTime(stime);
gui.setSampleTime(stime);
}
if(sensors.toffset != cfg.toffset) sensors.setTempOffset(cfg.toffset);
if(sensors.devmode != cfg.devmode) sensors.setDebugMode(cfg.devmode);
if(sensors.toffset != toffset) sensors.setTempOffset(toffset);
if(sensors.devmode != devmode) sensors.setDebugMode(devmode);
}
else{
Serial.println("[E][BTLE][CONFIG] saving error!");
Expand All @@ -90,20 +92,20 @@ class MyConfigCallbacks : public BLECharacteristicCallbacks {
};

void onRead(BLECharacteristic* pCharacteristic) {
if (FAMILY == "ESP32-C3") return;
// if (FAMILY == "ESP32-C3") return;
bleServerConfigRefresh();
}
};

// Status BLE callbacks
class MyStatusCallbacks : public BLECharacteristicCallbacks {
void onWrite(BLECharacteristic* pCharacteristic) {
if (FAMILY == "ESP32-C3") return;
// if (FAMILY == "ESP32-C3") return;
std::string value = pCharacteristic->getValue();
if (value.length() > 0 && cfg.getTrackStatusValues(value.c_str())) {
if (value.length() > 0 && getTrackStatusValues(value.c_str())) {
log_v("[E][BTLE][STATUS] "+String(value.c_str()));
gui.setTrackValues(cfg.track.spd,cfg.track.kms);
gui.setTrackTime(cfg.track.hrs,cfg.track.min,cfg.track.seg);
gui.setTrackValues(track.spd,track.kms);
gui.setTrackTime(track.hrs,track.min,track.seg);
}
else {
Serial.println("[E][BTLE][STATUS] write error!");
Expand Down Expand Up @@ -164,7 +166,7 @@ void bleServerInit() {
void bleLoop() {
static uint_fast64_t bleTimeStamp = 0;
// notify changed value
if (deviceConnected && (millis() - bleTimeStamp > cfg.stime * 1000)) { // each 5 secs
if (deviceConnected && (millis() - bleTimeStamp > stime * 1000)) { // each 5 secs
log_i("[BTLE] sending notification..");
log_d("[BTLE] %s",getNotificationData().c_str());
bleTimeStamp = millis();
Expand All @@ -189,3 +191,4 @@ void bleLoop() {
bool bleIsConnected(){
return deviceConnected;
}
#endif
16 changes: 8 additions & 8 deletions include/bluetooth.hpp → lib/ble/bluetooth.hpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
#ifndef DISABLE_BLE

#include <Arduino.h>
#include <ConfigApp.hpp>
#include <BLEDevice.h>
#include <BLEServer.h>
#include <BLEUtils.h>
#include <BLE2902.h>
#include <GUILib.hpp>
#include <Sensors.hpp>
#include <wifi.hpp>
#include <sniffer.hpp>
#include <Batterylib.hpp>

#include "GUILib.hpp"
#include "Sensors.hpp"
#include "sniffer.hpp"
#include "Batterylib.hpp"

#define SERVICE_UUID "c8d1d262-861f-4082-947e-f383a259aaf3"
#define CHARAC_DATA_UUID "b0f332a8-a5aa-4f3f-bb43-f99e7791ae01"
Expand All @@ -19,4 +18,5 @@
void bleLoop();
void bleServerInit();
bool bleIsConnected();
void bleServerConfigRefresh();
void bleServerConfigRefresh();
#endif
Loading

0 comments on commit 1b897eb

Please sign in to comment.