working fixes

This commit is contained in:
Dan Priece
2026-08-17 12:55:33 -04:00
parent a23322dddf
commit 122abcdc7c
5 changed files with 351 additions and 17 deletions
+31 -10
View File
@@ -1,27 +1,40 @@
#include "ChronoReadingManager.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
ChronoReadingManager::ChronoReadingManager() {}
void ChronoReadingManager::initializeProfiles(){
//load gun profiles from disk
FileManager& files = FileManager::getInstance();
//files.formatDisk();
files.loadGunProfiles(_gunProfiles);
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);
ProjectileProfile pp("", ProjectileProfile::PELLET, 0.0, 0.0);
//set current profile
/*if (_gunProfiles.size()>0){
gp=_gunProfiles.get(0);
if (savedGunId >= 0 && savedGunId < _gunProfiles.size()) {
gp = _gunProfiles.get(savedGunId);
} else if (_gunProfiles.size() > 0) {
gp = _gunProfiles.get(0);
}
if (_projectileProfiles.size()>0){
pp=_projectileProfiles.get(0);
}*/
_currentProfile=new ChronoProfile(gp,pp);
if (savedProjId >= 0 && savedProjId < _projectileProfiles.size()) {
pp = _projectileProfiles.get(savedProjId);
} else if (_projectileProfiles.size() > 0) {
pp = _projectileProfiles.get(0);
}
_currentProfile = new ChronoProfile(gp, pp);
}
ChronoReadingManager& ChronoReadingManager::getInstance(){
static ChronoReadingManager instance;
@@ -31,6 +44,10 @@ LinkedList<GunProfile>& ChronoReadingManager::getGunProfiles(){return _gunProfil
void ChronoReadingManager::setGunProfile(int id){
GunProfile p=_gunProfiles.get(id);
_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){
if (writeToDisk){
@@ -59,6 +76,10 @@ LinkedList<ProjectileProfile>& ChronoReadingManager::getProjectileProfiles(){ret
void ChronoReadingManager::setProjectileProfile(int id){
ProjectileProfile pp=_projectileProfiles.get(id);
_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){
if (writeToDisk){