mirror of https://github.com/rusefi/wideband.git
don't keep two or three copies of the config
This commit is contained in:
parent
75d48dfe8e
commit
f654cbd14b
|
@ -141,15 +141,15 @@ static float AuxGetInputSignal(int sel)
|
||||||
static THD_WORKING_AREA(waAuxOutThread, 256);
|
static THD_WORKING_AREA(waAuxOutThread, 256);
|
||||||
void AuxOutThread(void*)
|
void AuxOutThread(void*)
|
||||||
{
|
{
|
||||||
const auto& cfg = GetConfiguration();
|
const auto cfg = GetConfiguration();
|
||||||
|
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
for (int ch = 0; ch < AFR_CHANNELS; ch++)
|
for (int ch = 0; ch < AFR_CHANNELS; ch++)
|
||||||
{
|
{
|
||||||
auto cfg = GetConfiguration();
|
auto cfg = GetConfiguration();
|
||||||
float input = AuxGetInputSignal(cfg.auxInput[ch]);
|
float input = AuxGetInputSignal(cfg->auxInput[ch]);
|
||||||
float voltage = interpolate2d(input, cfg.auxOutBins[ch], cfg.auxOutValues[ch]);
|
float voltage = interpolate2d(input, cfg->auxOutBins[ch], cfg->auxOutValues[ch]);
|
||||||
|
|
||||||
SetAuxDac(ch, voltage);
|
SetAuxDac(ch, voltage);
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,7 +97,7 @@ int InitConfiguration()
|
||||||
|
|
||||||
static Configuration c;
|
static Configuration c;
|
||||||
|
|
||||||
Configuration& GetConfiguration()
|
Configuration* GetConfiguration()
|
||||||
{
|
{
|
||||||
const auto& cfg = __configflash__start__;
|
const auto& cfg = __configflash__start__;
|
||||||
|
|
||||||
|
@ -129,10 +129,10 @@ Configuration& GetConfiguration()
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return c;
|
return &c;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetConfiguration(const Configuration& newConfig)
|
void SetConfiguration()
|
||||||
{
|
{
|
||||||
// erase config page
|
// erase config page
|
||||||
Flash::ErasePage(31);
|
Flash::ErasePage(31);
|
||||||
|
@ -140,7 +140,7 @@ void SetConfiguration(const Configuration& newConfig)
|
||||||
// Copy data to flash
|
// Copy data to flash
|
||||||
Flash::Write(
|
Flash::Write(
|
||||||
reinterpret_cast<flashaddr_t>(&__configflash__start__),
|
reinterpret_cast<flashaddr_t>(&__configflash__start__),
|
||||||
reinterpret_cast<const uint8_t*>(&newConfig),
|
reinterpret_cast<const uint8_t*>(&c),
|
||||||
sizeof(Configuration)
|
sizeof(Configuration)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,17 +52,13 @@ int InitConfiguration()
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Configuration c;
|
Configuration* GetConfiguration()
|
||||||
|
|
||||||
Configuration& GetConfiguration()
|
|
||||||
{
|
{
|
||||||
return cfg;
|
return &cfg;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetConfiguration(const Configuration& newConfig)
|
void SetConfiguration()
|
||||||
{
|
{
|
||||||
cfg = newConfig;
|
|
||||||
|
|
||||||
SaveConfiguration();
|
SaveConfiguration();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,8 +48,8 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
int InitConfiguration();
|
int InitConfiguration();
|
||||||
Configuration& GetConfiguration();
|
Configuration* GetConfiguration();
|
||||||
void SetConfiguration(const Configuration& newConfig);
|
void SetConfiguration();
|
||||||
|
|
||||||
/* TS stuff */
|
/* TS stuff */
|
||||||
uint8_t *GetConfiguratiuonPtr();
|
uint8_t *GetConfiguratiuonPtr();
|
||||||
|
|
|
@ -12,14 +12,14 @@
|
||||||
// this same header is imported by rusEFI to get struct layouts and firmware version
|
// this same header is imported by rusEFI to get struct layouts and firmware version
|
||||||
#include "../for_rusefi/wideband_can.h"
|
#include "../for_rusefi/wideband_can.h"
|
||||||
|
|
||||||
Configuration configuration;
|
static Configuration* configuration;
|
||||||
|
|
||||||
static THD_WORKING_AREA(waCanTxThread, 256);
|
static THD_WORKING_AREA(waCanTxThread, 256);
|
||||||
void CanTxThread(void*)
|
void CanTxThread(void*)
|
||||||
{
|
{
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
SendRusefiFormat(configuration.CanIndexOffset);
|
SendRusefiFormat(configuration->CanIndexOffset);
|
||||||
|
|
||||||
chThdSleepMilliseconds(10);
|
chThdSleepMilliseconds(10);
|
||||||
}
|
}
|
||||||
|
@ -100,10 +100,9 @@ void CanRxThread(void*)
|
||||||
// Check if it's an "index set" message
|
// Check if it's an "index set" message
|
||||||
else if (frame.DLC == 1 && frame.EID == WB_MSG_SET_INDEX)
|
else if (frame.DLC == 1 && frame.EID == WB_MSG_SET_INDEX)
|
||||||
{
|
{
|
||||||
auto &newCfg = GetConfiguration();
|
|
||||||
newCfg.CanIndexOffset = frame.data8[0];
|
|
||||||
SetConfiguration(newCfg);
|
|
||||||
configuration = GetConfiguration();
|
configuration = GetConfiguration();
|
||||||
|
configuration->CanIndexOffset = frame.data8[0];
|
||||||
|
SetConfiguration();
|
||||||
SendAck();
|
SendAck();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue