Ejemplo n.º 1
0
        public JObject SetVoltage([FromBody] BatteryInformation battery)
        {
            try
            {
                var context = new DatabaseContext();
                context.Batteries.Add(new Battery()
                {
                    BatteryId = context.Settings.Find(Int32.Parse(ConfigurationManager.AppSettings.Get("Battery"))).Value, Voltage = (float)battery.Voltage, DateTime = DateTime.Now
                });
                context.SaveChanges();

                var informationSend = context.Settings.Find(Int32.Parse(ConfigurationManager.AppSettings.Get("BatteryInformationSend")));
                if (informationSend.Value != null && battery.Voltage > 12)
                {
                    informationSend.Value = null;
                    context.SaveChanges();
                }
                if (informationSend.Value == null && battery.Voltage < 11.5)
                {
                    var ib = new InformationBroker();
                    ib.SendSms(InformationBroker.BatteryLow);
                    informationSend.Value = "Mega";
                    context.SaveChanges();
                }
                var value = "{ \"response\": \"success\" }";
                return(JObject.Parse(value));
            }
            catch (Exception e)
            {
                var value = "{ \"response\": \"error " + e.Message + "\" }";
                return(JObject.Parse(value));
            }
        }
Ejemplo n.º 2
0
 private void UpdateAppTrayText(Controller controller, BatteryInformation batteryInformation)
 {
     _notifyIcon.Text = Resources.NotificationIconText
                        .Replace(Resources.UserIndexPlaceholder, controller.UserIndex.ToString())
                        .Replace(Resources.BatteryTypePlaceholder, batteryInformation.BatteryType.ToString())
                        .Replace(Resources.BatteryLevelPlaceholder, batteryInformation.BatteryLevel.ToString());
 }
Ejemplo n.º 3
0
        static uint XInputGetBatteryInformation_Hooked(int dwUserIndex, int devType, out BatteryInformation pBatteryInformation)
        {
            pBatteryInformation = new BatteryInformation();
            try
            {
                ControllerReader myController = ControllerReader.Instance;

                if (myController.controllers.Count < dwUserIndex)
                {
                    return(ERROR_DEVICE_NOT_CONNECTED);
                }

                pBatteryInformation.BatteryType  = BatteryType.Wired;
                pBatteryInformation.BatteryLevel = BatteryLevel.Full;

                XboxOneControllerInjection This = (XboxOneControllerInjection)HookRuntimeInfo.Callback;

                lock (This.Queue)
                {
                    if (This.Queue.Count < 1000)
                    {
                        This.Queue.Push("XInputGetBatteryInformation");
                    }
                }
            }
            catch
            {
                return(ERROR_DEVICE_NOT_CONNECTED);
            }
            return(ERROR_SUCCESS);
        }
Ejemplo n.º 4
0
        private void UpdateAppTrayIcon(BatteryInformation batteryInformation)
        {
            switch (batteryInformation.BatteryLevel)
            {
            case BatteryLevel.Empty:
                _notifyIcon.Icon = Resources.batteryIcon_0;
                break;

            case BatteryLevel.Low:
                _notifyIcon.Icon = Resources.batteryIcon_33;
                break;

            case BatteryLevel.Medium:
                _notifyIcon.Icon = Resources.batteryIcon_66;
                break;

            case BatteryLevel.Full:
                _notifyIcon.Icon = Resources.batteryIcon_100;
                break;

            default:
                _notifyIcon.Icon = Resources.AppIcon;
                break;
            }
        }
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            BatteryInformation info = (BatteryInformation)value;

            switch (info.BatteryLevel)
            {
            case BatteryLevel.Empty:
                if (info.BatteryType == BatteryType.Unknown || info.BatteryType == BatteryType.Disconnected)
                {
                    return(Application.Current.FindResource("GamepadBatteryUnknown"));
                }
                return(Application.Current.FindResource("GamepadBatteryEmpty"));

            case BatteryLevel.Low:
                return(Application.Current.FindResource("GamepadBatteryLow"));

            case BatteryLevel.Medium:
                return(Application.Current.FindResource("GamepadBatteryMedium"));

            case BatteryLevel.Full:
                return(Application.Current.FindResource("GamepadBatteryFull"));

            default:
                return(Application.Current.FindResource("GamepadOff"));
            }
        }
Ejemplo n.º 6
0
        public void UpdateBatteryState()
        {
            BatteryInformation headset = new BatteryInformation(),
            gamepad = new BatteryInformation();

            XInput.XInput.XInputGetBatteryInformation(_playerIndex, (byte)BatteryDeviceType.BATTERY_DEVTYPE_GAMEPAD, ref gamepad);
            XInput.XInput.XInputGetBatteryInformation(_playerIndex, (byte)BatteryDeviceType.BATTERY_DEVTYPE_HEADSET, ref headset);

            BatteryInformationHeadset = headset;
            BatteryInformationGamepad = gamepad;
        }
Ejemplo n.º 7
0
            void Update(object state)
            {
                while (_check == false)
                {
                    this._batteryInfo = BatteryInfo.GetBatteryInformation();
                    if (this._last_batteryInfo.CurrentCapacity != this._batteryInfo.CurrentCapacity)
                    {
                        this._last_batteryInfo = this._batteryInfo;

                        this.BatteryStatusUpdate?.Invoke(this, this._batteryInfo);
                    }
                }
            }
Ejemplo n.º 8
0
        static void Main(string[] args)
        {
            Controller xbox = new Controller(UserIndex.One);

            Console.WriteLine("Controller connected: " + xbox.IsConnected);
            BatteryInformation battery = xbox.GetBatteryInformation(BatteryDeviceType.Gamepad);

            Console.WriteLine("Battery level: " + battery.BatteryLevel);

            bool isRunning = true;


            while (isRunning)
            {
                Console.Clear();
                State state = xbox.GetState();

                switch (state.Gamepad.Buttons)
                {
                case GamepadButtonFlags.Start:
                    isRunning = false;
                    break;

                default:
                    break;
                }

                Console.Write("Key pressed: " + state.Gamepad.Buttons + "\n");
                Console.Write("RightThumbX stick: " + state.Gamepad.RightThumbX + "\n");
                Console.Write("RightThumbY stick: " + state.Gamepad.RightThumbY + "\n");
                Console.Write("LeftThumbX stick: " + state.Gamepad.LeftThumbX + "\n");
                Console.Write("LeftThumbY stick: " + state.Gamepad.LeftThumbY + "\n");
                Console.Write("LeftTrigger: " + state.Gamepad.LeftTrigger + "\n");
                Console.Write("RightTrigger: " + state.Gamepad.RightTrigger + "\n");

                int vibrationLeftMotorSpeed = 0;


                if (state.Gamepad.LeftThumbX > -1)
                {
                    vibrationLeftMotorSpeed = state.Gamepad.LeftThumbX;
                }

                vibration.LeftMotorSpeed = (ushort)vibrationLeftMotorSpeed;
                xbox.SetVibration(vibration);
                System.Threading.Thread.Sleep(100);
            }
        }
Ejemplo n.º 9
0
        private void updateInfo(Controller c)
        {
            BatteryInformation gamepadBattery = c.GetBatteryInformation(BatteryDeviceType.Gamepad);
            BatteryInformation headsetBattery = c.GetBatteryInformation(BatteryDeviceType.Headset);

            Capabilities gamepadCapa = c.GetCapabilities(DeviceQueryType.Gamepad);
            Vibration    v           = gamepadCapa.Vibration;
            string       vibeString  = "L: " + (v.LeftMotorSpeed == 255).ToString() + "  |  R: " + (v.RightMotorSpeed == 255).ToString();

            Dictionary <string, string> infoDict = new Dictionary <string, string>
            {
                { "GamepadBatteryType", gamepadBattery.BatteryType.ToString() },
                { "GamepadBatteryLevel", gamepadBattery.BatteryLevel.ToString() },
                { "HeadsetBatteryType", headsetBattery.BatteryType.ToString() },
                { "HeadsetBatteryLevel", headsetBattery.BatteryLevel.ToString() },
                { "GamepadFlags", gamepadCapa.Flags.ToString() },
                { "GamepadType", gamepadCapa.Type.ToString() },
                { "GamepadSubType", gamepadCapa.SubType.ToString() },
                { "Vibration", vibeString },
            };

            int totalCount = 0;

            XInputInfoList.BeginUpdate();
            foreach (KeyValuePair <string, string> pair in infoDict)
            {
                ListViewItem item = new ListViewItem();
                item.Text = pair.Key.ToString();
                item.SubItems.Add(pair.Value);

                if (XInputInfoList.Items.Count <= (totalCount))
                {
                    XInputInfoList.Items.Add(item);
                }
                else
                {
                    XInputInfoList.Items[totalCount] = item;
                }
                totalCount++;
            }
            XInputInfoList.EndUpdate();
        }
        private System.Drawing.Icon getBatteryLevelIcon(BatteryInformation batteryInfo)
        {
            switch (batteryInfo.BatteryLevel)
            {
            case BatteryLevel.Empty:
                return(XboxOneBatteryApp.Resource.empty);

            case BatteryLevel.Low:
                return(XboxOneBatteryApp.Resource.low);

            case BatteryLevel.Medium:
                return(XboxOneBatteryApp.Resource.medium);

            case BatteryLevel.Full:
                return(XboxOneBatteryApp.Resource.full);

            default:
                break;
            }

            return(null);
        }
Ejemplo n.º 11
0
        uint XInputGetBatteryInformation_Hooked(int dwUserIndex, int devType, out BatteryInformation pBatteryInformation)
        {
            pBatteryInformation = new BatteryInformation();

            var controller = new Controller((UserIndex)dwUserIndex);

            if (controller.IsConnected)
            {
                try
                {
                    pBatteryInformation = controller.GetBatteryInformation((BatteryDeviceType)devType);
                }
                catch
                {
                    return(ERROR_DEVICE_NOT_CONNECTED);
                }
            }
            else
            {
                pBatteryInformation.BatteryLevel = BatteryLevel.Full;
            }

            return(ERROR_SUCCESS);
        }
Ejemplo n.º 12
0
 /// <summary>
 /// Retrieves the battery type and charge status of a wireless controller.
 /// </summary>
 /// <param name="userIndex">Index of the signed-in gamer associated with the device. Can be a value in the range 0–<see cref="UserIndex.MaxCount"/> − 1.</param>
 /// <param name="devType">Specifies which device associated with this user index should be queried. Must be <see cref="BatteryDeviceType.Gamepad"/> or <see cref="BatteryDeviceType.Headset"/>.</param>
 /// <param name="batteryInformation">An <see cref="BatteryInformation"/> structure that receives the battery information.</param>
 /// <returns>If the function succeeds, the return value is <see cref="Error.Success"/>.</returns>
 public static Error GetBatteryInformation(UserIndex userIndex, BatteryDeviceType devType, out BatteryInformation batteryInformation)
 {
     return(XInputGetBatteryInformation(userIndex, devType, out batteryInformation));
 }
Ejemplo n.º 13
0
 private static extern Error XInputGetBatteryInformation(UserIndex userIndex, BatteryDeviceType devType, out BatteryInformation batteryInformation);
Ejemplo n.º 14
0
 public static extern int XInputGetBatteryInformation(int dwUserIndex, BatteryDeviceType devType, out BatteryInformation batteryInformationRef);
Ejemplo n.º 15
0
 public static extern uint XInputGetBatteryInformation(
     uint dwUserIndex,                          // Index of the gamer associated with the device
     BatteryDevType devType,                    // A BATTERY_DEVTYPE
     ref BatteryInformation pBatteryInformation // Battery status
     );
Ejemplo n.º 16
0
 public BatteryStatus()
 {
     this._last_batteryInfo = new BatteryInformation();
 }
        // Updates the public variables
        public void update()
        {
            // Make sure controller is connected
            try {
                connected = controller.IsConnected;
            } catch (Exception err) { return; }
            if (connected == false)
            {
                return;
            }

            // Helper variables
            gamepad = controller.GetState().Gamepad;
            GamepadButtonFlags btns = controller.GetState().Gamepad.Buttons;

            batteryInfo = controller.GetBatteryInformation(BatteryDeviceType.Gamepad);


            // Thumbsticks
            leftThumb.X  = Convert.ToInt32((Math.Abs((float)gamepad.LeftThumbX) < deadband) ? 0 : (float)gamepad.LeftThumbX / short.MinValue * -100);
            leftThumb.Y  = Convert.ToInt32((Math.Abs((float)gamepad.LeftThumbY) < deadband) ? 0 : (float)gamepad.LeftThumbY / short.MaxValue * 100);
            rightThumb.X = Convert.ToInt32((Math.Abs((float)gamepad.RightThumbX) < deadband) ? 0 : (float)gamepad.RightThumbX / short.MaxValue * 100);
            rightThumb.Y = Convert.ToInt32((Math.Abs((float)gamepad.RightThumbY) < deadband) ? 0 : (float)gamepad.RightThumbY / short.MaxValue * 100);

            // Triggers
            leftTrigger  = gamepad.LeftTrigger;
            rightTrigger = gamepad.RightTrigger;

            // A, B, X, Y
            buttons.A = (btns & GamepadButtonFlags.A) != 0;
            buttons.B = (btns & GamepadButtonFlags.B) != 0;
            buttons.X = (btns & GamepadButtonFlags.X) != 0;
            buttons.Y = (btns & GamepadButtonFlags.Y) != 0;

            // Left and Right bumpers
            buttons.LB = (btns & GamepadButtonFlags.LeftShoulder) != 0;
            buttons.RB = (btns & GamepadButtonFlags.RightShoulder) != 0;

            // Clicking left and right thumbsticks
            buttons.LeftStick  = (btns & GamepadButtonFlags.LeftThumb) != 0;
            buttons.RightStick = (btns & GamepadButtonFlags.RightThumb) != 0;

            // Start & Back
            buttons.Back  = (btns & GamepadButtonFlags.Back) != 0;
            buttons.Start = (btns & GamepadButtonFlags.Start) != 0;

            // D-Pad
            buttons.DLeft  = (btns & GamepadButtonFlags.DPadLeft) != 0;
            buttons.DUp    = (btns & GamepadButtonFlags.DPadUp) != 0;
            buttons.DRight = (btns & GamepadButtonFlags.DPadRight) != 0;
            buttons.DDown  = (btns & GamepadButtonFlags.DPadDown) != 0;

            // Battery
            batteryLevel = batteryInfo.BatteryLevel.ToString();
            Console.WriteLine(batteryLevel);
            batteryType = batteryInfo.BatteryType.ToString();

            switch (batteryInfo.BatteryLevel)
            {
            case BatteryLevel.Empty:
                batteryColor = Color.DarkGray;
                break;

            case BatteryLevel.Low:
                batteryColor = Color.Red;
                break;

            case BatteryLevel.Medium:
                batteryColor = Color.Orange;
                break;

            case BatteryLevel.Full:
                batteryColor = Color.Green;
                break;
            }
        }