public SensorMeasurementSessionService()
        {
            _repoManager = App.Container.Resolve <IRepoManager>();

            _sensorMeasurementSessionRepository = _repoManager.SensorMeasurementSessionRepository;
            _sensorMeasurementSession           = new SensorMeasurementSession();
        }
Example #2
0
 public static TabiApiClient.Models.SensorMeasurementSession ToApiModel(this SensorMeasurementSession session)
 {
     return(new TabiApiClient.Models.SensorMeasurementSession()
     {
         AmbientLight = session.AmbientLight,
         BatteryLevel = session.BatteryLevel,
         BatteryState = (int)session.BatteryStatus,
         Pedometer = session.Pedometer,
         Proximity = session.Proximity,
         Compass = session.Compass,
         Timestamp = session.Timestamp
     });
 }
        private void TimerElapsed(object sender, ElapsedEventArgs e)
        {
            // get data from _sensorMeasurementSession
            // insert datetimeoffset
            _sensorMeasurementSession.Timestamp = DateTimeOffset.Now;


            //battery info
            using (IntentFilter filter = new IntentFilter(Intent.ActionBatteryChanged))
            {
                using (Intent battery = Application.Context.RegisterReceiver(null, filter))
                {
                    int level          = battery.GetIntExtra(BatteryManager.ExtraLevel, -1);
                    int scale          = battery.GetIntExtra(BatteryManager.ExtraScale, -1);
                    int level_0_to_100 = Convert.ToInt32(Math.Floor(level * 100D / scale));
                    _sensorMeasurementSession.BatteryLevel = level_0_to_100;

                    // batterystatus
                    BatteryStatus status = (BatteryStatus)battery.GetIntExtra(BatteryManager.ExtraStatus, -1);
                    switch (status)
                    {
                    case BatteryStatus.Charging:
                        _sensorMeasurementSession.BatteryStatus = BatteryEntryState.Charging;
                        break;

                    case BatteryStatus.Discharging:
                        _sensorMeasurementSession.BatteryStatus = BatteryEntryState.Discharging;
                        break;

                    case BatteryStatus.NotCharging:
                        _sensorMeasurementSession.BatteryStatus = BatteryEntryState.NotCharging;
                        break;

                    case BatteryStatus.Full:
                        _sensorMeasurementSession.BatteryStatus = BatteryEntryState.Full;
                        break;

                    case BatteryStatus.Unknown:
                        _sensorMeasurementSession.BatteryStatus = BatteryEntryState.Unknown;
                        break;
                    }
                }
            }

            // push to database
            _sensorMeasurementSessionRepository.Add(_sensorMeasurementSession);

            //clean object
            _sensorMeasurementSession = new SensorMeasurementSession();
        }
        private void SensorMeasurementSessionTimerElapsed(object sender, ElapsedEventArgs e)
        {
            SensorMeasurementSession sensorMeasurementSession = new SensorMeasurementSession
            {
                Timestamp = DateTimeOffset.Now
            };

            //pedometer
            sensorMeasurementSession.Pedometer = _pedometerInt;

            //compass
            sensorMeasurementSession.Compass = Convert.ToInt32(_locationManager.Heading.MagneticHeading);

            // proximity
            sensorMeasurementSession.Proximity = UIDevice.CurrentDevice.ProximityState;

            //ambient light
            //sensorMeasurementSession.AmbientLight = Convert.ToInt32(UIScreen.MainScreen.Brightness); // works only with dynamic brightness?
            //Console.WriteLine(UIScreen.MainScreen.Brightness);


            //battery
            sensorMeasurementSession.BatteryLevel = Convert.ToInt32(UIDevice.CurrentDevice.BatteryLevel * 100F);

            //sensorMeasurementSession.BatteryStatus =
            switch (UIDevice.CurrentDevice.BatteryState)
            {
            case UIDeviceBatteryState.Unknown:
                sensorMeasurementSession.BatteryStatus = BatteryEntryState.Unknown;
                break;

            case UIDeviceBatteryState.Unplugged:
                sensorMeasurementSession.BatteryStatus = BatteryEntryState.NotCharging;
                break;

            case UIDeviceBatteryState.Charging:
                sensorMeasurementSession.BatteryStatus = BatteryEntryState.Charging;
                break;

            case UIDeviceBatteryState.Full:
                sensorMeasurementSession.BatteryStatus = BatteryEntryState.Full;
                break;

            default:
                break;
            }

            _sensorMeasurementSessionRepository.Add(sensorMeasurementSession);
            Console.WriteLine("added sensormeasurementsession");
        }