void VoltageEvent(object sender, CSLibrary.Notification.VoltageEventArgs e) { InvokeOnMainThread(() => { if (e.Voltage == 0xffff) { _labelVoltage = "CS108 Bat. ERROR"; // 3.98v } else { // to fix CS108 voltage bug if (_cancelVoltageValue) { _cancelVoltageValue = false; return; } switch (BleMvxApplication._config.BatteryLevelIndicatorFormat) { case 0: _labelVoltage = "CS108 Bat. " + ((double)e.Voltage / 1000).ToString("0.000") + "v"; // v break; default: _labelVoltage = "CS108 Bat. " + ClassBattery.Voltage2Percent((double)e.Voltage / 1000).ToString("0") + "%"; // % break; } } RaisePropertyChanged(() => labelVoltage); }); }
void VoltageEvent(object sender, CSLibrary.Notification.VoltageEventArgs e) { InvokeOnMainThread(() => { if (e.Voltage == 0xffff) { _labelVoltage = "CS108 Bat. ERROR"; // 3.98v } else { // to fix CS108 voltage bug if (_cancelVoltageValue) { _cancelVoltageValue = false; return; } double voltage = (double)e.Voltage / 1000; { var batlow = ClassBattery.BatteryLow(voltage); if (BleMvxApplication._batteryLow && batlow == ClassBattery.BATTERYLEVELSTATUS.NORMAL) { BleMvxApplication._batteryLow = false; RaisePropertyChanged(() => labelVoltageTextColor); } else if (!BleMvxApplication._batteryLow && batlow != ClassBattery.BATTERYLEVELSTATUS.NORMAL) { BleMvxApplication._batteryLow = true; if (batlow == ClassBattery.BATTERYLEVELSTATUS.LOW) { _userDialogs.AlertAsync("20% Battery Life Left, Please Recharge CS108 or Replace Freshly Charged CS108B"); } //else if (batlow == ClassBattery.BATTERYLEVELSTATUS.LOW_17) // _userDialogs.AlertAsync("8% Battery Life Left, Please Recharge CS108 or Replace with Freshly Charged CS108B"); RaisePropertyChanged(() => labelVoltageTextColor); } } switch (BleMvxApplication._config.BatteryLevelIndicatorFormat) { case 0: _labelVoltage = "CS108 Bat. " + voltage.ToString("0.000") + "v"; // v break; default: _labelVoltage = voltage.ToString("0.000") + "v " + ClassBattery.Voltage2Percent(voltage).ToString("0") + "%"; // % //_labelVoltage = ClassBattery.Voltage2Percent((double)e.Voltage / 1000).ToString("0") + "% " + ((double)e.Voltage / 1000).ToString("0.000") + "v"; // % break; } } RaisePropertyChanged(() => labelVoltage); }); }