Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b02ed4c8d5 |
@@ -1,39 +1,26 @@
|
|||||||
#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);
|
||||||
|
|
||||||
Preferences prefs;
|
//defaults
|
||||||
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);
|
||||||
|
|
||||||
if (savedGunId >= 0 && savedGunId < _gunProfiles.size()) {
|
//set current profile
|
||||||
gp = _gunProfiles.get(savedGunId);
|
/*if (_gunProfiles.size()>0){
|
||||||
} else if (_gunProfiles.size() > 0) {
|
|
||||||
gp=_gunProfiles.get(0);
|
gp=_gunProfiles.get(0);
|
||||||
}
|
}
|
||||||
if (savedProjId >= 0 && savedProjId < _projectileProfiles.size()) {
|
if (_projectileProfiles.size()>0){
|
||||||
pp = _projectileProfiles.get(savedProjId);
|
|
||||||
} else if (_projectileProfiles.size() > 0) {
|
|
||||||
pp=_projectileProfiles.get(0);
|
pp=_projectileProfiles.get(0);
|
||||||
}
|
}*/
|
||||||
|
|
||||||
_currentProfile=new ChronoProfile(gp,pp);
|
_currentProfile=new ChronoProfile(gp,pp);
|
||||||
}
|
}
|
||||||
ChronoReadingManager& ChronoReadingManager::getInstance(){
|
ChronoReadingManager& ChronoReadingManager::getInstance(){
|
||||||
@@ -44,10 +31,6 @@ 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){
|
||||||
@@ -76,10 +59,6 @@ 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){
|
||||||
|
|||||||
+1
-286
File diff suppressed because one or more lines are too long
@@ -31,11 +31,6 @@ 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();
|
||||||
@@ -46,7 +41,6 @@ class ChronoWebServer {
|
|||||||
static void _handleWifiSave();
|
static void _handleWifiSave();
|
||||||
static void _handleClearWifi();
|
static void _handleClearWifi();
|
||||||
static void _handleWifiMode();
|
static void _handleWifiMode();
|
||||||
static void _handleInitData();
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+3
-13
@@ -1,20 +1,10 @@
|
|||||||
#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) {
|
||||||
memset(_name, 0, sizeof(_name));
|
strcpy(_name, name.c_str());
|
||||||
strncpy(_name, name.c_str(), sizeof(_name) - 1);
|
|
||||||
_type=type;
|
_type=type;
|
||||||
}
|
}
|
||||||
String GunProfile::getName(){
|
String GunProfile::getName(){return String(_name);}
|
||||||
_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;}
|
||||||
+3
-15
@@ -1,26 +1,14 @@
|
|||||||
#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) {
|
||||||
memset(_name, 0, sizeof(_name));
|
strcpy(_name, name.c_str());
|
||||||
strncpy(_name, name.c_str(), sizeof(_name) - 1);
|
|
||||||
_type=type;
|
_type=type;
|
||||||
_caliber=caliber;
|
_caliber=caliber;
|
||||||
_weight=weight;
|
_weight=weight;
|
||||||
}
|
}
|
||||||
String ProjectileProfile::getName(){
|
String ProjectileProfile::getName(){return String(_name);}
|
||||||
_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;}
|
||||||
Reference in New Issue
Block a user