Skip to content

Commit

Permalink
saves config to flash
Browse files Browse the repository at this point in the history
  • Loading branch information
markzakharyan committed Oct 7, 2024
1 parent d0215b2 commit ba39083
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions m4/src/Peripherals/DAC/DACChannel.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

#include "Config.h"

#include "KVStore.h"
#include "kvstore_global_api.h"

class DACChannel {
private:
float gain_error;
Expand Down Expand Up @@ -36,6 +39,18 @@ class DACChannel {
digitalWrite(cs_pin, HIGH);
commsController.endSingleTransaction();
setVoltage(0.0);

char offsetKey[14];
char gainKey[12];
sprintf(offsetKey, "offsetError%d", cs_pin);
sprintf(gainKey, "gainError%d", cs_pin);
float offset;
kv_get(offsetKey, (uint8_t*)&offset, sizeof(offsetKey) , 0);
float gain;
kv_get(gainKey, (uint8_t*)&gain, sizeof(gain) , 0);

this->offset_error = offset;
this->gain_error = gain;
}

// initialize is the command INITIALIZE, setup is called in main::setup
Expand Down Expand Up @@ -86,8 +101,16 @@ class DACChannel {
}

void setCalibration(float offset, float gain) {
char offsetKey[14];
char gainKey[12];
sprintf(offsetKey, "offsetError%d", cs_pin);
sprintf(gainKey, "gainError%d", cs_pin);
kv_set(offsetKey, (uint8_t*)&offset_error, sizeof(offset), 0);
kv_set(gainKey, (uint8_t*)&gain_error, sizeof(gain), 0);
this->offset_error = offset;
this->gain_error = gain;
voltage_upper_bound = full_scale * gain_error + offset_error;
voltage_lower_bound = -full_scale * gain_error + offset_error;
}

void setFullScale(float full_scale) {
Expand Down

0 comments on commit ba39083

Please sign in to comment.