public override void Init(params string[] Param) { MainWindow = GlideLoader.LoadWindow(Resources.GetString(Resources.StringResources.MyRoomForm)); ArrayList control = new ArrayList(); GT.Picture pic = null; var imgTemp = (GHI.Glide.UI.Image)MainWindow.GetChildByName("imgTemp"); pic = new GT.Picture(Resources.GetBytes(Resources.BinaryResources.temperature), GT.Picture.PictureEncoding.JPEG); imgTemp.Bitmap = pic.MakeBitmap(); control.Add(imgTemp); var imgLight = (GHI.Glide.UI.Image)MainWindow.GetChildByName("imgLight"); pic = new GT.Picture(Resources.GetBytes(Resources.BinaryResources.light), GT.Picture.PictureEncoding.JPEG); imgLight.Bitmap = pic.MakeBitmap(); control.Add(imgLight); var imgHumid = (GHI.Glide.UI.Image)MainWindow.GetChildByName("imgHumid"); pic = new GT.Picture(Resources.GetBytes(Resources.BinaryResources.humidity), GT.Picture.PictureEncoding.JPEG); imgHumid.Bitmap = pic.MakeBitmap(); control.Add(imgHumid); GT.Timer timer = new GT.Timer(2000); var Btn = (GHI.Glide.UI.Button)MainWindow.GetChildByName("btnBack"); control.Add(Btn); Btn.PressEvent += (sender) => { timer.Stop(); CallFormRequestEvent(ScreenTypes.MainMenu); }; txtTemp = (GHI.Glide.UI.TextBlock)MainWindow.GetChildByName("txtTemp"); txtHumid = (GHI.Glide.UI.TextBlock)MainWindow.GetChildByName("txtHumid"); txtLight = (GHI.Glide.UI.TextBlock)MainWindow.GetChildByName("txtLight"); Glide.MainWindow = MainWindow; timer.Tick += (a) => { var measure = tempHumidSI70.TakeMeasurement(); txtTemp.Text = Toolbox.NETMF.Tools.Round((float)measure.Temperature, 2);// + "C"; txtHumid.Text = Toolbox.NETMF.Tools.Round((float)measure.RelativeHumidity);// + "%"; txtLight.Text = Toolbox.NETMF.Tools.Round((float)lightSense.GetIlluminance());// + "Lux"; //MainWindow.Graphics.DrawRectangle(txtTemp.Rect, MainWindow.BackColor, 255); //MainWindow.Graphics.DrawRectangle(txtHumid.Rect, MainWindow.BackColor, 255); //MainWindow.Graphics.DrawRectangle(txtLight.Rect, MainWindow.BackColor, 255); txtTemp.Invalidate(); txtHumid.Invalidate(); txtLight.Invalidate(); MainWindow.Invalidate(); }; timer.Start(); //MainWindow.Invalidate(); }
// This method is run when the mainboard is powered up or reset. void ProgramStarted() { //setup wifi wifiRS21.DebugPrintEnabled = true; NetworkChange.NetworkAvailabilityChanged += NetworkChange_NetworkAvailabilityChanged; // setup events NetworkChange.NetworkAddressChanged += NetworkChange_NetworkAddressChanged; wifiRS21.NetworkDown += new GT.Modules.Module.NetworkModule.NetworkEventHandler(wifi_NetworkDown); wifiRS21.NetworkUp += new GT.Modules.Module.NetworkModule.NetworkEventHandler(wifi_NetworkUp); // use the router's DHCP server to set my network info if (!wifiRS21.NetworkInterface.Opened) wifiRS21.NetworkInterface.Open(); if (!wifiRS21.NetworkInterface.IsDhcpEnabled) { wifiRS21.UseDHCP(); wifiRS21.NetworkInterface.EnableDhcp(); wifiRS21.NetworkInterface.EnableDynamicDns(); } // look for avaiable networks var scanResults = wifiRS21.NetworkInterface.Scan(); // go through each network and print out settings in the debug window foreach (GHI.Networking.WiFiRS9110.NetworkParameters result in scanResults) { Debug.Print("****" + result.Ssid + "****"); Debug.Print("ChannelNumber = " + result.Channel); Debug.Print("networkType = " + result.NetworkType); Debug.Print("PhysicalAddress = " + GetMACAddress(result.PhysicalAddress)); Debug.Print("RSSI = " + result.Rssi); Debug.Print("SecMode = " + result.SecurityMode); } // locate a specific network GHI.Networking.WiFiRS9110.NetworkParameters[] info = wifiRS21.NetworkInterface.Scan(SSID); if (info != null) { wifiRS21.NetworkInterface.Join(info[0].Ssid, KeyWifi); wifiRS21.UseThisNetworkInterface(); bool res = wifiRS21.IsNetworkConnected; Debug.Print("Network joined"); Debug.Print("active:" + wifiRS21.NetworkInterface.ActiveNetwork.Ssid); } Debug.Print("Program Started"); Mobil = new MobilRemote(); GT.Timer timer = new GT.Timer(100); timer.Tick += (x) => { if (isNavigating) return; isNavigating = true; ledStrip.TurnAllLedsOff(); switch (Mobil.Arah) { case MobilRemote.ArahJalan.Maju: motorDriverL298.SetSpeed(MotorDriverL298.Motor.Motor1, 1); motorDriverL298.SetSpeed(MotorDriverL298.Motor.Motor2, 1); ledStrip.TurnAllLedsOn(); break; case MobilRemote.ArahJalan.Mundur: motorDriverL298.SetSpeed(MotorDriverL298.Motor.Motor1, -0.7); motorDriverL298.SetSpeed(MotorDriverL298.Motor.Motor2, -0.7); ledStrip.TurnLedOn(2); ledStrip.TurnLedOn(3); ledStrip.TurnLedOn(4); break; case MobilRemote.ArahJalan.Kiri: motorDriverL298.SetSpeed(MotorDriverL298.Motor.Motor1, -0.7); motorDriverL298.SetSpeed(MotorDriverL298.Motor.Motor2, 0.7); ledStrip.TurnLedOn(0); ledStrip.TurnLedOn(1); break; case MobilRemote.ArahJalan.Kanan: motorDriverL298.SetSpeed(MotorDriverL298.Motor.Motor1, 0.7); motorDriverL298.SetSpeed(MotorDriverL298.Motor.Motor2, -0.7); ledStrip.TurnLedOn(5); ledStrip.TurnLedOn(6); break; case MobilRemote.ArahJalan.Stop: motorDriverL298.SetSpeed(MotorDriverL298.Motor.Motor1, 0); motorDriverL298.SetSpeed(MotorDriverL298.Motor.Motor2, 0); break; } isNavigating = false; }; timer.Start(); while (!wifiRS21.IsNetworkConnected || wifiRS21.NetworkInterface.IPAddress=="0.0.0.0") { Thread.Sleep(100); } client = new MqttClient(MQTT_BROKER_ADDRESS); string clientId = Guid.NewGuid().ToString(); client.Connect(clientId); SubscribeMessage(); }