@@ -17,6 +17,17 @@ class DACController {
1717 inline static std::vector<DACChannel> dac_channels;
1818
1919 public:
20+ // Setter functions for global voltage limits
21+ inline static OperationResult setUpperLimit (float limit) {
22+ DACLimits::upper_voltage_limit = limit;
23+ return OperationResult::Success (" UPPER_LIMIT_SET_TO_" + String (limit, 6 ));
24+ }
25+
26+ inline static OperationResult setLowerLimit (float limit) {
27+ DACLimits::lower_voltage_limit = limit;
28+ return OperationResult::Success (" LOWER_LIMIT_SET_TO_" + String (limit, 6 ));
29+ }
30+
2031 inline static void initializeRegistry () {
2132 registerMemberFunction (setVoltage, " SET" );
2233 registerMemberFunction (getVoltage, " GET_DAC" );
@@ -28,6 +39,8 @@ class DACController {
2839 registerMemberFunction (autoRamp2, " RAMP2" );
2940 registerMemberFunctionVector (autoRampN, " RAMP_N" );
3041 registerMemberFunction (toggleLdacTest, " TOGGLE_LDAC" );
42+ registerMemberFunction (setUpperLimit, " SET_UPPER_LIMIT" );
43+ registerMemberFunction (setLowerLimit, " SET_LOWER_LIMIT" );
3144 }
3245
3346 inline static void addChannel (int cs_pin) {
@@ -68,6 +81,9 @@ class DACController {
6881 return OperationResult::Failure (" Invalid channel index " +
6982 String (channel_index));
7083 }
84+ // Fast clamp voltage to global limits
85+ voltage = DACLimits::clampVoltage (voltage);
86+
7187 DACChannel dac_channel = dac_channels[channel_index];
7288 if (voltage < dac_channel.getLowerBound () ||
7389 voltage > dac_channel.getUpperBound ()) {
@@ -84,6 +100,9 @@ class DACController {
84100 if (!isChannelIndexValid (channel_index)) {
85101 return ;
86102 }
103+ // Fast clamp voltage to global limits
104+ voltage = DACLimits::clampVoltage (voltage);
105+
87106 DACChannel dac_channel = dac_channels[channel_index];
88107 if (voltage < dac_channel.getLowerBound () ||
89108 voltage > dac_channel.getUpperBound ()) {
0 commit comments