public bool Update(bool canUpdate, bool batteryInteresting) { bool ret = false; OmDevice omdev = GetDevice(); if (omdev == null) { return(false); } if (canUpdate) { ret = omdev.Update(); if (batteryInteresting && lastUpdatedBattery == DateTime.MinValue || DateTime.Now - lastUpdatedBattery > TimeSpan.FromSeconds(5)) { int batteryLevel = OmApi.OmGetBatteryLevel(Id); if (batteryLevel != this.BatteryLevel) { this.BatteryLevel = batteryLevel; ret = true; } } } return(ret); }
void configure_Completed(object sender, Configure.CompletedEventArgs e) { string label; string info; if (e.Error != null) // Internal exception { label = "ERROR"; info = e.Error.ToString(); Mode = DeviceStatus.DeviceMode.Error; } else if (e.ExitCode < 0) // External error code { label = "ERROR"; info = "" + e.ExitCode + " " + (e.ErrorMessages == null ? "" : e.ErrorMessages); Mode = DeviceStatus.DeviceMode.Error; } else if (e.ExitCode == 42) // { label = "FLAGGED"; info = "" + e.Error + " [FLAGGED] " + (e.ErrorMessages == null ? "" : e.ErrorMessages); OmDevice omdev = GetDevice(); if (omdev != null) { omdev.SetLed(OmApi.OM_LED_STATE.OM_LED_CYAN); } Mode = DeviceStatus.DeviceMode.Failed; } else if (e.ExitCode > 0) // { label = "FAIL"; info = "" + e.Error + " " + (e.ErrorMessages == null ? "" : e.ErrorMessages); OmDevice omdev = GetDevice(); if (omdev != null) { omdev.SetLed(OmApi.OM_LED_STATE.OM_LED_BLUE); } Mode = DeviceStatus.DeviceMode.Failed; } else { label = "OK"; info = ""; Console.WriteLine("Configuration stopped - OK"); OmDevice omdev = GetDevice(); if (omdev != null) { omdev.SetLed(OmApi.OM_LED_STATE.OM_LED_MAGENTA); } Mode = DeviceStatus.DeviceMode.Complete; } this.Info = info; Console.WriteLine("Configuration stopped - " + label + "," + info); Log("" + DateTime.Now.ToString() + "," + Id + "," + label); Changed = true; }
void OnDeviceUpdate(OmDeviceEventArgs e) { OmDevice device = e.Device; /* * if (!devices.ContainsKey(e.Device.DeviceId)) * { * devices[e.Device.DeviceId] = new Device(e.Device); * } * Device device = devices[e.Device.DeviceId]; */ if (DeviceUpdate != null) { DeviceUpdate(this, new DeviceEventArgs(device, e)); } }
public bool CanConfigure(int minBattery) { if (Mode != DeviceStatus.DeviceMode.Charging) { return(false); } OmDevice omdev = GetDevice(); if (omdev == null) { return(false); } if (omdev.BatteryLevel < minBattery) { return(false); } return(true); }
public OmDevice GetDevice() { OmDevice omdev = Om.Instance.GetDevice(Id); return(omdev); }
public DeviceEventArgs(OmDevice device, OmDeviceEventArgs omEvent) { Device = device; OmEvent = omEvent; }