Exemple #1
0
        public static PowerUsageHistory Constructor()
        {
            PowerUsageHistory str = new PowerUsageHistory();

            str.values = new int[120];

            return(str);
        }
Exemple #2
0
        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();
        }
Exemple #3
0
        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);
        }