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