public static bool OnAddressSetEvent(string text, ref string card, GenericBase cardDriver)
        {
            var keepText = false;

            if (text.IsNotEmpty())
            {
                try {
                    int address;
                    if ((text.StartsWith("x", StringComparison.InvariantCultureIgnoreCase)) ||
                        (text.StartsWith("0x", StringComparison.InvariantCultureIgnoreCase)))
                    {
                        var parseString = text.Substring(text.IndexOf("x", StringComparison.InvariantCultureIgnoreCase) + 1);
                        address = int.Parse(parseString, NumberStyles.HexNumber);
                    }
                    else
                    {
                        address = Convert.ToInt32(text);
                    }

                    if (!AquaPicBus.SlaveAddressOk(address))
                    {
                        MessageBox.Show("Address already exists");
                    }
                    else
                    {
                        var ja = SettingsHelper.OpenSettingsFile("hardware") as JArray;

                        card = string.Format(
                            "{0}{1}",
                            cardDriver.GetCardAcyronym(),
                            cardDriver.GetLowestCardNameIndex());

                        cardDriver.AddCard(card, address);

                        var type = cardDriver.GetCardType().ToString();
                        type = Char.ToLower(type[0]) + type.Substring(1);
                        var jo = new JObject {
                            new JProperty("type", type),
                            new JProperty("address", string.Format("0x{0:X}", address)),
                            new JProperty("name", card),
                            new JProperty("options", string.Empty)
                        };
                        ja.Add(jo);
                        SettingsHelper.WriteSettingsFile("hardware", ja);
                        keepText = true;
                    }
                } catch (Exception ex) {
                    MessageBox.Show("Improper address");
                    Console.WriteLine(ex);
                }
            }

            return(keepText);
        }
Example #2
0
        protected void OnOpenButtonRelease(object sender, ButtonReleaseEventArgs args)
        {
            var b = sender as TouchButton;

            if (b != null)
            {
                if (c.activeIndex != -1)
                {
                    AquaPicBus.Open(c.activeText);
                    if (AquaPicBus.isOpen)
                    {
                        b.buttonColor         = "grey3";
                        b.ButtonReleaseEvent -= OnOpenButtonRelease;
                        b.QueueDraw();
                    }
                }
                else
                {
                    MessageBox.Show("No communication port selected");
                }
            }
        }
Example #3
0
        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
        }