예제 #1
0
파일: I2cHelper.cs 프로젝트: isammour/LUCT
 public static async void HandleRFlag(byte r)
 {
     if (r == 0)
     {
         await I2cHelper.WriteRead(new Slave()
         {
             I2cAddress = 9
         }, Mode.Mode1, 0, 0, new SmsSlaveModel()
         {
             Sflag = 0, SmsSend = 1, Switch1 = AppKeys.Switch1 ? 1:0, Switch2 = AppKeys.Switch2 ? 1 : 0
         });
     }
     else if (r == 1)
     {
         int s1 = 1, s2 = 1;
         if (AppKeys.Switch1 == true)
         {
             s1 = 0;
         }
         if (AppKeys.Switch2 == true)
         {
             s2 = 0;
         }
         AppKeys.Switch2 = AppKeys.Switch1 = false;
         await I2cHelper.WriteRead(new Slave()
         {
             I2cAddress = 9
         }, Mode.Mode1, 0, 0, new SmsSlaveModel()
         {
             Sflag = Sflag.Shutdowned, SmsSend = 1, Switch1 = s1, Switch2 = s2
         });
     }
     else if (r == 2)
     {
         int s1 = 0, s2 = 0;
         if (AppKeys.Switch1 == false)
         {
             s1 = 1;
         }
         if (AppKeys.Switch2 == true)
         {
             s2 = 1;
         }
         AppKeys.Switch1 = false;
         await I2cHelper.WriteRead(new Slave()
         {
             I2cAddress = 9
         }, Mode.Mode1, 0, 0, new SmsSlaveModel()
         {
             Sflag = Sflag.SleepMode, SmsSend = 1, Switch1 = s1, Switch2 = s2
         });
     }
 }
예제 #2
0
파일: I2cHelper.cs 프로젝트: isammour/LUCT
        public static async void DecodeRespose(int slaveId, byte[] response)
        {
            if (slaveId == 8)
            {
                if (response[0] == 1)
                {
                    await App.LUCTGPIOService.CapturePhoto();

                    await I2cHelper.WriteRead(new Slave()
                    {
                        I2cAddress = 9
                    }, Mode.Mode1, 0, 0, new SmsSlaveModel()
                    {
                        Sflag = Sflag.BadKeyPadAttempts, SmsSend = 1, Switch1 = -1, Switch2 = -1
                    });
                }
                if (response[1] == 1 || response[2] == 1)
                {
                    App.LUCTGPIOService.ChangeLedState(true);
                }
            }
            else
            {
                SensorsData sensor = new SensorsData()
                {
                    TankLevel   = response[0],
                    Temperature = response[1],
                    Humidity    = response[2],
                    Current     = (((response[4] + response[5])) * 220 * 0.9) / 1000
                };
                Debug.WriteLine(response[0]);
                SensorsBinder.dt = sensor;
                _database.InsertModel <SensorsData>(sensor);
                if ((response[4]) * 220 * 0.9 > 4000)
                {
                    AppKeys.Switch1State = true;
                    //AppKeys.Switch1 = true ;
                }
                else
                {
                    AppKeys.Switch1State = false;
                    //AppKeys.Switch1 = false;
                }
                if ((response[5]) * 220 * 0.9 > 4000)
                {
                    AppKeys.Switch2State = true;
                    //AppKeys.Switch2 = true;
                }
                else
                {
                    AppKeys.Switch2State = false;
                    //AppKeys.Switch2 = false;
                }
                if (response[7] == 1)
                {
                    _database.InsertModel <Models.Database.PillsTaken>(new Models.Database.PillsTaken()
                    {
                        Time = DateTime.Now
                    });
                    AppKeys.PillState = true;
                }
                else
                {
                    AppKeys.PillState = false;
                }

                HandleRFlag(response[6]);

                Debug.WriteLine(response[4] * 220 * 0.9 + " From i2c switch 1");
                Debug.WriteLine(response[5] * 220 * 0.9 + "From i2c switch 2");
            }
        }