mirror of
https://codeberg.org/mclemens/ubitxv6.git
synced 2024-09-10 16:34:19 -04:00
Offload settings to it's own set of files
This commit is contained in:
parent
2902764d73
commit
9dee71f5bd
111
settings.cpp
Normal file
111
settings.cpp
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
/**
|
||||||
|
* These are the "magic" indices where these user changable settinngs are stored in the EEPROM
|
||||||
|
*/
|
||||||
|
static const uint8_t EEPROM_ADDR_MASTER_CAL = 0;//int32_t
|
||||||
|
//4 is currently unused, but may have been LSB_CAL on other versions
|
||||||
|
static const uint8_t EEPROM_ADDR_USB_CAL = 8;//uint32_t
|
||||||
|
//12 is currently unused, but may have been CW_SIDETONE on other versions?
|
||||||
|
static const uint8_t EEPROM_ADDR_VFO_A_FREQ = 16;//uint32_t
|
||||||
|
static const uint8_t EEPROM_ADDR_VFO_B_FREQ = 20;//uint32_t
|
||||||
|
static const uint8_t EEPROM_ADDR_CW_SIDETONE = 24;//uint32_t
|
||||||
|
static const uint8_t EEPROM_ADDR_CW_DIT_TIME = 28;//uint32_t
|
||||||
|
static const uint8_t EEPROM_ADDR_TOUCH_SLOPE_X = 32;//int16_t
|
||||||
|
static const uint8_t EEPROM_ADDR_TOUCH_SLOPE_Y = 36;//int16_t
|
||||||
|
static const uint8_t EEPROM_ADDR_TOUCH_OFFSET_X = 40;//int16_t
|
||||||
|
static const uint8_t EEPROM_ADDR_TOUCH_OFFSET_Y = 44;//int16_t
|
||||||
|
static const uint8_t EEPROM_ADDR_CW_DELAYTIME = 48;
|
||||||
|
static const uint8_t EEPROM_ADDR_VFO_A_MODE = 256;
|
||||||
|
static const uint8_t EEPROM_ADDR_VFO_B_MODE = 257;
|
||||||
|
static const uint8_t EEPROM_ADDR_CW_KEY_TYPE = 358;
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
bool LoadSane(T& dest,uint16_t addr, T min, T max)
|
||||||
|
{
|
||||||
|
T read_value;
|
||||||
|
EEPROM.get(addr,read_value);
|
||||||
|
if((min <= read_value) && (read_value <= max)){
|
||||||
|
dest = read_value;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
#include <EEPROM.h>
|
||||||
|
#include "settings.h"
|
||||||
|
|
||||||
|
//This is the non-extern version that actually gets built
|
||||||
|
SettingsRam globalSettings;
|
||||||
|
|
||||||
|
void LoadDefaultSettings()
|
||||||
|
{
|
||||||
|
memset(&globalSettings,0x00,sizeof(globalSettings));
|
||||||
|
|
||||||
|
globalSettings.oscillatorCal = 0;
|
||||||
|
globalSettings.usbCarrierFreq = 11052000L;
|
||||||
|
|
||||||
|
globalSettings.activeVfo = Vfo_e::VFO_A;
|
||||||
|
globalSettings.vfoA.frequency = 7150000L;
|
||||||
|
globalSettings.vfoA.mode = VFO_MODE_LSB;
|
||||||
|
globalSettings.vfoB.frequency = 14150000L;
|
||||||
|
globalSettings.vfoB.mode = VFO_MODE_USB;
|
||||||
|
|
||||||
|
globalSettings.keyerMode = KEYER_STRAIGHT;
|
||||||
|
globalSettings.cwSideToneFreq = 800;
|
||||||
|
globalSettings.cwDitDurationMs = 100;
|
||||||
|
globalSettings.cwActiveTimeoutMs = 50;
|
||||||
|
|
||||||
|
globalSettings.touchSlopeX = 104;
|
||||||
|
globalSettings.touchSlopeY = 137;
|
||||||
|
globalSettings.touchOffsetX = 28;
|
||||||
|
globalSettings.touchOffsetY = 29;
|
||||||
|
|
||||||
|
globalSettings.ritOn = false;
|
||||||
|
globalSettings.ritFrequency = globalSettings.vfoA.frequency;
|
||||||
|
|
||||||
|
globalSettings.tuningMode = TuningMode_e::TUNE_VOICE;
|
||||||
|
|
||||||
|
globalSettings.splitOn = false;
|
||||||
|
|
||||||
|
globalSettings.txActive = false;
|
||||||
|
globalSettings.txCatActive = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LoadSettingsFromEeprom()
|
||||||
|
{
|
||||||
|
LoadSane(globalSettings.usbCarrierFreq,EEPROM_ADDR_USB_CAL,11048000L,11060000L);
|
||||||
|
LoadSane(globalSettings.vfoA.frequency,EEPROM_ADDR_VFO_A_FREQ,3500000L,30000000L);
|
||||||
|
LoadSane(globalSettings.vfoB.frequency,EEPROM_ADDR_VFO_B_FREQ,3500000L,30000000L);
|
||||||
|
LoadSane(globalSettings.cwSideToneFreq,EEPROM_ADDR_CW_SIDETONE,100,2000);
|
||||||
|
LoadSane(globalSettings.cwDitDurationMs,EEPROM_ADDR_CW_DIT_TIME,10,1000);
|
||||||
|
if(LoadSane(globalSettings.cwActiveTimeoutMs,EEPROM_ADDR_CW_DELAYTIME,10,100)){
|
||||||
|
globalSettings.cwActiveTimeoutMs *= 10;//scale by 10 for legacy reasons
|
||||||
|
}
|
||||||
|
LoadSane(globalSettings.vfoA.mode,EEPROM_ADDR_VFO_A_MODE,VFO_MODE_LSB,VFO_MODE_USB);
|
||||||
|
LoadSane(globalSettings.vfoB.mode,EEPROM_ADDR_VFO_B_MODE,VFO_MODE_LSB,VFO_MODE_USB);
|
||||||
|
LoadSane(globalSettings.keyerMode,EEPROM_ADDR_CW_KEY_TYPE,KEYER_STRAIGHT,KEYER_IAMBIC_B);
|
||||||
|
|
||||||
|
//No sanity check on these - cal your heart out
|
||||||
|
EEPROM.get(EEPROM_ADDR_MASTER_CAL,globalSettings.masterCalibration);
|
||||||
|
EEPROM.get(EEPROM_ADDR_TOUCH_SLOPE_X,globalSettings.touchSlopeX);
|
||||||
|
EEPROM.get(EEPROM_ADDR_TOUCH_SLOPE_Y,globalSettings.touchSlopeY);
|
||||||
|
EEPROM.get(EEPROM_ADDR_TOUCH_OFFSET_X,globalSettings.touchOffsetX);
|
||||||
|
EEPROM.get(EEPROM_ADDR_TOUCH_OFFSET_Y,globalSettings.touchOffsetY);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SaveSettingsToEeprom()
|
||||||
|
{
|
||||||
|
EEPROM.put(EEPROM_ADDR_MASTER_CAL,globalSettings.masterCalibration);
|
||||||
|
EEPROM.put(EEPROM_ADDR_USB_CAL,globalSettings.usbCarrierFreq);
|
||||||
|
EEPROM.put(EEPROM_ADDR_VFO_A_FREQ,globalSettings.vfoA.frequency);
|
||||||
|
EEPROM.put(EEPROM_ADDR_VFO_B_FREQ,globalSettings.vfoB.frequency);
|
||||||
|
EEPROM.put(EEPROM_ADDR_CW_SIDETONE,globalSettings.cwSideToneFreq);
|
||||||
|
EEPROM.put(EEPROM_ADDR_CW_DIT_TIME,globalSettings.cwDitDurationMs);
|
||||||
|
EEPROM.put(EEPROM_ADDR_TOUCH_SLOPE_X,globalSettings.touchSlopeX);
|
||||||
|
EEPROM.put(EEPROM_ADDR_TOUCH_SLOPE_Y,globalSettings.touchSlopeY);
|
||||||
|
EEPROM.put(EEPROM_ADDR_TOUCH_OFFSET_X,globalSettings.touchOffsetX);
|
||||||
|
EEPROM.put(EEPROM_ADDR_TOUCH_OFFSET_Y,globalSettings.touchOffsetY);
|
||||||
|
EEPROM.put(EEPROM_ADDR_CW_DELAYTIME,globalSettings.cwActiveTimeoutMs/10);//scale by 10 for legacy reasons
|
||||||
|
EEPROM.put(EEPROM_ADDR_VFO_A_MODE,globalSettings.vfoA.mode);
|
||||||
|
EEPROM.put(EEPROM_ADDR_VFO_B_MODE,globalSettings.vfoB.mode);
|
||||||
|
EEPROM.put(EEPROM_ADDR_CW_KEY_TYPE,globalSettings.keyerMode);
|
||||||
|
}
|
147
settings.h
Normal file
147
settings.h
Normal file
@ -0,0 +1,147 @@
|
|||||||
|
/*
|
||||||
|
* This class deals with all of the radio settings,
|
||||||
|
* so that other areas of the code doesn't have to
|
||||||
|
*
|
||||||
|
* Example usage:
|
||||||
|
* LoadSettingsFromEeprom();
|
||||||
|
* Serial.println(globalSettings.vfoAFreq);
|
||||||
|
* globalSettings.vfoAFreq = 12345678;
|
||||||
|
* SaveSettingsToEeprom();
|
||||||
|
* Serial.println(globalSettings.vfoAFreq);
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Loads default values for all settings
|
||||||
|
*/
|
||||||
|
void LoadDefaultSettings();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Loads all persistent settings from the EEPROM
|
||||||
|
*/
|
||||||
|
void LoadSettingsFromEeprom();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Saves all persistent settings to the EEPROM
|
||||||
|
*
|
||||||
|
* It's a little CPU-cycle-wasteful to save EVERYTHING
|
||||||
|
* each time, but keeps things simple
|
||||||
|
*/
|
||||||
|
void SaveSettingsToEeprom();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* These are all of the settings
|
||||||
|
* Note that not all settings are saved to the EEPROM
|
||||||
|
*/
|
||||||
|
enum Vfo_e : uint8_t
|
||||||
|
{
|
||||||
|
VFO_A,
|
||||||
|
VFO_B
|
||||||
|
};
|
||||||
|
|
||||||
|
enum VfoMode_e : uint16_t
|
||||||
|
{
|
||||||
|
VFO_MODE_LSB = 2,
|
||||||
|
VFO_MODE_USB = 3
|
||||||
|
};
|
||||||
|
|
||||||
|
struct VfoSettings_t
|
||||||
|
{
|
||||||
|
uint32_t frequency;
|
||||||
|
VfoMode_e mode;
|
||||||
|
};
|
||||||
|
|
||||||
|
enum TuningMode_e : uint8_t
|
||||||
|
{
|
||||||
|
TUNE_SSB,
|
||||||
|
TUNE_CW
|
||||||
|
};
|
||||||
|
|
||||||
|
enum KeyerMode_e : uint8_t
|
||||||
|
{
|
||||||
|
KEYER_STRAIGHT,
|
||||||
|
KEYER_IAMBIC_A,
|
||||||
|
KEYER_IAMBIC_B
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This is the definition of the settings/state variables
|
||||||
|
*/
|
||||||
|
struct SettingsRam
|
||||||
|
{
|
||||||
|
uint32_t oscillatorCal;
|
||||||
|
uint32_t usbCarrierFreq;
|
||||||
|
|
||||||
|
Vfo_e activeVfo;
|
||||||
|
VfoSettings_t vfoA;
|
||||||
|
VfoSettings_t vfoB;
|
||||||
|
|
||||||
|
KeyerMode_e keyerMode;
|
||||||
|
uint32_t cwSideToneFreq;
|
||||||
|
uint32_t cwDitDurationMs;
|
||||||
|
uint16_t cwActiveTimeoutMs;
|
||||||
|
|
||||||
|
int16_t touchSlopeX;
|
||||||
|
int16_t touchSlopeY;
|
||||||
|
int16_t touchOffsetX;
|
||||||
|
int16_t touchOffsetY;
|
||||||
|
|
||||||
|
bool ritOn;
|
||||||
|
uint32_t ritFrequency;
|
||||||
|
|
||||||
|
TuningMode_e tuningMode;
|
||||||
|
|
||||||
|
bool splitOn;
|
||||||
|
|
||||||
|
bool txActive;
|
||||||
|
bool txCatActive;
|
||||||
|
|
||||||
|
uint32_t cwExpirationTimeMs;
|
||||||
|
};
|
||||||
|
|
||||||
|
//This is the shared declaration
|
||||||
|
extern SettingsRam globalSettings;
|
||||||
|
|
||||||
|
//Some convenience functions
|
||||||
|
uint32_t GetActiveVfoFreq()
|
||||||
|
{
|
||||||
|
if(VFO_A == globalSettings.activeVfo){
|
||||||
|
return globalSettings.vfoA.frequency;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
return globalSettings.vfoB.frequency;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetActiveVfoFreq(uint32_t frequency)
|
||||||
|
{
|
||||||
|
if(VFO_A == globalSettings.activeVfo)
|
||||||
|
{
|
||||||
|
globalSettings.vfoA.frequency = frequency;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
globalSettings.vfoB.frequency = frequency;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
VfoMode_e GetActiveVfoMode()
|
||||||
|
{
|
||||||
|
if(VFO_A == globalSettings.activeVfo){
|
||||||
|
return globalSettings.vfoA.mode;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
return globalSettings.vfoB.mode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetActiveVfoMode(VfoMode_e mode)
|
||||||
|
{
|
||||||
|
if(VFO_A == globalSettings.activeVfo)
|
||||||
|
{
|
||||||
|
globalSettings.vfoA.mode = mode;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
globalSettings.vfoB.mode = mode;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user