Compare commits

...
3 Commits
Author SHA1 Message Date
Dan Priece 122abcdc7c working fixes 2026-08-17 12:55:33 -04:00
Dan Priece a23322dddf working version 2026-07-17 15:04:49 -04:00
Dan Priece 6167432e1b working version 2026-06-23 14:48:47 -04:00
8 changed files with 548 additions and 230 deletions
+9 -7
View File
@@ -4,11 +4,12 @@
// Flag to signal that a new reading is ready to be processed // Flag to signal that a new reading is ready to be processed
volatile bool newReadingAvailable = false; volatile bool newReadingAvailable = false;
volatile int lastReadFPS = 0; volatile int lastReadFPS = 0;
static NimBLEScan* pScan;
static NimBLEClient* _pClient = nullptr; static NimBLEClient* _pClient = nullptr;
static ChronoBLE::ConnectionState currentState; static ChronoBLE::ConnectionState currentState;
static const NimBLEAdvertisedDevice* advDevice = nullptr; static const NimBLEAdvertisedDevice* advDevice = nullptr;
static uint32_t scanTimeMs = 5000; static uint32_t scanTimeMs = 1000; //5000
static uint32_t scanTimeoutMs = 1000;
static NimBLEUUID deviceUUID("0000180a-0000-1000-8000-00805f9b34fb"); static NimBLEUUID deviceUUID("0000180a-0000-1000-8000-00805f9b34fb");
static NimBLEUUID serviceUUID("00001623-88EC-688C-644B-3FA706C0BB75"); static NimBLEUUID serviceUUID("00001623-88EC-688C-644B-3FA706C0BB75");
static NimBLEUUID speedCharacteristicUUID("00001624-88EC-688C-644B-3FA706C0BB75"); static NimBLEUUID speedCharacteristicUUID("00001624-88EC-688C-644B-3FA706C0BB75");
@@ -58,7 +59,8 @@ class ScanCallbacks : public NimBLEScanCallbacks {
/** Callback to process the results of the completed scan or restart it */ /** Callback to process the results of the completed scan or restart it */
void onScanEnd(const NimBLEScanResults& results, int reason) override { void onScanEnd(const NimBLEScanResults& results, int reason) override {
//Serial.printf("Scan Ended, reason: %d, device count: %d; Restarting scan\n", reason, results.getCount()); //Serial.printf("Scan Ended, reason: %d, device count: %d; Restarting scan\n", reason, results.getCount());
NimBLEDevice::getScan()->start(scanTimeMs, false, true); delay(scanTimeoutMs);
pScan->start(scanTimeMs, false, false);
} }
} scanCallbacks; } scanCallbacks;
@@ -94,11 +96,11 @@ ChronoBLE::ChronoBLE() {
void ChronoBLE::init() { void ChronoBLE::init() {
NimBLEDevice::init("FX-Chrono-Client"); NimBLEDevice::init("FX-Chrono-Client");
NimBLEDevice::setPower(3); /** 3dbm */ NimBLEDevice::setPower(3); /** 3dbm */
NimBLEScan* pScan = NimBLEDevice::getScan(); pScan = NimBLEDevice::getScan();
pScan->setScanCallbacks(&scanCallbacks, false); pScan->setScanCallbacks(&scanCallbacks, false);
pScan->setInterval(100); pScan->setInterval(100);
pScan->setWindow(100); pScan->setWindow(99);
pScan->setActiveScan(true); pScan->setActiveScan(false);
} }
void ChronoBLE::_setState(ConnectionState state){ void ChronoBLE::_setState(ConnectionState state){
currentState=state; currentState=state;
@@ -122,7 +124,7 @@ bool ChronoBLE::foundDevice(){if (advDevice!=nullptr){return true;}return false;
void ChronoBLE::startScan(){ void ChronoBLE::startScan(){
Serial.println("starting scan!!!"); Serial.println("starting scan!!!");
_setState(SCANNING); _setState(SCANNING);
NimBLEDevice::getScan()->start(scanTimeMs, false, true); pScan->start(scanTimeMs, false, false);
} }
void ChronoBLE::_disconnectDevice(){ void ChronoBLE::_disconnectDevice(){
_setState(IDLE); _setState(IDLE);
Binary file not shown.
Binary file not shown.
+31 -10
View File
@@ -1,27 +1,40 @@
#include "ChronoReadingManager.h" #include "ChronoReadingManager.h"
#include "FileManager.h" #include "FileManager.h"
#include <Preferences.h>
static const char* PROFILE_NS = "profile";
static const char* GUN_ID_KEY = "gunId";
static const char* PROJ_ID_KEY = "projId";
// Constructor implementation // Constructor implementation
ChronoReadingManager::ChronoReadingManager() {} ChronoReadingManager::ChronoReadingManager() {}
void ChronoReadingManager::initializeProfiles(){ void ChronoReadingManager::initializeProfiles(){
//load gun profiles from disk
FileManager& files = FileManager::getInstance(); FileManager& files = FileManager::getInstance();
//files.formatDisk();
files.loadGunProfiles(_gunProfiles); files.loadGunProfiles(_gunProfiles);
files.loadProjectileProfiles(_projectileProfiles); files.loadProjectileProfiles(_projectileProfiles);
//defaults Preferences prefs;
prefs.begin(PROFILE_NS, true);
int savedGunId = prefs.getInt(GUN_ID_KEY, -1);
int savedProjId = prefs.getInt(PROJ_ID_KEY, -1);
prefs.end();
GunProfile gp("", GunProfile::PROFILE_TYPE_AIR_GUN_FAC); GunProfile gp("", GunProfile::PROFILE_TYPE_AIR_GUN_FAC);
ProjectileProfile pp("", ProjectileProfile::PELLET, 0.0, 0.0); ProjectileProfile pp("", ProjectileProfile::PELLET, 0.0, 0.0);
//set current profile if (savedGunId >= 0 && savedGunId < _gunProfiles.size()) {
/*if (_gunProfiles.size()>0){ gp = _gunProfiles.get(savedGunId);
gp=_gunProfiles.get(0); } else if (_gunProfiles.size() > 0) {
gp = _gunProfiles.get(0);
} }
if (_projectileProfiles.size()>0){ if (savedProjId >= 0 && savedProjId < _projectileProfiles.size()) {
pp=_projectileProfiles.get(0); pp = _projectileProfiles.get(savedProjId);
}*/ } else if (_projectileProfiles.size() > 0) {
_currentProfile=new ChronoProfile(gp,pp); pp = _projectileProfiles.get(0);
}
_currentProfile = new ChronoProfile(gp, pp);
} }
ChronoReadingManager& ChronoReadingManager::getInstance(){ ChronoReadingManager& ChronoReadingManager::getInstance(){
static ChronoReadingManager instance; static ChronoReadingManager instance;
@@ -31,6 +44,10 @@ LinkedList<GunProfile>& ChronoReadingManager::getGunProfiles(){return _gunProfil
void ChronoReadingManager::setGunProfile(int id){ void ChronoReadingManager::setGunProfile(int id){
GunProfile p=_gunProfiles.get(id); GunProfile p=_gunProfiles.get(id);
_currentProfile->setGunProfile(p); _currentProfile->setGunProfile(p);
Preferences prefs;
prefs.begin(PROFILE_NS, false);
prefs.putInt(GUN_ID_KEY, id);
prefs.end();
} }
void ChronoReadingManager::addGunProfile(GunProfile profile, bool writeToDisk){ void ChronoReadingManager::addGunProfile(GunProfile profile, bool writeToDisk){
if (writeToDisk){ if (writeToDisk){
@@ -59,6 +76,10 @@ LinkedList<ProjectileProfile>& ChronoReadingManager::getProjectileProfiles(){ret
void ChronoReadingManager::setProjectileProfile(int id){ void ChronoReadingManager::setProjectileProfile(int id){
ProjectileProfile pp=_projectileProfiles.get(id); ProjectileProfile pp=_projectileProfiles.get(id);
_currentProfile->setProjectileProfile(pp); _currentProfile->setProjectileProfile(pp);
Preferences prefs;
prefs.begin(PROFILE_NS, false);
prefs.putInt(PROJ_ID_KEY, id);
prefs.end();
} }
void ChronoReadingManager::addProjectileProfile(ProjectileProfile profile, bool writeToDisk){ void ChronoReadingManager::addProjectileProfile(ProjectileProfile profile, bool writeToDisk){
if (writeToDisk){ if (writeToDisk){
+469 -207
View File
File diff suppressed because one or more lines are too long
+11
View File
@@ -6,6 +6,7 @@
#include <NetworkClient.h> #include <NetworkClient.h>
#include <ESPmDNS.h> #include <ESPmDNS.h>
#include <Update.h> #include <Update.h>
#include <Preferences.h>
#include <ChronoBLE.h> #include <ChronoBLE.h>
#include <GunProfile.h> #include <GunProfile.h>
#include "ChronoVersion.h" #include "ChronoVersion.h"
@@ -30,12 +31,22 @@ class ChronoWebServer {
static void _handleAddGunProfile(); static void _handleAddGunProfile();
static void _handleSetGunProfile(); static void _handleSetGunProfile();
static void _handleRemoveGunProfile(); static void _handleRemoveGunProfile();
static void _handleGetGunProfiles();
static void _handleGetProjectileProfiles();
static void _handleGetCurrentGunProfile();
static void _handleGetCurrentProjectileProfile();
static void _handleGetReadings();
static void _handleExport(); static void _handleExport();
static void _handleReset(); static void _handleReset();
static void _handleFormat(); static void _handleFormat();
static void _handleTestMode(); static void _handleTestMode();
static void _handleOta(); static void _handleOta();
static void _handleVersion(); static void _handleVersion();
static void _handleWifi();
static void _handleWifiSave();
static void _handleClearWifi();
static void _handleWifiMode();
static void _handleInitData();
}; };
+13 -3
View File
@@ -1,10 +1,20 @@
#include "GunProfile.h" #include "GunProfile.h"
// Constructor implementation // Constructor implementation
GunProfile::GunProfile() {} GunProfile::GunProfile() {
memset(_name, 0, sizeof(_name));
_type = 0;
}
GunProfile::GunProfile(String name, int type) { GunProfile::GunProfile(String name, int type) {
strcpy(_name, name.c_str()); memset(_name, 0, sizeof(_name));
strncpy(_name, name.c_str(), sizeof(_name) - 1);
_type=type; _type=type;
} }
String GunProfile::getName(){return String(_name);} String GunProfile::getName(){
_name[sizeof(_name)-1] = '\0';
for (int i = 0; i < sizeof(_name) - 1; i++) {
if (_name[i] == '\0') { _name[i+1] = '\0'; break; }
}
return String(_name);
}
int GunProfile::getPowerLevel(){return _type;} int GunProfile::getPowerLevel(){return _type;}
+15 -3
View File
@@ -1,14 +1,26 @@
#include "ProjectileProfile.h" #include "ProjectileProfile.h"
// Constructor implementation // Constructor implementation
ProjectileProfile::ProjectileProfile() {} ProjectileProfile::ProjectileProfile() {
memset(_name, 0, sizeof(_name));
_type = PELLET;
_caliber = 0;
_weight = 0;
}
ProjectileProfile::ProjectileProfile(String name, ProjectileType type, float caliber, float weight) { ProjectileProfile::ProjectileProfile(String name, ProjectileType type, float caliber, float weight) {
strcpy(_name, name.c_str()); memset(_name, 0, sizeof(_name));
strncpy(_name, name.c_str(), sizeof(_name) - 1);
_type=type; _type=type;
_caliber=caliber; _caliber=caliber;
_weight=weight; _weight=weight;
} }
String ProjectileProfile::getName(){return String(_name);} String ProjectileProfile::getName(){
_name[sizeof(_name)-1] = '\0';
for (int i = 0; i < sizeof(_name) - 1; i++) {
if (_name[i] == '\0') { _name[i+1] = '\0'; break; }
}
return String(_name);
}
float ProjectileProfile::getWeight(){return _weight;} float ProjectileProfile::getWeight(){return _weight;}
String ProjectileProfile::getType(){if (_type==PELLET){return "Pellet";}else{return "Slug";}} String ProjectileProfile::getType(){if (_type==PELLET){return "Pellet";}else{return "Slug";}}
float ProjectileProfile::getCaliber(){return _caliber;} float ProjectileProfile::getCaliber(){return _caliber;}