コード例 #1
0
ファイル: Program.cs プロジェクト: Nikituh/Thinkforce-Desktop
        static async Task RegisterDevice()
        {
            LampResponse response = await LampClient.RegisterDevice();

            if (response.IsOk)
            {
                ContentView.Indicator.IsConnected = true;
                Accounts.Add(new Account(LampClient.IP, LampClient.REGISTEREDUSERNAME));
                LocalStorage.Instance.Write(Accounts);
            }
            else
            {
                if (response.LinkNotPressedError)
                {
                    CreateLinkAlert();
                }
                else
                {
                    CreateAlert(response.Error.Description, "Something went terribly wrong",
                                delegate { },
                                delegate { }
                                );
                }
            }
        }
コード例 #2
0
        public static async Task <LampResponse> RegisterDevice()
        {
            LampResponse response = new LampResponse();

            string    url  = "http://" + IP + "/api";
            JsonValue json = Codec.EncodeRegistrationJson(APPNAME, APPKEY);

            WazombiNetworkingResponse intermediary = await WazombiNetworking.Post(url, json);

            if (intermediary.HasException)
            {
                response.Error = new LampError {
                    Type        = intermediary.Exception,
                    Description = "Oops! Something went terribly wrong. Please try again"
                };
            }
            else
            {
                response = Codec.DecodeLampResponse(intermediary.Json);

                if (response.IsOk)
                {
                    REGISTEREDUSERNAME = response.Username;
                }
            }

            return(response);
        }
コード例 #3
0
        public IActionResult Post([FromBody] LampResponse colour)
        {
            int clampedRed   = Math.Max(Math.Min(colour.Red, 255), 0);
            int clampedGreen = Math.Max(Math.Min(colour.Green, 255), 0);
            int clampedBlue  = Math.Max(Math.Min(colour.Blue, 255), 0);

            int redValue   = (int)Math.Round((clampedRed * 100) / 255f);
            int greenValue = (int)Math.Round((clampedGreen * 100) / 255f);
            int blueValue  = (int)Math.Round((clampedBlue * 100) / 255f);

            Console.WriteLine($"Changing colour to ({clampedRed}, {clampedGreen}, {clampedBlue})");

            Pi.Gpio[Program.RedPin].SoftPwmValue   = redValue;
            Pi.Gpio[Program.GreenPin].SoftPwmValue = greenValue;
            Pi.Gpio[Program.BluePin].SoftPwmValue  = blueValue;
            return(Ok());
        }
コード例 #4
0
ファイル: Codec.cs プロジェクト: Nikituh/Thinkforce-Desktop
        public static LampResponse DecodeLampResponse(JsonValue json)
        {
            LampResponse response = new LampResponse();

            foreach (KeyValuePair <string, JsonValue> child in json)
            {
                if (child.Value.ContainsKey(ERROR))
                {
                    response.Error = DecodeError(child.Value);
                }
                else if (child.Value.ContainsKey(SUCCESS))
                {
                    response.Username = (string)child.Value[SUCCESS][USERNAME];
                }
            }

            return(response);
        }