public TrainStationProcessor(System.Windows.Forms.Label label) { rand = new Random(); ip = "localhost:8000"; if (!File.Exists("ip.txt")) { File.Create("ip.txt"); } if (File.Exists("ip.txt")) { try { string temp = File.ReadAllText("ip.txt"); if (!string.IsNullOrEmpty(temp) && !string.IsNullOrWhiteSpace(temp) && temp.Length > 2) { ip = temp; } } catch (Exception) { } } if (!localOnly) { _service = new TrafficMessageClient("BasicHttpBinding_ITrafficMessage", "http://" + ip + "/MEX/MessageService"); //_service = new TrafficMessageClient(); _inMessage = new ServerMessage(); _outMessage = new ServerMessage(); } string[] comports = System.IO.Ports.SerialPort.GetPortNames(); if (comports.Length > 0) { _arduino = new Arduino(0, System.IO.Ports.SerialPort.GetPortNames()[0]); _ledControl = new LedControl(_arduino, 6, 50); try { _arduino.Connect(); _ledControl.InitializeLedStrip(); } catch (Exception ex) { Console.WriteLine(ex.Message); } } //_timer = new Timer(500.0); //_timer.Elapsed += Tick; _timer = new System.Windows.Forms.Timer(); _timer.Interval = 127; _timer.Tick += _timer_Tick; _timer.Enabled = true; _timer.Start(); }
public App() { //TODO: Find out if this is even right for finding the pin var ledPin = (IDigitalPin)Device.Pins.AllPins.Single(x => x.Name == LedPinName); _sleepTimer = new BlockingTimer(TimeSpan.FromMilliseconds(100)); _ledControl = new LedControl(ledPin, _sleepTimer); var lightSensorI2cConfig = new I2cPeripheral.Configuration(LightSensorDeviceAddress, I2cDeviceClockHz); var lightI2cPeripheral = new I2cPeripheral(lightSensorI2cConfig); _lightSensor = new APDS9301_LightSensor(lightI2cPeripheral, APDS9301_LightSensor.MinimumPollingPeriod); }
public CameraParam() { iShutterSpeed = 2000; iGain = 10; ledCtrl = LedControl.IO; strControlCardName = string.Empty; iIoNum = 0; strLedControllerName = string.Empty; iLuminance = 50; iChannel = 0; strCamBingding = string.Empty; iWhiteBalanceR = 0; iWhiteBalanceG = 0; iWhiteBalanceB = 0; }
static void Main() { //Compile with: // dotnet publish ./RaspbianNetCoreDemo -c Release -r linux-arm --self-contained var taskSchedulerUtility = new TaskSchedulerUtility(); var fileUtils = new AsyncFileUtil(); var pinController = new LinuxPinController(fileUtils, taskSchedulerUtility); var ledPin = pinController.GetOrCreateOutputPin(LedPinNumber); BlockingTimer sleepTimer = new BlockingTimer(TimeSpan.FromMilliseconds(100)); LedControl ledControl = new LedControl(ledPin, sleepTimer); //while (true) //{ // ledControl.Blink(); //} var lightSensorDevice = new I2cDevice(I2cDevicePath, LightSensorDeviceAddress); var lightSensor = new APDS9301_LightSensor(lightSensorDevice, APDS9301_LightSensor.MinimumPollingPeriod); while (true) { float currentLuminosity = lightSensor.Luminosity; if (!ledControl.State && currentLuminosity <= OnMinimumLuminosity) { ledControl.Blink(); ledControl.Blink(); ledControl.TurnOnLed(); System.Diagnostics.Debug.WriteLine(currentLuminosity.ToString()); } else if (ledControl.State && currentLuminosity > OnMinimumLuminosity) { ledControl.TurnOffLed(); System.Diagnostics.Debug.WriteLine(currentLuminosity.ToString()); } Thread.Sleep(10); } //TODO: Dispose these somehow // Only care if exception is thrown on startup when the I2C Bus and IO Pins are already setup I guess //lightSensor.Dispose(); //pinController.Dispose(); }
static void Main() { GpioPin led = GpioController.GetDefault().OpenPin(FezPins.GpioPin.D0); led.SetDriveMode(GpioPinDriveMode.Output); BlockingTimer sleepTimer = new BlockingTimer(TimeSpan.FromMilliseconds(100)); LedControl ledControl = new LedControl(led, sleepTimer); int sdaPin = FezPins.GpioPin.A0; int slcPin = FezPins.GpioPin.A1; int lightSensorDeviceAddress = 0x39; I2cConnectionSettings ledDeviceConnectionSettings = new I2cConnectionSettings(lightSensorDeviceAddress, I2cAddressFormat.SevenBit, I2cBusSpeed.StandardMode); I2cControllerSoftwareProvider i2cProvider = new I2cControllerSoftwareProvider(sdaPin, slcPin, false); I2cController i2cController = I2cController.FromProvider(i2cProvider); I2cDevice lightSensorDevice = i2cController.GetDevice(ledDeviceConnectionSettings); var lightSensor = new APDS9301_LightSensor(lightSensorDevice, APDS9301_LightSensor.MinimumPollingPeriod); while (true) { float currentLuminosity = lightSensor.Luminosity; if (!ledControl.State && currentLuminosity <= OnMinimumLuminosity) { ledControl.Blink(); ledControl.Blink(); ledControl.TurnOnLed(); System.Diagnostics.Debug.WriteLine(currentLuminosity.ToString()); } else if (ledControl.State && currentLuminosity > OnMinimumLuminosity) { ledControl.TurnOffLed(); System.Diagnostics.Debug.WriteLine(currentLuminosity.ToString()); } Thread.Sleep(10); } }
public async void Run(IBackgroundTaskInstance taskInstance) { _deferral = taskInstance.GetDeferral(); taskInstance.Canceled += TaskInstance_Canceled; _gpioController = await GpioController.GetDefaultAsync(); _ledPin = _gpioController.OpenPin(LedPinNumber); _ledPin.SetDriveMode(GpioPinDriveMode.Output); var sleepTimer = new BlockingTimer(TimeSpan.FromMilliseconds(100)); _ledController = new LedControl(_ledPin, sleepTimer); var ledDeviceConnectionSettings = new I2cConnectionSettings(LightSensorDeviceAddress); var i2cController = await I2cController.GetDefaultAsync(); var lightSensorDevice = i2cController.GetDevice(ledDeviceConnectionSettings); _lightSensor = new APDS9301_LightSensor(lightSensorDevice, APDS9301_LightSensor.MinimumPollingPeriod); ThreadPoolTimer.CreatePeriodicTimer(Tick, TimeSpan.FromMilliseconds(500)); }
bool initLed() { string strException = string.Empty; string strComPort = conf.LedControlPort; string nBaudrate = "9600"; ledCtrl = new LedControl(); ledCtrl.callback = onLedControlResp; int nRet = ledCtrl.OpenCom(strComPort, out strException); if (nRet != 0) { string strLog = "连接LED设备失败,失败原因: " + strException; WriteLog(logRichText, strLog, 1); writeLog("open infrared port fail"); return false; } else { string strLog = "连接LED设备 " + strComPort + "@" + nBaudrate.ToString(); WriteLog(logRichText, strLog, 0); writeLog("open infrared port ok"); } ledCtrl.closeLed(); //ledTimerInit(); return true; }