/// <summary> /// Set custom battery extended profile /// </summary> /// <param name="batteryProfile">Custom battery extended profile</param> public void SetCustomBatteryExtProfile(BatteryExtendedProfile batteryProfile) { var data = new byte[17]; data[0] = (byte)batteryProfile.BatteryChemistry; data[1] = (byte)((int)batteryProfile.OpenCircuitVoltage10Percent.Millivolts & 0xFF); data[2] = (byte)(((int)batteryProfile.OpenCircuitVoltage10Percent.Millivolts >> 8) & 0xFF); data[3] = (byte)((int)batteryProfile.OpenCircuitVoltage50Percent.Millivolts & 0xFF); data[4] = (byte)(((int)batteryProfile.OpenCircuitVoltage50Percent.Millivolts >> 8) & 0xFF); data[5] = (byte)((int)batteryProfile.OpenCircuitVoltage90Percent.Millivolts & 0xFF); data[6] = (byte)(((int)batteryProfile.OpenCircuitVoltage90Percent.Millivolts >> 8) & 0xFF); data[7] = (byte)((int)batteryProfile.InternalResistance10Percent.Milliohms & 0xFF); data[8] = (byte)(((int)batteryProfile.InternalResistance10Percent.Milliohms >> 8) & 0xFF); data[9] = (byte)((int)batteryProfile.InternalResistance50Percent.Milliohms & 0xFF); data[10] = (byte)(((int)batteryProfile.InternalResistance50Percent.Milliohms >> 8) & 0xFF); data[11] = (byte)((int)batteryProfile.InternalResistance90Percent.Milliohms & 0xFF); data[12] = (byte)(((int)batteryProfile.InternalResistance90Percent.Milliohms >> 8) & 0xFF); data[13] = 0xFF; data[14] = 0xFF; data[15] = 0xFF; data[16] = 0xFF; _piJuice.WriteCommandVerify(PiJuiceCommand.BatteryExtendedProfile, data); }
/// <summary> /// Get Battery extended profile /// </summary> /// <returns>Battery extended profile</returns> public BatteryExtendedProfile GetBatteryExtProfile() { var batteryProfile = new BatteryExtendedProfile(); var response = _piJuice.ReadCommand(PiJuiceCommand.BatteryExtendedProfile, 17); if (response[0] < 2) { batteryProfile.BatteryChemistry = (BatteryChemistry)response[0]; } else { batteryProfile.BatteryChemistry = BatteryChemistry.Unknown; } batteryProfile.OpenCircuitVoltage10Percent = new ElectricPotential((response[2] << 8) | response[1], ElectricPotentialUnit.Millivolt); batteryProfile.OpenCircuitVoltage50Percent = new ElectricPotential((response[4] << 8) | response[3], ElectricPotentialUnit.Millivolt); batteryProfile.OpenCircuitVoltage90Percent = new ElectricPotential((response[6] << 8) | response[5], ElectricPotentialUnit.Millivolt); batteryProfile.InternalResistance10Percent = new ElectricResistance(((response[8] << 8) | response[7]) / 100.0, ElectricResistanceUnit.Milliohm); batteryProfile.InternalResistance50Percent = new ElectricResistance(((response[10] << 8) | response[9]) / 100.0, ElectricResistanceUnit.Milliohm); batteryProfile.InternalResistance90Percent = new ElectricResistance(((response[12] << 8) | response[11]) / 100.0, ElectricResistanceUnit.Milliohm); return(batteryProfile); }