protected void GetAtoGroupData() { if (atoGroupName.IsNotEmpty()) { if (AutoTopOff.GetAtoGroupEnable(atoGroupName)) { atoStateTextBox.text = string.Format("{0} : {1}", AutoTopOff.GetAtoGroupState(atoGroupName), AutoTopOff.GetAtoGroupAtoTime(atoGroupName).SecondsToString()); if (Alarm.CheckAlarming(AutoTopOff.GetAtoGroupFailAlarmIndex(atoGroupName)) || AutoTopOff.GetAtoGroupState(atoGroupName) == AutoTopOffState.Cooldown) { atoClearFailBtn.Visible = true; atoClearFailBtn.Show(); } else { atoClearFailBtn.Visible = false; } } else { atoStateTextBox.text = "ATO Disabled"; atoClearFailBtn.Visible = false; } } else { atoStateTextBox.text = "ATO Disabled"; atoClearFailBtn.Visible = false; } atoStateTextBox.QueueDraw(); }
protected override bool OnSave(object sender) { var atoSettings = new AutoTopOffGroupSettings(); atoSettings.name = (string)settings["Name"].setting; if (atoSettings.name == "Enter name") { MessageBox.Show("Invalid ATO name"); return(false); } atoSettings.enable = (int)settings["Enable"].setting == 0; atoSettings.waterLevelGroupName = (string)settings["Water Group"].setting; if (atoSettings.waterLevelGroupName.IsEmpty()) { MessageBox.Show("Please select a Water Level Group"); return(false); } atoSettings.requestBitName = (string)settings["Request Bit Name"].setting; if (atoSettings.requestBitName == "Enter name") { MessageBox.Show("Invalid request bit name"); return(false); } atoSettings.useAnalogSensors = (int)settings["Use Analog"].setting == 0; atoSettings.analogOnSetpoint = Convert.ToSingle(settings["Analog On"].setting); atoSettings.analogOffSetpoint = Convert.ToSingle(settings["Analog Off"].setting); if (atoSettings.analogOnSetpoint > atoSettings.analogOffSetpoint) { MessageBox.Show("Analog On Setpoint can not be higher than the analog off setpoint"); return(false); } atoSettings.useFloatSwitches = (int)settings["Use Float Switch"].setting == 0; atoSettings.maximumRuntime = (uint)ParseTime((string)settings["Max Runtime"].setting); atoSettings.minimumCooldown = (uint)ParseTime((string)settings["Cooldown"].setting); AutoTopOff.UpdateAtoGroup(groupName, atoSettings); groupName = atoSettings.name; return(true); }
protected void OnAtoSettingsButtonReleaseEvent(object sender, ButtonReleaseEventArgs args) { var parent = Toplevel as Window; var s = new AtoSettings(AutoTopOff.GetAutoTopOffGroupSettings(atoGroupName), parent); s.Run(); var newAtoGroupName = s.groupName; var outcome = s.outcome; if ((outcome == TouchSettingsOutcome.Modified) && (newAtoGroupName != groupName)) { var index = atoGroupCombo.comboList.IndexOf(groupName); atoGroupCombo.comboList[index] = newAtoGroupName; atoGroupName = newAtoGroupName; } else if (outcome == TouchSettingsOutcome.Added) { atoGroupCombo.comboList.Insert(atoGroupCombo.comboList.Count - 1, newAtoGroupName); atoGroupCombo.activeText = newAtoGroupName; atoGroupName = newAtoGroupName; } else if (outcome == TouchSettingsOutcome.Deleted) { atoGroupCombo.comboList.Remove(atoGroupName); atoGroupName = AutoTopOff.firstAtoGroup; if (atoGroupName.IsNotEmpty()) { atoGroupCombo.activeText = atoGroupName; } else { atoGroupCombo.activeIndex = -1; } } atoGroupCombo.QueueDraw(); GetAtoGroupData(); }
public static void Main(string[] args) { var aquaPicEnvironment = string.Empty; var aquaPicSettings = string.Empty; // Call the Gtk library hack because Windows sucks at everything if (Utils.ExecutingOperatingSystem == Platform.Windows) { CheckWindowsGtk(); //Get the AquaPic directory environment aquaPicEnvironment = Environment.GetEnvironmentVariable("AquaPic"); if (aquaPicEnvironment.IsEmpty()) { var path = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location); path = Path.Combine(path, "AquaPicEnvironment.txt"); if (File.Exists(path)) { var lines = File.ReadAllLines(path); aquaPicEnvironment = lines[0]; } } if (aquaPicEnvironment.IsNotEmpty()) { var path = aquaPicEnvironment; if (!Directory.Exists(path)) { Console.WriteLine("Path to AquaPic directory environment is incorrect"); Console.WriteLine("Incorrect path was {0}", path); aquaPicEnvironment = string.Empty; } } if (aquaPicEnvironment.IsEmpty()) { Console.WriteLine("Please edit the AquaPicEnvironment.txt file to point to the path of the AquaPicRuntime directory."); Console.WriteLine("For example if the AquaPicRuntime directory is located at /home/user/AquaPicRuntimeProject/,"); Console.WriteLine("then add \"/home/user/AquaPicRuntimeProject/\" to the first line of the file."); return; } } else { aquaPicEnvironment = Environment.GetEnvironmentVariable("HOME"); aquaPicEnvironment = Path.Combine(aquaPicEnvironment, ".config"); aquaPicEnvironment = Path.Combine(aquaPicEnvironment, "AquaPic"); if (!Directory.Exists(aquaPicEnvironment)) { Directory.CreateDirectory(aquaPicEnvironment); Directory.CreateDirectory(Path.Combine(aquaPicEnvironment, "DataLogging")); Directory.CreateDirectory(Path.Combine(aquaPicEnvironment, "Logs")); Directory.CreateDirectory(Path.Combine(aquaPicEnvironment, "TestProcedures")); } } if (args.Length > 0) { Console.WriteLine("Arguments {0}", args[0]); if (args[0].Contains("-empty")) { aquaPicSettings = Path.Combine(aquaPicEnvironment, "Settings.Empty"); } else if (args[0].Contains("-full")) { aquaPicSettings = Path.Combine(aquaPicEnvironment, "Settings.Full"); } else { aquaPicSettings = Path.Combine(aquaPicEnvironment, "Settings"); } } else { aquaPicSettings = Path.Combine(aquaPicEnvironment, "Settings"); } if (!Directory.Exists(aquaPicSettings)) { Directory.CreateDirectory(aquaPicSettings); } //Setup Utils.AquaPicEnvironment = aquaPicEnvironment; Utils.AquaPicSettings = aquaPicSettings; Application.Init(); Logger.Add("Executing operating system is {0}", Utils.GetDescription(Utils.ExecutingOperatingSystem)); #if DEBUG try { #endif Driver.AddFromJson(); Sensors.AddSensors(); Devices.AddDevices(); Temperature.Init(); WaterLevel.Init(); AutoTopOff.Init(); #if DEBUG } catch (Exception ex) { Logger.AddError(ex.ToString()); return; } #endif #if DEBUG Driver.AnalogInput.SetChannelMode("Right Overflow, Temperature Probe", Mode.Manual); Driver.AnalogInput.SetChannelValue("Right Overflow, Temperature Probe", 2796.5); Driver.AnalogInput.SetChannelMode("Left Overflow, Temperature Probe", Mode.Manual); Driver.AnalogInput.SetChannelValue("Left Overflow, Temperature Probe", 2796.5); Driver.AnalogInput.SetChannelMode("Sump, Temperature Probe", Mode.Manual); Driver.AnalogInput.SetChannelValue("Sump, Temperature Probe", 2796.5); Driver.AnalogInput.SetChannelMode("Salt Mixing, Temperature Probe", Mode.Manual); Driver.AnalogInput.SetChannelValue("Salt Mixing, Temperature Probe", 2796.5); Driver.AnalogInput.SetChannelMode("Return Chamber, Water Level Sensor", Mode.Manual); Driver.AnalogInput.SetChannelValue("Return Chamber, Water Level Sensor", 1803); Driver.AnalogInput.SetChannelMode("ATO Reservoir, Water Level Sensor", Mode.Manual); Driver.AnalogInput.SetChannelValue("ATO Reservoir, Water Level Sensor", 3878); Driver.AnalogInput.SetChannelMode("Salt Reservoir, Water Level Sensor", Mode.Manual); Driver.AnalogInput.SetChannelValue("Salt Reservoir, Water Level Sensor", 2048); Driver.DigitalInput.SetChannelMode("Sump High, Float Switch", Mode.Manual); Driver.DigitalInput.SetChannelValue("Sump High, Float Switch", true); Driver.DigitalInput.SetChannelMode("Sump Low, Float Switch", Mode.Manual); Driver.DigitalInput.SetChannelValue("Sump Low, Float Switch", true); Driver.DigitalInput.SetChannelMode("Sump ATO, Float Switch", Mode.Manual); Driver.PhOrp.SetChannelMode("Sump, pH Probe", Mode.Manual); Driver.PhOrp.SetChannelValue("Sump, pH Probe", 2282); #endif // Run the control var win = AquaPicGui.CreateInstance(); win.Show(); Application.Run(); // Cleanup if (AquaPicBus.isOpen) { AquaPicBus.Close(); } #if DELETE_DATA_FILES // For some reason this doesn't like to be in the destroyed event var groups = Temperature.GetAllTemperatureGroupNames(); foreach (var group in groups) { var dataLogger = (DataLoggerIoImplementation)Temperature.GetTemperatureGroupDataLogger(group); if (dataLogger != null) { dataLogger.DeleteAllLogFiles(); } } groups = WaterLevel.GetAllWaterLevelGroupNames(); foreach (var group in groups) { var dataLogger = (DataLoggerIoImplementation)WaterLevel.GetWaterLevelGroupDataLogger(group); if (dataLogger != null) { dataLogger.DeleteAllLogFiles(); } } var phProbes = Sensors.PhProbes.GetAllGadgetNames(); foreach (var probe in phProbes) { var dataLogger = (DataLoggerIoImplementation)Sensors.PhProbes.GetPhProbeDataLogger(probe); if (dataLogger != null) { dataLogger.DeleteAllLogFiles(); } } #endif }
public WaterLevelWindow(params object[] options) { sceneTitle = "Water Level"; ExposeEvent += OnExpose; /******************************************************************************************************/ /* Water Level Groups */ /******************************************************************************************************/ groupName = WaterLevel.firstWaterLevelGroup; if (options.Length >= 3) { var requestedGroup = options[2] as string; if (requestedGroup != null) { if (WaterLevel.WaterLevelGroupNameExists(requestedGroup)) { groupName = requestedGroup; } } } var label = new TouchLabel(); label.text = "Groups"; label.WidthRequest = 118; label.textColor = "seca"; label.textSize = 12; label.textAlignment = TouchAlignment.Left; Put(label, 37, 80); label.Show(); label = new TouchLabel(); label.WidthRequest = 329; label.text = "Level"; label.textColor = "grey3"; label.textAlignment = TouchAlignment.Center; Put(label, 60, 155); label.Show(); levelLabel = new TouchLabel(); levelLabel.WidthRequest = 329; levelLabel.textSize = 20; levelLabel.textAlignment = TouchAlignment.Center; levelLabel.textRender.unitOfMeasurement = UnitsOfMeasurement.Inches; Put(levelLabel, 60, 120); levelLabel.Show(); var globalSettingsBtn = new TouchButton(); globalSettingsBtn.text = "\u2699"; globalSettingsBtn.SetSizeRequest(30, 30); globalSettingsBtn.buttonColor = "pri"; globalSettingsBtn.ButtonReleaseEvent += OnGroupSettingsButtonReleaseEvent; Put(globalSettingsBtn, 358, 77); globalSettingsBtn.Show(); /******************************************************************************************************/ /* ATO Groups */ /******************************************************************************************************/ atoGroupName = AutoTopOff.firstAtoGroup; label = new TouchLabel(); label.text = "ATO"; label.textColor = "seca"; label.textSize = 12; Put(label, 37, 280); label.Show(); atoStateTextBox = new TouchLabel(); atoStateTextBox.WidthRequest = 329; atoStateTextBox.textSize = 20; atoStateTextBox.textAlignment = TouchAlignment.Center; Put(atoStateTextBox, 60, 320); atoStateTextBox.Show(); var atoSettingsBtn = new TouchButton(); atoSettingsBtn.text = "\u2699"; atoSettingsBtn.SetSizeRequest(30, 30); atoSettingsBtn.buttonColor = "pri"; atoSettingsBtn.ButtonReleaseEvent += OnAtoSettingsButtonReleaseEvent; Put(atoSettingsBtn, 358, 277); atoSettingsBtn.Show(); atoClearFailBtn = new TouchButton(); atoClearFailBtn.SetSizeRequest(100, 60); atoClearFailBtn.text = "Reset ATO"; atoClearFailBtn.buttonColor = "compl"; atoClearFailBtn.ButtonReleaseEvent += (o, args) => { if (atoGroupName.IsNotEmpty()) { if (AutoTopOff.GetAtoGroupState(atoGroupName) == AutoTopOffState.Cooldown) { AutoTopOff.ResetCooldownTime(atoGroupName); } else { if (!AutoTopOff.ClearAtoAlarm(atoGroupName)) { MessageBox.Show("Please acknowledge alarms first"); } } } }; Put(atoClearFailBtn, 70, 405); /**************************************************************************************************************/ /* Analog water sensor */ /**************************************************************************************************************/ analogSensorWidget = new WaterLevelSensorWidget(); Put(analogSensorWidget, 415, 77); analogSensorWidget.Show(); analogSensorWidget.sensorCombo.comboList.Clear(); if (groupName.IsNotEmpty()) { var groupsWaterLevelSensors = WaterLevel.GetAllWaterLevelSensorsForWaterLevelGroup(groupName); analogSensorWidget.sensorCombo.comboList.AddRange(groupsWaterLevelSensors); if (groupsWaterLevelSensors.Length > 0) { analogSensorWidget.sensorName = groupsWaterLevelSensors[0]; } else { analogSensorWidget.sensorName = string.Empty; } } analogSensorWidget.sensorCombo.comboList.Add("New level sensor..."); analogSensorWidget.sensorCombo.activeIndex = 0; analogSensorWidget.sensorCombo.QueueDraw(); /**************************************************************************************************************/ /* Float Switches */ /**************************************************************************************************************/ label = new TouchLabel(); label.text = "Probes"; label.textColor = "seca"; label.textSize = 12; Put(label, 415, 280); label.Show(); switchStateLabel = new TouchLabel(); switchStateLabel.text = "Current Switch State"; switchStateLabel.textAlignment = TouchAlignment.Center; switchStateLabel.textColor = "grey3"; switchStateLabel.WidthRequest = 370; Put(switchStateLabel, 415, 355); switchStateTextBox = new TouchLabel(); switchStateTextBox.WidthRequest = 370; switchStateTextBox.textSize = 20; switchStateTextBox.textAlignment = TouchAlignment.Center; Put(switchStateTextBox, 415, 320); switchStateTextBox.Show(); //Type switchTypeLabel = new TouchLabel(); switchTypeLabel.WidthRequest = 370; switchTypeLabel.textAlignment = TouchAlignment.Center; switchTypeLabel.textColor = "grey3"; Put(switchTypeLabel, 415, 370); switchTypeLabel.Show(); var switchSetupBtn = new TouchButton(); switchSetupBtn.text = "\u2699"; switchSetupBtn.SetSizeRequest(30, 30); switchSetupBtn.buttonColor = "pri"; switchSetupBtn.ButtonReleaseEvent += OnFloatSwitchSettingsButtonReleaseEvent; Put(switchSetupBtn, 755, 277); switchSetupBtn.Show(); groupCombo = new TouchComboBox(WaterLevel.GetAllWaterLevelGroupNames()); if (groupName.IsNotEmpty()) { groupCombo.activeText = groupName; } else { groupCombo.activeIndex = 0; } groupCombo.WidthRequest = 200; groupCombo.comboList.Add("New group..."); groupCombo.ComboChangedEvent += OnGroupComboChanged; Put(groupCombo, 153, 77); groupCombo.Show(); atoGroupCombo = new TouchComboBox(AutoTopOff.GetAllAtoGroupNames()); if (atoGroupName.IsNotEmpty()) { atoGroupCombo.activeText = atoGroupName; } else { atoGroupCombo.activeIndex = 0; } atoGroupCombo.WidthRequest = 200; atoGroupCombo.comboList.Add("New ATO..."); atoGroupCombo.ComboChangedEvent += OnAtoGroupComboChanged; Put(atoGroupCombo, 153, 277); atoGroupCombo.Show(); switchCombo = new TouchComboBox(); switchCombo.WidthRequest = 200; if (groupName.IsNotEmpty()) { var groupsFloatSwitches = WaterLevel.GetAllFloatSwitchesForWaterLevelGroup(groupName); switchCombo.comboList.AddRange(groupsFloatSwitches); if (groupsFloatSwitches.Length > 0) { switchName = groupsFloatSwitches[0]; } else { switchName = string.Empty; } } switchCombo.comboList.Add("New switch..."); switchCombo.activeIndex = 0; switchCombo.ComboChangedEvent += OnSwitchComboChanged; Put(switchCombo, 550, 277); switchCombo.Show(); GetGroupData(); GetAtoGroupData(); analogSensorWidget.GetSensorData(); GetSwitchData(); Show(); }
public AtoSettings(AutoTopOffGroupSettings settings, Window parent) : base(settings.name + " Auto Top Off", settings.name.IsNotEmpty(), parent) { groupName = settings.name; var t = new SettingsTextBox("Name"); t.textBox.text = groupName.IsNotEmpty() ? groupName : "Enter name"; t.textBox.TextChangedEvent += (sender, args) => { if (args.text.IsEmpty()) { args.keepText = false; } else if (!AutoTopOff.AtoGroupNameOk(args.text)) { MessageBox.Show("ATO group name already exists"); args.keepText = false; } }; AddSetting(t); var s = new SettingsSelectorSwitch("Enable"); if (groupName.IsNotEmpty()) { s.selectorSwitch.currentSelected = settings.enable ? 0 : 1; } AddSetting(s); var c = new SettingsComboBox("Water Group"); c.combo.nonActiveMessage = "Select Water Level Group"; var availableGroups = WaterLevel.GetAllWaterLevelGroupNames(); c.combo.comboList.AddRange(availableGroups); if (groupName.IsNotEmpty()) { var index = Array.IndexOf(availableGroups, settings.waterLevelGroupName); c.combo.activeIndex = index; } AddSetting(c); t = new SettingsTextBox("Request Bit Name"); t.textBox.text = groupName.IsNotEmpty() ? settings.requestBitName : "Enter name"; t.textBox.TextChangedEvent += (sender, args) => { if (args.text.IsEmpty()) { args.keepText = false; } }; AddSetting(t); s = new SettingsSelectorSwitch("Use Analog"); if (groupName.IsNotEmpty()) { s.selectorSwitch.currentSelected = settings.useAnalogSensors ? 0 : 1; } AddSetting(s); t = new SettingsTextBox("Analog Off"); t.textBox.text = groupName.IsNotEmpty() ? settings.analogOffSetpoint.ToString() : "0"; t.textBox.TextChangedEvent += (sender, args) => { try { float offStpnt = Convert.ToSingle(args.text); if (offStpnt < 0f) { MessageBox.Show("Analog on setpoint can't be negative"); args.keepText = false; return; } } catch { MessageBox.Show("Improper analog off setpoint format"); args.keepText = false; } }; AddSetting(t); t = new SettingsTextBox("Analog On"); t.textBox.text = groupName.IsNotEmpty() ? settings.analogOnSetpoint.ToString() : "0"; t.textBox.TextChangedEvent += (sender, args) => { try { float onStpnt = Convert.ToSingle(args.text); if (onStpnt < 0f) { MessageBox.Show("Analog on setpoint can't be negative"); args.keepText = false; return; } } catch { MessageBox.Show("Improper analog on setpoint format"); args.keepText = false; } }; AddSetting(t); s = new SettingsSelectorSwitch("Use Float Switch"); if (groupName.IsNotEmpty()) { s.selectorSwitch.currentSelected = settings.useFloatSwitches ? 0 : 1; } AddSetting(s); t = new SettingsTextBox("Max Runtime"); t.textBox.text = groupName.IsNotEmpty() ? string.Format("{0} mins", settings.maximumRuntime) : "1 min"; t.textBox.TextChangedEvent += (sender, args) => { if (args.text.IsEmpty()) { args.keepText = false; } var time = ParseTime(args.text); if (time >= 0) { args.text = string.Format("{0} mins", time); } else { MessageBox.Show("Improper format"); args.keepText = false; } }; AddSetting(t); t = new SettingsTextBox("Cooldown"); t.textBox.text = groupName.IsNotEmpty() ? string.Format("{0} mins", settings.minimumCooldown) : "10 min"; t.textBox.TextChangedEvent += (sender, args) => { if (args.text.IsEmpty()) { args.keepText = false; } var time = ParseTime(args.text); if (time >= 0) { args.text = string.Format("{0} mins", time); } else { MessageBox.Show("Improper format"); args.keepText = false; } }; AddSetting(t); DrawSettings(); }
protected override bool OnDelete(object sender) { AutoTopOff.RemoveAtoGroup(groupName); return(true); }