/// <summary> /// Sends a new set of settings to the device, to be written to flash. /// This takes about 26 ms. /// </summary> public unsafe void setSmcSettings(SmcSettings settings) { SmcSettingsStruct settingsStruct = settings.convertToStruct(); try { controlTransfer(0x40, (byte)SmcRequest.SetSettings, 0, 0, &settingsStruct, (UInt16)sizeof(SmcSettingsStruct)); } catch (Exception exception) { throw new Exception("There was an error writing settings to the device.", exception); } }
/// <summary> /// Reads the current settings from the device. /// </summary> public unsafe SmcSettings getSmcSettings() { SmcSettingsStruct settingsStruct = new SmcSettingsStruct(); UInt16 settingsSize = (UInt16)sizeof(SmcSettingsStruct); try { controlTransfer(0xC0, (byte)SmcRequest.GetSettings, 0, 0, &settingsStruct, settingsSize); } catch (Exception exception) { throw new Exception("There was an error reading settings from the device.", exception); } return(new SmcSettings(productId, settingsStruct)); }
internal SmcSettings(UInt16 productId, SmcSettingsStruct s) { this.productId = productId; // [Add-new-settings-here] this.neverSleep = (s.b1 & SmcBoolSettings1.NeverSleep) != 0; this.uartResponseDelay = (s.b1 & SmcBoolSettings1.UartResponseDelay) != 0; this.useFixedBaudRate = (s.b1 & SmcBoolSettings1.UseFixedBaudRate) != 0; this.disableSafeStart = (s.b1 & SmcBoolSettings1.DisableSafeStart) != 0; this.enableI2C = (s.b1 & SmcBoolSettings1.EnableI2C) != 0; this.ignoreErrLineHigh = (s.b1 & SmcBoolSettings1.IgnoreErrLineHigh) != 0; this.tempLimitGradual = (s.b1 & SmcBoolSettings1.TempLimitGradual) != 0; this.ignorePotDisconnect = (s.b1 & SmcBoolSettings1.IgnorePotDisconnect) != 0; this.motorInvert = (s.b1 & SmcBoolSettings1.MotorInvert) != 0; this.coastWhenOff = (s.b1 & SmcBoolSettings1.CoastWhenOff) != 0; this.crcForCommands = (s.b1 & SmcBoolSettings1.CrcForCommands) != 0; this.crcForResponses = (s.b1 & SmcBoolSettings1.CrcForResponses) != 0; this.fixedBaudRateBps = Smc.convertBaudRegisterToBps(s.fixedBaudRateRegister); this.speedUpdatePeriod = s.speedUpdatePeriod; this.commandTimeout = s.commandTimeout; this.serialDeviceNumber = s.serialDeviceNumber; this.overTempCompleteShutoffThreshold = s.overTempCompleteShutoffThreshold; this.overTempNormalOperationThreshold = s.overTempNormalOperationThreshold; this.inputMode = s.inputMode; this.pwmPeriodFactor = s.pwmPeriodFactor; this.mixingMode = s.mixingMode; this.minPulsePeriod = s.minPulsePeriod; this.maxPulsePeriod = s.maxPulsePeriod; this.rcTimeout = s.rcTimeout; this.consecGoodPulses = s.consecGoodPulses; this.vinScaleCalibration = s.vinScaleCalibration; this.lowVinShutoffTimeout = s.lowVinShutoffTimeout; this.lowVinShutoffMv = s.lowVinShutoffMv; this.lowVinStartupMv = s.lowVinStartupMv; this.highVinShutoffMv = s.highVinShutoffMv; this.serialMode = s.serialMode; this.rc1 = new SmcChannelSettings(s.rc1); this.rc2 = new SmcChannelSettings(s.rc2); this.analog1 = new SmcChannelSettings(s.analog1); this.analog2 = new SmcChannelSettings(s.analog2); this.forwardLimits = new SmcMotorLimits(s.forwardLimits); this.reverseLimits = new SmcMotorLimits(s.reverseLimits); this.currentLimit = s.currentLimit; this.currentOffsetCalibration = s.currentOffsetCalibration; this.currentScaleCalibration = s.currentScaleCalibration; }
internal SmcSettingsStruct convertToStruct() { SmcSettingsStruct s = new SmcSettingsStruct(); // [Add-new-settings-here] if (this.neverSleep) { s.b1 |= SmcBoolSettings1.NeverSleep; } if (this.uartResponseDelay) { s.b1 |= SmcBoolSettings1.UartResponseDelay; } if (this.useFixedBaudRate) { s.b1 |= SmcBoolSettings1.UseFixedBaudRate; } if (this.disableSafeStart) { s.b1 |= SmcBoolSettings1.DisableSafeStart; } if (this.enableI2C) { s.b1 |= SmcBoolSettings1.EnableI2C; } if (this.ignoreErrLineHigh) { s.b1 |= SmcBoolSettings1.IgnoreErrLineHigh; } if (this.tempLimitGradual) { s.b1 |= SmcBoolSettings1.TempLimitGradual; } if (this.ignorePotDisconnect) { s.b1 |= SmcBoolSettings1.IgnorePotDisconnect; } if (this.motorInvert) { s.b1 |= SmcBoolSettings1.MotorInvert; } if (this.coastWhenOff) { s.b1 |= SmcBoolSettings1.CoastWhenOff; } if (this.crcForCommands) { s.b1 |= SmcBoolSettings1.CrcForCommands; } if (this.crcForResponses) { s.b1 |= SmcBoolSettings1.CrcForResponses; } s.fixedBaudRateRegister = Smc.convertBpsToBaudRegister(this.fixedBaudRateBps); s.speedUpdatePeriod = this.speedUpdatePeriod; s.commandTimeout = this.commandTimeout; s.serialDeviceNumber = this.serialDeviceNumber; s.overTempCompleteShutoffThreshold = this.overTempCompleteShutoffThreshold; s.overTempNormalOperationThreshold = this.overTempNormalOperationThreshold; s.inputMode = this.inputMode; s.pwmPeriodFactor = this.pwmPeriodFactor; s.mixingMode = this.mixingMode; s.minPulsePeriod = this.minPulsePeriod; s.maxPulsePeriod = this.maxPulsePeriod; s.rcTimeout = this.rcTimeout; s.consecGoodPulses = this.consecGoodPulses; s.vinScaleCalibration = this.vinScaleCalibration; s.lowVinShutoffTimeout = this.lowVinShutoffTimeout; s.lowVinShutoffMv = this.lowVinShutoffMv; s.lowVinStartupMv = this.lowVinStartupMv; s.highVinShutoffMv = this.highVinShutoffMv; s.serialMode = this.serialMode; s.rc1 = this.rc1.convertToStruct(); s.rc2 = this.rc2.convertToStruct(); s.analog1 = this.analog1.convertToStruct(); s.analog2 = this.analog2.convertToStruct(); s.forwardLimits = this.forwardLimits.convertToStruct(); s.reverseLimits = this.reverseLimits.convertToStruct(); s.currentLimit = this.currentLimit; s.currentOffsetCalibration = this.currentOffsetCalibration; s.currentScaleCalibration = this.currentScaleCalibration; return(s); }