working fixes
This commit is contained in:
+31
-10
@@ -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){
|
||||
|
||||
+286
-1
File diff suppressed because one or more lines are too long
@@ -31,6 +31,11 @@ class ChronoWebServer {
|
||||
static void _handleAddGunProfile();
|
||||
static void _handleSetGunProfile();
|
||||
static void _handleRemoveGunProfile();
|
||||
static void _handleGetGunProfiles();
|
||||
static void _handleGetProjectileProfiles();
|
||||
static void _handleGetCurrentGunProfile();
|
||||
static void _handleGetCurrentProjectileProfile();
|
||||
static void _handleGetReadings();
|
||||
static void _handleExport();
|
||||
static void _handleReset();
|
||||
static void _handleFormat();
|
||||
@@ -41,6 +46,7 @@ class ChronoWebServer {
|
||||
static void _handleWifiSave();
|
||||
static void _handleClearWifi();
|
||||
static void _handleWifiMode();
|
||||
static void _handleInitData();
|
||||
|
||||
};
|
||||
|
||||
|
||||
+13
-3
@@ -1,10 +1,20 @@
|
||||
#include "GunProfile.h"
|
||||
|
||||
// Constructor implementation
|
||||
GunProfile::GunProfile() {}
|
||||
GunProfile::GunProfile() {
|
||||
memset(_name, 0, sizeof(_name));
|
||||
_type = 0;
|
||||
}
|
||||
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;
|
||||
}
|
||||
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;}
|
||||
+15
-3
@@ -1,14 +1,26 @@
|
||||
#include "ProjectileProfile.h"
|
||||
|
||||
// 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) {
|
||||
strcpy(_name, name.c_str());
|
||||
memset(_name, 0, sizeof(_name));
|
||||
strncpy(_name, name.c_str(), sizeof(_name) - 1);
|
||||
_type=type;
|
||||
_caliber=caliber;
|
||||
_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;}
|
||||
String ProjectileProfile::getType(){if (_type==PELLET){return "Pellet";}else{return "Slug";}}
|
||||
float ProjectileProfile::getCaliber(){return _caliber;}
|
||||
Reference in New Issue
Block a user