public static PowerUsageHistory Constructor() { PowerUsageHistory str = new PowerUsageHistory(); str.values = new int[120]; return(str); }
void UpdatePowerMonitor() { if (!powerMonitorActive || communicator.ActiveDevice.Item1 == null) { return; } var r = communicator.SendCommand("powerhistory"); powerHistory = PowerUsageHistory.FromByteArray(r); FindViewById <TextView>(Resource.Id.textViewCurrentPower).SetText($"Current Power Draw: {powerHistory.values[0]} Watt", TextView.BufferType.Normal); UpdatePowerMonitorChart(); }
public static PowerUsageHistory FromByteArray(byte[] bytes) { PowerUsageHistory str = Constructor(); int size = Marshal.SizeOf(str); if (bytes.Length != size) { throw new ArgumentException($"Wrong size of byte array. Expecdey: {size}, actual {bytes.Length}."); } IntPtr ptr = Marshal.AllocHGlobal(size); Marshal.Copy(bytes, 0, ptr, size); str = (PowerUsageHistory)Marshal.PtrToStructure(ptr, str.GetType()); Marshal.FreeHGlobal(ptr); return(str); }