I’m getting started with my first projects here with the .NET MF and I have a FEZ Spider with a Temperature Humidity module from Seeed that I’m trying to use.
My code is really simple, below is my Program.cs for some clarity. I have a very simple setup, a single “image” that is being displayed to a WPF window. Once clicked I call “RequestMeasurement” on the TemperatureHumidity Module. I have a handler added to then update the UI. Debugging I can see that it does actually get called but the line to update the text content isn’t being fired off.
With WinForms I’d think of this as a threading issue, but I don’t see any way to actually see/fix it.
private Image imgButton1;
private Image imbButton2;
private Text txtFeedback;
// This method is run when the mainboard is powered up or reset.
void ProgramStarted()
{
temperatureHumidity.MeasurementComplete += new TemperatureHumidity.MeasurementCompleteEventHandler(tempUpdated);
SetupUI();
// Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.
Debug.Print("Program Started");
}
void tempUpdated(TemperatureHumidity sender, double temperature, double relativeHumidity)
{
//Update label
txtFeedback.TextContent = string.Concat("Temp: ", temperature.ToString("0.0"), " Humidity: ", relativeHumidity.ToString("0.0"));
}
public void SetupUI()
{
var window = display.WPFWindow;
var canvas = new Canvas();
window.Child = canvas;
//Add the first button
var imgButton1 = new Image(Resources.GetBitmap(Resources.BitmapResources.Button1));
imgButton1.TouchDown += new Microsoft.SPOT.Input.TouchEventHandler(Button1_Pressed);
canvas.Children.Add(imgButton1);
PositionElemen(imgButton1, 10, 5);
//Add the textbox
txtFeedback = new Text(Resources.GetFont(Resources.FontResources.NinaB), string.Empty);
canvas.Children.Add(txtFeedback);
PositionElemen(txtFeedback, 20, 200);
}
private void PositionElemen(UIElement element, int x, int y)
{
Canvas.SetTop(element, y);
Canvas.SetLeft(element, x);
}
void Button1_Pressed(object sender, Microsoft.SPOT.Input.TouchEventArgs e)
{
temperatureHumidity.RequestMeasurement();
}