/*On timer tick event, read the message from the serial port. If it is a float, update the temperature label. Otherwise, * update the garbage label and panel with appropriate text and color depicting the garbage status based on the text from the serial port*/ private void timerUpdate_Tick(object sender, EventArgs e) { if (TempAndLightPort.BytesToRead > 0) { string message = TempAndLightPort.ReadLine(); message = message.Trim(); float RealTemp; if (float.TryParse(message, out RealTemp))//see if message is float (only temperature can be converted to int) { lblTemperature.Text = "Temperature: " + RealTemp + " °C"; } switch (message) //filter message for strings { case "LIGHT_DETECTED": { pnlGarbage.BackColor = Color.PaleGreen; lblGarbage.Text = "Garbage has been set out!"; } break; case "NO_LIGHT_DETECTED": { pnlGarbage.BackColor = Color.Yellow; lblGarbage.Text = "Garbage is not set out yet."; } break; } } }
/**/ private void PlBorder_MouseDown(object sender, MouseEventArgs e) { ReleaseCapture(); //controls mouse pressed SendMessage(Handle, 0x112, 0xf012, 0); } /*method makes sure to close the port if it is open when exiting the program*/ private void HMU_Mainform_FormClosing(object sender, FormClosingEventArgs e) { if (TempAndLightPort.IsOpen) { TempAndLightPort.Close(); } }