Ejemplo n.º 1
0
 public void ReleaseDisplay()
 {
     using (var requestSocket = new RequestSocket())
     {
         requestSocket.Connect("tcp://127.0.0.1:3782");
         var request = new PiTopMessage(PiTop4MessageId.REQ_SET_OLED_CONTROL, "0");
         requestSocket.SendFrame(request.ToString());
     }
 }
Ejemplo n.º 2
0
 public void RequestDeviceId()
 {
     using (var requestSocket = new RequestSocket())
     {
         requestSocket.Connect("tcp://127.0.0.1:3782");
         var request = new PiTopMessage(PiTop4MessageId.REQ_GET_DEVICE_ID);
         requestSocket.SendFrame(request.ToString());
     }
 }
Ejemplo n.º 3
0
        private void ProcessBatteryState(PiTopMessage message)
        {
            var newState = BatteryState.FromMessage(message);

            if (!BatteryState.BatteryStateComparer.Equals(BatteryState, newState))
            {
                BatteryState = newState;
                BatteryStateChanged?.Invoke(this, newState);
            }
        }
Ejemplo n.º 4
0
        public static BatteryState FromMessage(PiTopMessage message)
        {
            var args = message.Parameters.ToArray();

            var chargingState = (BatteryChargingState)int.Parse(args[0]);
            var capacity      = double.Parse(args[1]);
            var timeRemaining = TimeSpan.FromMinutes(int.Parse(args[2]));
            var wattage       = double.Parse(args[3]);
            var state         = new BatteryState(chargingState, capacity, timeRemaining, wattage);

            return(state);
        }
Ejemplo n.º 5
0
        public Task RequestBatteryState()
        {
            var requestSocket = new RequestSocket();

            requestSocket.Connect("tcp://127.0.0.1:3782");
            var request = new PiTopMessage(PiTop4MessageId.REQ_GET_BATTERY_STATE);
            requestSocket.SendFrame(request.ToString());
            return Task.Run(() =>
            {
                var messageString = requestSocket.ReceiveFrameString();
                requestSocket.Dispose();
                var message = PiTopMessage.Parse(messageString);
                MessageReceived?.Invoke(this, message);
            });
        }
Ejemplo n.º 6
0
        private void ModuleDriverClientMessageReceived(object?sender, PiTopMessage message)
        {
            switch (message.Id)
            {
            case PiTopMessageId.REQ_PING:
                break;

            case PiTopMessageId.REQ_GET_DEVICE_ID:
                break;

            case PiTopMessageId.REQ_GET_BRIGHTNESS:
                break;

            case PiTopMessageId.REQ_SET_BRIGHTNESS:
                break;

            case PiTopMessageId.REQ_INCREMENT_BRIGHTNESS:
                break;

            case PiTopMessageId.REQ_DECREMENT_BRIGHTNESS:
                break;

            case PiTopMessageId.REQ_BLANK_SCREEN:
                break;

            case PiTopMessageId.REQ_UNBLANK_SCREEN:
                break;

            case PiTopMessageId.REQ_GET_BATTERY_STATE:
                break;

            case PiTopMessageId.REQ_GET_PERIPHERAL_ENABLED:
                break;

            case PiTopMessageId.REQ_GET_SCREEN_BLANKING_TIMEOUT:
                break;

            case PiTopMessageId.REQ_SET_SCREEN_BLANKING_TIMEOUT:
                break;

            case PiTopMessageId.REQ_GET_LID_OPEN_STATE:
                break;

            case PiTopMessageId.REQ_GET_SCREEN_BACKLIGHT_STATE:
                break;

            case PiTopMessageId.REQ_SET_SCREEN_BACKLIGHT_STATE:
                break;

            case PiTopMessageId.REQ_GET_OLED_CONTROL:
                break;

            case PiTopMessageId.REQ_SET_OLED_CONTROL:
                break;

            case PiTopMessageId.RSP_ERR_SERVER:
                break;

            case PiTopMessageId.RSP_ERR_MALFORMED:
                break;

            case PiTopMessageId.RSP_ERR_UNSUPPORTED:
                break;

            case PiTopMessageId.RSP_PING:
                break;

            case PiTopMessageId.RSP_GET_DEVICE_ID:
                break;

            case PiTopMessageId.RSP_GET_BRIGHTNESS:
                break;

            case PiTopMessageId.RSP_SET_BRIGHTNESS:
                break;

            case PiTopMessageId.RSP_INCREMENT_BRIGHTNESS:
                break;

            case PiTopMessageId.RSP_DECREMENT_BRIGHTNESS:
                break;

            case PiTopMessageId.RSP_GET_BATTERY_STATE:
                break;

            case PiTopMessageId.RSP_GET_PERIPHERAL_ENABLED:
                break;

            case PiTopMessageId.RSP_GET_SCREEN_BLANKING_TIMEOUT:
                break;

            case PiTopMessageId.RSP_SET_SCREEN_BLANKING_TIMEOUT:
                break;

            case PiTopMessageId.RSP_GET_LID_OPEN_STATE:
                break;

            case PiTopMessageId.RSP_GET_SCREEN_BACKLIGHT_STATE:
                break;

            case PiTopMessageId.RSP_SET_SCREEN_BACKLIGHT_STATE:
                break;

            case PiTopMessageId.RSP_GET_OLED_CONTROL:
                break;

            case PiTopMessageId.RSP_SET_OLED_CONTROL:
                break;

            case PiTopMessageId.PUB_BRIGHTNESS_CHANGED:
                break;

            case PiTopMessageId.PUB_PERIPHERAL_CONNECTED:
                break;

            case PiTopMessageId.PUB_PERIPHERAL_DISCONNECTED:
                break;

            case PiTopMessageId.PUB_SHUTDOWN_REQUESTED:
                break;

            case PiTopMessageId.PUB_REBOOT_REQUIRED:
                break;

            case PiTopMessageId.PUB_BATTERY_STATE_CHANGED:
                break;

            case PiTopMessageId.PUB_SCREEN_BLANKED:
                break;

            case PiTopMessageId.PUB_SCREEN_UNBLANKED:
                break;

            case PiTopMessageId.PUB_LOW_BATTERY_WARNING:
                BatteryStateChanged?.Invoke(this, BatteryState.Low);
                break;

            case PiTopMessageId.PUB_CRITICAL_BATTERY_WARNING:
                BatteryStateChanged?.Invoke(this, BatteryState.Critical);
                break;

            case PiTopMessageId.PUB_LID_CLOSED:
                break;

            case PiTopMessageId.PUB_LID_OPENED:
                break;

            case PiTopMessageId.PUB_UNSUPPORTED_HARDWARE:
                break;

            case PiTopMessageId.PUB_V3_BUTTON_UP_PRESSED:
                UpButton.State = PiTopButtonState.Pressed;
                break;

            case PiTopMessageId.PUB_V3_BUTTON_UP_RELEASED:
                UpButton.State = PiTopButtonState.Released;
                break;

            case PiTopMessageId.PUB_V3_BUTTON_DOWN_PRESSED:
                DownButton.State = PiTopButtonState.Pressed;
                break;

            case PiTopMessageId.PUB_V3_BUTTON_DOWN_RELEASED:
                DownButton.State = PiTopButtonState.Released;
                break;

            case PiTopMessageId.PUB_V3_BUTTON_SELECT_PRESSED:
                SelectButton.State = PiTopButtonState.Pressed;
                break;

            case PiTopMessageId.PUB_V3_BUTTON_SELECT_RELEASED:
                SelectButton.State = PiTopButtonState.Released;
                break;

            case PiTopMessageId.PUB_V3_BUTTON_CANCEL_PRESSED:
                CancelButton.State = PiTopButtonState.Pressed;
                break;

            case PiTopMessageId.PUB_V3_BUTTON_CANCEL_RELEASED:
                CancelButton.State = PiTopButtonState.Released;
                break;

            case PiTopMessageId.PUB_KEYBOARD_DOCKED:
                break;

            case PiTopMessageId.PUB_KEYBOARD_UNDOCKED:
                break;

            case PiTopMessageId.PUB_KEYBOARD_CONNECTED:
                break;

            case PiTopMessageId.PUB_FAILED_KEYBOARD_CONNECT:
                break;

            case PiTopMessageId.PUB_OLED_CONTROL_CHANGED:
                break;

            case PiTopMessageId.PUB_NATIVE_DISPLAY_CONNECTED:
                break;

            case PiTopMessageId.PUB_NATIVE_DISPLAY_DISCONNECTED:
                break;

            case PiTopMessageId.PUB_EXTERNAL_DISPLAY_CONNECTED:
                break;

            case PiTopMessageId.PUB_EXTERNAL_DISPLAY_DISCONNECTED:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Ejemplo n.º 7
0
 private void ResponseSocketOnReceiveReady(object? sender, NetMQSocketEventArgs e)
 {
     var messageString = e.Socket.ReceiveFrameString();
     var message = PiTopMessage.Parse(messageString);
     MessageReceived?.Invoke(this, message);
 }