Esempio n. 1
0
        public AppAirQuality(int width, int height, MySqlDBConnection mySql)
        {
            tLabel   = "Temperatura";
            cLabel   = "CO₂";
            dLabel   = "Ponto de Orvalho";
            pLabel   = "PM2.5";
            humLabel = "Humidade";
            vLabel   = "VOCs";
            hLabel   = "Sensação Térmica";

            tUnit   = "°C";
            cUnit   = "ppm";
            dUnit   = "°C";
            pUnit   = "ug/m3";
            humUnit = "%";
            vUnit   = "";
            hUnit   = "°C";

            goodLabel     = "Bom";
            moderateLabel = "Moderado";
            badLabel      = "Mau";
            titleLabel    = "Monitorização da Qualidade do ar";

            big    = "Big";
            medium = "Medium";
            small  = "Small";

            se = new SendEmail();

            fontBrush = new SolidBrush(Color.FromArgb(8, 128, 186));
            sf        = new StringFormat();

            config = new Button();
            cf     = new Config();

            spaceInicialY    = 0.2F * height;
            spaceInicialY1   = 0.25F * height;
            spaceInicialX    = 0.05F * width;
            queueHeight      = 0.35F * height;
            firstQueueWidth  = 0.33F * width;
            secondQueueWidth = 0.25F * width;
            headerWidth      = width;
            legendHeight     = 0.10F * height;
            screenHeight     = height;
            screenWidth      = width;
            result           = Resolution(width, height);

            mySqlDB = mySql;

            //Last value
            aux = new SensorValue();
        }
Esempio n. 2
0
        public void ReceiveData(Object sender, Stack <SensorValue> allValues, MySqlDBConnection db)
        {
            Start : Thread.Sleep(5000); //the same on arduino program
            string[] separatingChars = { " " };
            sp = (SerialPort)sender;

            //send handshake code to visual studio
            if (firstInfo == false)
            {
                sp.Write(code);
                firstInfo = true;
            }

            //read serial data from arduino program
            s            = sp.ReadExisting();
            indata       = s.Split(separatingChars, StringSplitOptions.RemoveEmptyEntries);
            parsedValues = new int[size];

            //verify the length of the packet sent by arduino
            if (indata.Length != size)
            {
                Array.Clear(indata, 0, indata.Length);
                goto Start;
            }
            //parse from string[] to int[]
            for (int i = 0; i < indata.Length; i++)
            {
                int.TryParse(indata[i], out parsedValues[i]);
            }

            Array.Clear(indata, 0, indata.Length);

            sv.c        = parsedValues[0];
            sv.v        = parsedValues[1];
            sv.r        = Convert.ToSingle(parsedValues[2]) / 100;
            sv.temp     = Convert.ToSingle(parsedValues[3]) / 100;
            sv.pm       = parsedValues[4];
            sv.h        = Convert.ToSingle(parsedValues[5]) / 100;
            sv.d        = fToCelsius(Convert.ToSingle(parsedValues[6]) / 100);
            sv.dateTime = DateTime.Now;

            Array.Clear(parsedValues, 0, parsedValues.Length);
            allValues.Push(sv); //save last read data on sensorvalues stack
            sv = new SensorValue();

            Console.WriteLine("\n Sensor Values: ");
            Console.Write(allValues.Peek().ToString()); //print last read data
            Console.WriteLine();
        }