コード例 #1
0
        /// <summary>
        /// Read battery status continously
        /// </summary>
        public override void Start()
        {
            //shutdown
            SetControlRegister(SHUTDOWN_MODE, _prescalerSelected, ALERT_MODE);

            //configure params
            QLSB    = CHARGE_LEAST * (50 / SENSE_RESISTOR_VALUE) * (this._prescalerValue / 4096d); //maH
            QBATMAX = QLSB * 65536d;                                                               //mAH
            double QbatUsed   = BATTERY_CAPACITY_MAH / QLSB;                                       //number
            double LastCharge = QBATMAX - 0.5 * BATTERY_CAPACITY_MAH;                              // last charge default mAh

            _batteryUnderChargeStatus = GpioGlobalConnection.Read(_batteryUnderChargeGpio);

            // Set the charge counter to db value
            if (File.Exists("lastbatterychargestatus.txt"))
            {
                string bcs = File.ReadAllText("lastbatterychargestatus.txt");
                LastCharge = Convert.ToDouble(bcs);
            }

            SetChargeMAHToRegister(LastCharge);

            SetControlRegister(AUTOMATIC_MODE, _prescalerSelected, ALERT_MODE);
            SetVoltageThresholdHigh(8.3f);
            SetVoltageThresholdLow(6.5f);

            base.Start();
            Task.Factory.StartNew(() => ReadContinuosly(_cancellationTokenSource.Token), _cancellationTokenSource.Token, TaskCreationOptions.LongRunning, TaskScheduler.Default).ConfigureAwait(false);
            Console.WriteLine("LTC2943: Started");
        }
コード例 #2
0
 public LTC2943Service() : base((int)LTC2943_Constants.ADDRESS)
 {
     this.Enabled            = this.InitSensor();
     _batteryUnderChargeGpio = ProcessorPin.Gpio33;//GPIO33, led di carica
     GpioGlobalConnection.Add(_batteryUnderChargeGpio, false);
     GpioGlobalConnection.GlobalConnectionPin.PinStatusChanged += GlobalConnectionPin_PinStatusChanged;
     _chargeStatus             = ChargeStatusType.NotCharging;
     _prescalerSelected        = PRESCALER_1024;
     _batteryUnderChargeStatus = true;
     BATTERY_NOMINAL_VOLTAGE   = 7.2;
     BATTERY_MAX_VOLTAGE       = 8.38;
 }
コード例 #3
0
 public void Close()
 {
     GpioGlobalConnection.Remove(_batteryUnderChargeGpio);
     GpioGlobalConnection.Stop();
     base.Stop();
 }