private static void DisplayError(string message) { Debug.Print(message); while (true) { Mainboard.SetDebugLED(true); Thread.Sleep(200); Mainboard.SetDebugLED(false); Thread.Sleep(200); } }
void timer_Tick(GT.Timer timer) { var isButtonPressed = _digitalInput.Read(); Mainboard.SetDebugLED(isButtonPressed); _digitalOutput.Write(isButtonPressed); _digitalOutput2.Write(_analogValue); Debug.Print("signal measured: " + _digitalInput2.Read().ToString()); _analogValue = !_analogValue; }
/* * UNLOCK DOOR * Called by either PinFound or TagFound to unlock the door. */ private void UnlockDoor() { // Authorize access authorizedAccess = true; unlockTimerRunning = true; unlockedTimer.Restart(); // Blink LED Mainboard.SetDebugLED(true); System.Threading.Thread.Sleep(200); Mainboard.SetDebugLED(false); }
// -------------------------------- Sensori -------------------------------- // private void InitSensors() { Mainboard.SetDebugLED(true); Gadgeteer.Socket socket = Gadgeteer.Socket.GetSocket(8, true, null, null); buzzer = new PWM(Cpu.PWMChannel.PWM_4, 1000, 0.5, false); buzzer.Stop(); orizzontal_mov = extender.CreatePwmOutput(Gadgeteer.Socket.Pin.Seven); vertical_mov = extender.CreatePwmOutput(Gadgeteer.Socket.Pin.Nine); current_orizzontal_pos = 0.075; current_vertical_pos = 0.075; orizzontal_mov.Set(50, current_orizzontal_pos); Thread.Sleep(2000); vertical_mov.Set(50, current_vertical_pos); }
// This method is run when the mainboard is powered up or reset. void ProgramStarted() { Debug.Print("Blink green LED"); ledStrip.TurnLedOn(2); ledStrip.TurnLedOn(5); while (true) { Mainboard.SetDebugLED(true); Thread.Sleep(1000); // leave it on for 1 second Mainboard.SetDebugLED(false); Thread.Sleep(500); // turn it of for 500 milliseconds } Debug.Print("Program finished"); }
//lora data received void _loraSerial_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e) { _dataInLora = _loraSerial.Deserialize(); for (int index = 0; index < _dataInLora.Length; index++) { rx = _dataInLora[index]; //if error if (_dataInLora[index].Length > 7) { if (rx.Substring(0, 9) == "radio_err") { Debug.Print("!!!!!!!!!!!!! Radio Error !!!!!!!!!!!!!!"); PrintToLCD("Radio Error"); _restPort.Write(false); Thread.Sleep(1000); _restPort.Write(true); Thread.Sleep(1000); _loraSerial.WriteLine("mac pause"); Thread.Sleep(1000); _loraSerial.WriteLine("radio rx 0"); return; } //if receive data if (rx.Substring(0, 8) == "radio_rx") { string hex = _dataInLora[index].Substring(10); Mainboard.SetDebugLED(true); Thread.Sleep(500); Mainboard.SetDebugLED(false); Debug.Print(hex); Debug.Print(Unpack(hex)); //update display PrintToLCD(Unpack(hex)); Thread.Sleep(100); // set module to RX _loraSerial.WriteLine("radio rx 0"); } } } }
private void _timer_Tick(GT.Timer timer) { Mainboard.SetDebugLED(true); var measurement = tempHumidSI70.TakeMeasurement(); var volts = lightSense.ReadVoltage(); // Display data and time in debug console Debug.Print(DateTime.Now.ToString()); Debug.Print("Temperature = " + measurement.TemperatureFahrenheit); Debug.Print("Humidity = " + measurement.RelativeHumidity); Debug.Print("Light = " + volts); // send to Event Hub SendAMQPMessage(FormatMessage("Temperature", "F", measurement.TemperatureFahrenheit)); SendAMQPMessage(FormatMessage("Humidity", "%", measurement.RelativeHumidity)); SendAMQPMessage(FormatMessage("Light", "v", volts)); Mainboard.SetDebugLED(false); }
void timer_Tick(GT.Timer timer) { status = !status; Mainboard.SetDebugLED(status); }
void ProgramStarted() { if (sdCard.IsCardMounted) { rootDirectory = sdCard.StorageDevice.RootDirectory; } else { Mainboard.SetDebugLED(true); } Byte[] buffer = new Byte[10]; TimeService.SystemTimeChanged += TimeService_SystemTimeChanged; TimeService.TimeSyncFailed += TimeService_TimeSyncFailed; ethernetJ11D.NetworkDown += ethernetJ11D_NetworkDown; ethernetJ11D.NetworkUp += ethernetJ11D_NetworkUp; button.ButtonPressed += button_ButtonPressed; sdCard.Unmounted += sdCard_Unmounted; sdCard.Mounted += sdCard_Mounted; _mqttclient.MqttMsgPublished += _mqttclient_MqttMsgPublished; Thread syncTimerThread, measureThread, systemTimerThread, publisheverythingThread; if (sdCard.IsCardMounted) { JSON.printConfiguration(sdCard, config); } //Debug.Print("Hello PC"); Bitmap my_bitmap = new Bitmap((Int32)displayTE35.Width, (Int32)displayTE35.Height); string mystring = "waiting for measure"; my_bitmap.DrawText(mystring, font, Microsoft.SPOT.Presentation.Media.Color.White, 5, 10); displayTE35.SimpleGraphics.DisplayImage(my_bitmap, 0, 0); ethernetJ11D.NetworkInterface.Open(); ethernetJ11D.NetworkSettings.EnableDhcp(); ethernetJ11D.NetworkSettings.EnableDynamicDns(); //ethernetJ11D.UseDHCP(); //initializeNetwork(); if (!sdCard.IsCardMounted) { sdCard.Mount(); } try { if (sdCard.IsCardMounted) { myread.delete_wrong_file(sdCard); FileStream fs = new FileStream(rootDirectory + @"\setup.txt", FileMode.Open); int byteRead = fs.Read(buffer, 0, 0); if (byteRead != 0) { SetUp.Wrong = 0; SetUp.lastToSend = 0; SetUp.writeFile(sdCard); } Debug.Print(buffer[0].ToString()); fs.Close(); } } catch (System.IO.IOException e) { } mytempsensor.Setup(); myuvsensor.Setup(); //myread.readSetup(sdCard); //initializeNetworkTimerThread = new Thread(this.initializeNetworkThread); //initializeNetworkTimerThread.Start(); //Creation of threads starting from there //Timer systemTimeDisplayTimer = new Timer(new TimerCallback(systemTimeDisplay), null, 0, 1000); systemTimerThread = new Thread(this.systemTimeDisplay); systemTimerThread.Start(); syncTimerThread = new Thread(this.syncTimer); syncTimerThread.Start(); //Thread.Sleep(1000); measureThread = new Thread(this.Measure); measureThread.Start(); publisheverythingThread = new Thread(this.PublishEverything); publisheverythingThread.Start(); //publishthread = new thread(this.publishmqtt); //publishthread.start(); }
void sdCard_Unmounted(SDCard sender, EventArgs e) { Mainboard.SetDebugLED(true); }
void sdCard_Mounted(SDCard sender, GT.StorageDevice device) { Mainboard.SetDebugLED(false); rootDirectory = sdCard.StorageDevice.RootDirectory; }
// This method is run when the mainboard is powered up or reset. void ProgramStarted() { Mainboard.SetDebugLED(true); // Clear all relays for (int i = 0; i < 8; i++) { SetRelay(i, false); } var volumes = Microsoft.SPOT.IO.VolumeInfo.GetVolumes(); var fs = Microsoft.SPOT.IO.VolumeInfo.GetFileSystems(); // Read the settings file if (System.IO.File.Exists("\\Settings.json")) { var reader = JsonReader.Create("\\Settings.json"); reader.ReadArray(); while (reader.Type == JsonType.Object) { reader.ReadObject(); int switchNumber = 0; int onTime = 0; int offTime = 0; while (reader.IsValue) { switch (reader.ReadName()) { case "switchNumber": switchNumber = (int)reader.ReadValueAsDouble(); break; case "onTime": onTime = (int)reader.ReadValueAsDouble(); break; case "offTime": offTime = (int)reader.ReadValueAsDouble(); break; } } _schedule.Add(new ScheduleItem(switchNumber, onTime, offTime)); reader.ReadEnd(); } reader.ReadEnd(); } // Init Wifi module comms StartCommunications(); SetTime(); _schedule.Add(new ScheduleItem(0, (18 * 60 + 38) * 60, (18 * 60 + 42) * 16)); SaveSchedule(); // Run the schedule immediately RunSchedule(); _clock.SetInterval(1, RunSchedule); Mainboard.SetDebugLED(false); // Run the server listen thread var t = new Thread(new ThreadStart(() => { while (true) { try { // Listen for a connect var socket = this._wifi.ListenSocket(2000); // The first line is the method and the URL var line = socket.ReadLine(); Debug.Print(line); var parts = line.Split(' '); var method = parts[0]; var url = parts[1]; // Read the headers until we get to the empty line var headers = new Hashtable(); line = socket.ReadLine(); while (line != "\r\n") { var index = line.IndexOf(':'); var key = line.Substring(0, index); var value = line.Substring(index + 1).Trim(); headers.Add(key, value); line = socket.ReadLine(); } // Find the content length var contentLength = 0; if (headers.Contains("Content-Length")) { contentLength = int.Parse((string)headers["Content-Length"]); } // Read the body var buffer = new StringBuilder(); while (buffer.Length < contentLength) { buffer.Append(socket.Read()); } switch (method) { case "GET": { var pathParts = url.Split('/'); if (pathParts.Length == 3) { if (pathParts[1] == "relays") { if (pathParts[2] == "all") { // Return all relay states SendResponse(GetAllRelayStates()); } else { // We expect a number var relayNum = Int32.Parse(pathParts[1]); SendResponse(GetRelay(relayNum).ToString()); } } } break; } case "POST": { var pathParts = url.Split('/'); if (pathParts.Length == 3) { if (pathParts[1] == "relays") { if (pathParts[2] == "all") { // Set all relay states // Body is a JSON string array of boolean values to set var relayStates = buffer.ToString().Trim('[', ']').Split(','); for (var i = 0; i < relayStates.Length; i++) { SetRelay(i, relayStates[i].Trim() == "true"); } SendResponse(""); } else { // We expect a number var relayNum = Int32.Parse(pathParts[1]); // Body is a single bool value var relayState = buffer.ToString() == "true"; SetRelay(relayNum, relayState); SendResponse(""); } } } break; } default: { SendError("Unknown method " + parts[0]); break; } } } catch (ApplicationException e) { Debug.Print(e.Message); } } })); t.Start(); }
public void VersionIndicatorLed(bool on) { _mb.SetDebugLED(on); }
private void setMainboardLED(bool state) { Mainboard.SetDebugLED(state); }