public static void Main() { using (var pi = new RaspberryPi()) { var led = new SimpleGPIO.Components.RGBLED(pi.GPIO23, pi.GPIO24, pi.GPIO25); var wait = TimeSpan.FromSeconds(0.5); led.TurnRed(); Thread.Sleep(wait); led.TurnYellow(); Thread.Sleep(wait); led.TurnGreen(); Thread.Sleep(wait); led.TurnCyan(); Thread.Sleep(wait); led.TurnBlue(); Thread.Sleep(wait); led.TurnPurple(); Thread.Sleep(wait); led.TurnOff(); Thread.Sleep(wait); led.TurnWhite(); Thread.Sleep(wait); } }
public IOHandler() { RaspberryPi.Initialize(); this.I2C = new I2CBusPi(); this.SPI = new SPIBusPi(0); this.PWMGenHighFreq = new PCA9685(this.I2C, 0x4C, -1, PCA9685.OutputInvert.Inverted, PCA9685.OutputDriverMode.OpenDrain); this.PWMGenLowFreq = new PCA9685(this.I2C, 0x74, -1, PCA9685.OutputInvert.Inverted, PCA9685.OutputDriverMode.OpenDrain); this.PWMGenHighFreq.SetFrequency(333); this.PWMGenLowFreq.SetFrequency(50); this.RailController = new Rail(this.PWMGenHighFreq.Outputs[0], new DigitalInPi(11), this.SPI, new DigitalOutPi(29), this.I2C, null) { TraceLogging = true }; this.DrillController = new Drill(this.PWMGenHighFreq.Outputs[1], this.PWMGenLowFreq.Outputs[0]); this.SampleController = new Sample(this.PWMGenLowFreq.Outputs[1]); this.LEDController = new LEDs(this.PWMGenLowFreq.Outputs, this.PWMGenHighFreq.Outputs); this.AuxSensors = new AuxSensors(this.SPI, this.I2C) { TraceLogging = false }; this.SysSensors = new SysSensors(); this.Music = new MusicPlayer(); this.InitProcedure = new ISubsystem[] { this.RailController, this.DrillController, this.LEDController, this.AuxSensors, this.SysSensors, this.Music }; this.EStopProcedure = new ISubsystem[] { this.Music, this.RailController, this.DrillController, this.LEDController, this.AuxSensors, this.SysSensors }; this.UpdateProcedure = new ISubsystem[] { this.RailController, this.DrillController, this.LEDController /*, this.AuxSensors, this.SysSensors*/ }; if (this.EStopProcedure.Length < this.InitProcedure.Length || this.EStopProcedure.Length < this.UpdateProcedure.Length) { throw new Exception("A system is registered for init or updates, but not for emergency stop. For safety reasons, this is not permitted."); } }
public static ParametresPortSerie CreerPourUARTGpioPi(uint vitesse, SerialParity parite, SerialStopBitCount bitsDeStop, ushort bitsDeDonnees, SerialHandshake controleDeFlux, double dureeLectureMs, double dureeEcritureMs) { if (string.IsNullOrEmpty(_piIdString)) { _piIdString = RaspberryPi.EstRaspberryPi2() ? @"\\?\ACPI#BCM2837#4#" : @"\\?\ACPI#BCM2836#0#"; } return(new ParametresPortSerie("", _piIdString, vitesse, parite, bitsDeStop, bitsDeDonnees, controleDeFlux, dureeLectureMs, dureeEcritureMs)); }
public void tearDown() { raspberryPi.reset(); raspberryPi = null; TestGpiooInterface = null; TestLcdDisplay = null; Testpotentiometer = null; Testadconverter = null; }
public void setUp() { rasPi = RaspberryPi.Instance; hwComponents = new HWComponent[] { new GPIOinterface(), new LCD(), new Potentiometer(), new Multiplexer(), new ADConverter() }; rasPi.initialize(hwComponents); mux = rasPi.Control.Multiplexer; ops = rasPi.Control; }
public static void Main() { var pi = new RaspberryPi(); var game = new Game(pi); game.Run(); Console.WriteLine("Press any key to exit..."); Console.ReadKey(); }
public void constructRaspberryPis() { foreach (string hostname in this.online) { try { RaspberryPi pi = new RaspberryPi(hostname); raspberryPis.Add(pi); } catch (Exception) { } } }
public static void Main() { using (var pi = new RaspberryPi()) { var button = pi.Pin11; var led = pi.Pin16; button.OnPowerOn(() => led.Toggle()); Console.WriteLine("Press any key to exit..."); Console.ReadKey(); } }
private static async Task Main() { var pi = new RaspberryPi(); var redLED = pi.Pin16; redLED.TurnOn(); await Task.Delay(TimeSpan.FromSeconds(5)); // I always pick up my playthings, and so // I will show you another good trick that I know pi.Dispose(); }
public void setUp() { raspberryPi = RaspberryPi.Instance; testAllComponents = new HWComponent[] { new GPIOinterface(), new LCD(), new Potentiometer(), new Multiplexer(), new ADConverter() }; testPartComponents = new HWComponent[] { new GPIOinterface(), new Multiplexer(), new ADConverter() }; testDuplicateComponents = new HWComponent[] { new GPIOinterface(), new Multiplexer(), new Multiplexer(), new ADConverter() }; TestGpiooInterface = new GPIOinterface(); TestLcdDisplay = new LCD(); Testpotentiometer = new Potentiometer(); Testmultiplexer = new Multiplexer(); Testadconverter = new ADConverter(); }
public static void Main() { using (var pi = new RaspberryPi()) { var dial = new SimpleGPIO.Components.RotaryEncoder(pi.Pin11, pi.Pin13); var x = 0; dial.OnIncrease(() => Console.WriteLine(++x)); dial.OnDecrease(() => Console.WriteLine(--x)); Console.WriteLine("Press any key to exit..."); Console.ReadKey(); } }
public void PinsAreMappedCorrectly(byte physical, byte bcm) { //arrange var newPin = Substitute.For <Func <byte, IPinInterface> >(); newPin.Invoke(Arg.Any <byte>()).Returns(p => new StubPinInterface(p.Arg <byte>())); var board = new RaspberryPi(newPin); //act var pin = (StubPinInterface)board.GetType().GetProperty($"Pin{physical}").GetValue(board); //assert Assert.Equal(bcm, pin.Pin); }
public static void Main() { using (var pi = new RaspberryPi()) { var display = new SimpleGPIO.Components.SevenSegmentDisplay(pi.GPIO23, pi.GPIO24, pi.GPIO25, pi.GPIO12, pi.GPIO17, pi.GPIO27, pi.GPIO22, pi.GPIO5); Console.WriteLine("Enter characters, or press enter to exit"); var keyInfo = new ConsoleKeyInfo(); do { display.Show(keyInfo.KeyChar); keyInfo = Console.ReadKey(); } while (keyInfo.Key != ConsoleKey.Enter); } Console.WriteLine(); }
public Game(RaspberryPi pi) { _cpuRed = pi.Pin11; _cpuYellow = pi.Pin13; _cpuGreen = pi.Pin15; _redButton = pi.Pin16; _yellowButton = pi.Pin18; _greenButton = pi.Pin22; _score1 = pi.Pin36; _score2 = pi.Pin38; _score3 = pi.Pin40; _difficultyDial = new RotaryEncoder(pi.Pin32, pi.Pin31); _random = new Random(); }
public void TestRaspberryPi() { //Arrange RaspberryPi pi = new RaspberryPi(); //Act pi.ID = 1; pi.Location = "test location"; pi.IsActive = true; pi.ProfileID = 1; //Assert Assert.AreEqual(pi.ID, 1); Assert.AreEqual(pi.Location, "test location"); Assert.AreEqual(pi.IsActive, true); Assert.AreEqual(pi.ProfileID, 1); }
public void TestUpdateOneIDOutOfRange() { //Arrange RaspberryPi u = new RaspberryPi() { Location = "Test Location Updated", IsActive = false, ID = 8, ProfileID = 2 }; RaspberryPisController controller = new RaspberryPisController(); //Act StatusCodeResult response = (StatusCodeResult)controller.Put(8, u); //Assert Assert.AreEqual(response.StatusCode, StatusCodes.Status404NotFound); }
public void TestUpdateOneIDMismatch() { //Arrange RaspberryPi u = new RaspberryPi() { Location = "Test Location Updated", IsActive = false, ID = 1, ProfileID = 2 }; RaspberryPisController controller = new RaspberryPisController(); //Act StatusCodeResult response = (StatusCodeResult)controller.Put(9, u); //Assert Assert.AreEqual(response.StatusCode, StatusCodes.Status400BadRequest); }
public void TestUpdateOne() { //Arrange RaspberryPi p = new RaspberryPi() { Location = "Test Location Updated", IsActive = false, ID = 3, ProfileID = 2 }; RaspberryPisController controller = new RaspberryPisController(); //Act StatusCodeResult response = (StatusCodeResult)controller.Put(3, p); //Assert Assert.AreEqual(response.StatusCode, 200); }
public RaspberryPi findPi(string hostname) { RaspberryPi pi = null; try { foreach (RaspberryPi search in raspberryPis) { if (search.getHostname() == hostname) { return(search); } } } catch (Exception) { } return(pi); }
public void TestPostOneProfileIDOutOfRange() { //Arrange RaspberryPi p = new RaspberryPi() { Location = "Test Location 3", IsActive = false, ID = 0, ProfileID = 237 }; RaspberryPisController controller = new RaspberryPisController(); //Act StatusCodeResult response = (StatusCodeResult)controller.Post(p); //Assert Assert.IsNotNull(response); Assert.AreEqual(response.StatusCode, 400); }
public static void Main() { using (var pi = new RaspberryPi()) { var enabledPin = pi.Pin11; var clockwisePin = pi.Pin13; var counterclockwisePin = pi.Pin15; var motor = new SimpleGPIO.Components.Motor(enabledPin, clockwisePin, counterclockwisePin); motor.TurnClockwiseFor(TimeSpan.FromSeconds(2)); //give it a second to fully stop before reversing Thread.Sleep(TimeSpan.FromSeconds(1)); motor.TurnCounterclockwiseFor(TimeSpan.FromSeconds(1), true); //give it some cooldown time before disposing, //as counterclockwisePin turning off will abruptly stop the motor Thread.Sleep(TimeSpan.FromSeconds(2)); } }
public void addRaspberryPi(string Address, string status) { //IsPiConnected = false; IPAddress address; try { address = IPAddress.Parse(Address); } catch (FormatException fx) { debugVM.AddDebugInfo("[ERROR]", "Invalid IP Address Format: " + fx.Message); return; } IPEndPoint endpoint = new IPEndPoint(address, 54321); foreach (var entry in BackendList) { if (entry.endpoint.Equals(endpoint)) { debugVM.AddDebugInfo("addRaspberryPi", "Already in the List"); return; } } RaspberryPi raspi = new RaspberryPi(); SynchronizationContext uiContext = SynchronizationContext.Current; raspi.ConnectionClosed += (object sender, Exception e) => OnConnectionClosed(sender, e, uiContext); RaspberryPiItem raspiItem = new RaspberryPiItem() { endpoint = endpoint, Status = status, raspi = raspi, Connected = false }; BackendList.Add(raspiItem); SelectedRaspiItem = raspiItem; CollectionViewSource.GetDefaultView(BackendList).Refresh(); }
public GpioController() { _pi = new RaspberryPi(); }
public PiCollection(ILoggerFactory loggerFactory) { try { _logger = loggerFactory.CreateLogger <PiCollection>(); zeros = new List <RaspberryPi>(); List <SlaveDevice> slaves; string folder = Environment.GetEnvironmentVariable("CONFIG_FOLDER"); string file = $"{folder}/RemoteHosts.xml"; if (System.IO.File.Exists(file)) { slaves = Common.LoadFromXML <List <SlaveDevice> >(file); } else { slaves = SlaveDevice.buildMcuListForTrack(); Common.SaveToXML <List <SlaveDevice> >(slaves, file); } foreach (SlaveDevice slave in slaves.Where(pi => pi.osType == Enums.RemoteOSType.Rpi)) { try { RaspberryPi rpi; file = $"{folder}/{slave.ipAddress}.xml"; if (System.IO.File.Exists(file)) { rpi = Common.LoadFromXML <RaspberryPi>(file); } else { rpi = new RaspberryPi(slave.ipAddress, slave.port); rpi.readRemoteConfigFile(); Common.SaveToXML <RaspberryPi>(rpi, file); } zeros.Add(rpi); //foreach (var rpiDevice in rpi.Relays) //{ // RelayDevice relay = new RelayDevice((Enums.ControlledAreas)rpiDevice.area, // rpiDevice.deviceName, // rpiDevice.state == 1, // rpi.ipAddress); // relay.mcu.port = rpi.port; // _relayDevices.relays.Add(relay); //} //foreach (var rpiDevice in rpi.PirDevices) //{ // PIRDevice pir = new PIRDevice((Enums.ControlledAreas)rpiDevice.area, rpiDevice.deviceName, rpi.ipAddress); // pir.mcu.port = rpi.port; // _pirDevices.pirDevices.Add(pir); //} //foreach (var rpiDevice in rpi.RFSwitches) //{ // RFSwitchDevice sw = new RFSwitchDevice((Enums.ControlledAreas)rpiDevice.area, rpiDevice.deviceName, rpiDevice.bitLength); // sw.mcu.ipAddress = rpi.ipAddress; // sw.mcu.port = rpi.port; // rpiDevice.onCodes.Skip(1).ToList().ForEach(c => sw.addCode(true, (Convert.ToInt64(c)))); // rpiDevice.offCodes.Skip(1).ToList().ForEach(c => sw.addCode(false, (Convert.ToInt32(c)))); // _rfSwitches.areaSwitches.Add(sw); //} } catch (Exception ex) { _logger.LogError($"Constructor(): Unexpected error: {ex.Message}"); } } } catch (Exception ex) { _logger.LogError($"Constructor(): Unexpected error: {ex.Message}"); } return; }
public RobotController(RaspberryPi pi) { _drive = new Motor(pi.Pin11, pi.Pin13); _flag = new Motor(pi.Pin33, pi.Pin35); _buzzer = pi.Pin40; }
public static void EnsureDatabaseCreated(IServiceProvider services) { var context = services.GetRequiredService <AutomaticaContext>(); var visuInitFactory = services.GetRequiredService <IVisualisationFactory>(); var config = services.GetRequiredService <IConfiguration>(); context.Database.Migrate(); bool dbCreated = !context.BoardTypes.Any(); if (dbCreated) { context.RuleInterfaceDirections.Add(new EF.Models.RuleInterfaceDirection() { ObjId = 1, Name = "Input", Description = "Input", Key = "I" }); context.RuleInterfaceDirections.Add(new EF.Models.RuleInterfaceDirection() { ObjId = 2, Name = "Output", Description = "Output", Key = "O" }); context.RuleInterfaceDirections.Add(new EF.Models.RuleInterfaceDirection() { ObjId = 3, Name = "Parameter", Description = "Parameter", Key = "P" }); context.RulePageTypes.Add(new RulePageType() { ObjId = 1, Name = "Rules", Description = "Rules", Key = "rules" }); context.VisuPageTypes.Add(new VisuPageType() { ObjId = 1, Name = "PC", Description = "PC", Key = "pc" }); context.VisuPageTypes.Add(new VisuPageType() { ObjId = 2, Name = "Mobile", Description = "Mobile", Key = "mobile" }); context.SaveChanges(); context.Slaves.Add(new Slave() { ObjId = new Guid(ServerInfo.SelfSlaveId), Name = "local", Description = "this is me", ClientId = "", ClientKey = "" }); context.Settings.Add(new Setting { ObjId = 1, ValueKey = "ConfigVersion", Type = (long)PropertyTemplateType.Numeric, Value = 0, Group = "ConfigVersion", IsVisible = false, Order = 10 }); context.SaveChanges(); } var lat = context.Settings.SingleOrDefault(a => a.ValueKey == "Latitude"); if (lat == null) { context.Settings.Add(new Setting { ValueKey = "Latitude", Type = (long)PropertyTemplateType.Numeric, Value = 0, Group = "SERVER.SETTINGS", IsVisible = true, Order = 10 }); context.Settings.Add(new Setting { ValueKey = "Longitude", Type = (long)PropertyTemplateType.Numeric, Value = 0, Group = "SERVER.SETTINGS", IsVisible = true, Order = 11 }); } else { var longi = context.Settings.SingleOrDefault(a => a.ValueKey == "Longitude"); if (lat.ValueDouble == null) { lat.ValueDouble = 0; } if (longi.ValueDouble == null) { longi.ValueDouble = 0; } context.Settings.Update(longi); context.Settings.Update(lat); } var apiKey = context.Settings.SingleOrDefault(a => a.ValueKey == "apiKey"); if (apiKey == null) { context.Settings.Add(new Setting { ValueKey = "apiKey", Type = (long)PropertyTemplateType.Text, Value = "", Group = "SERVER.SETTINGS", IsVisible = true, Order = 0 }); } var autoUpdate = context.Settings.SingleOrDefault(a => a.ValueKey == "autoUpdate"); var autoUpdateTime = context.Settings.SingleOrDefault(a => a.ValueKey == "autoUpdateTime"); var reportCrashLogs = context.Settings.SingleOrDefault(a => a.ValueKey == "reportCrashLogs"); if (autoUpdate == null) { context.Settings.Add(new Setting { ValueKey = "autoUpdate", Type = (long)PropertyTemplateType.Bool, Value = false, Group = "SERVER.SETTINGS", IsVisible = true, Order = 20 }); } else { autoUpdate.Order = 20; context.Update(autoUpdate); } if (autoUpdateTime == null) { context.Settings.Add(new Setting { ValueKey = "autoUpdateTime", Type = (long)PropertyTemplateType.Time, Value = new DateTime(2000, 12, 31, 2, 0, 0), Group = "SERVER.SETTINGS", IsVisible = true, Order = 21 }); } else { autoUpdateTime.Order = 21; autoUpdateTime.Type = (long)PropertyTemplateType.Time; context.Update(autoUpdateTime); } if (reportCrashLogs == null) { context.Settings.Add(new Setting { ValueKey = "reportCrashLogs", Type = (long)PropertyTemplateType.Bool, Value = false, Group = "SERVER.SETTINGS", IsVisible = true, Order = 22 }); } else { reportCrashLogs.Order = 22; context.Update(reportCrashLogs); } var cloudUrl = context.Settings.SingleOrDefault(a => a.ValueKey == "cloudUrl"); if (cloudUrl == null) { context.Settings.Add(new Setting { ValueKey = "cloudUrl", Type = (long)PropertyTemplateType.Text, Value = "https://automatica-core-cloud.azurewebsites.net", Group = "SERVER.SETTINGS", IsVisible = true, Order = 1 }); } var cloudEnvironment = context.Settings.SingleOrDefault(a => a.ValueKey == "cloudEnvironment"); if (cloudEnvironment == null) { var cloudEnvironmentType = "master"; #if DEBUG cloudEnvironmentType = "develop"; #else cloudEnvironmentType = "master"; #endif context.Settings.Add(new Setting { ValueKey = "cloudEnvironment", Type = (long)PropertyTemplateType.Text, Value = cloudEnvironmentType, Group = "SERVER.SETTINGS", IsVisible = true, Order = 2 }); } var projectName = context.Settings.SingleOrDefault(a => a.ValueKey == "projectName"); if (projectName == null) { context.Settings.Add(new Setting { ValueKey = "projectName", Type = (long)PropertyTemplateType.Text, Value = "Automatica.Core", Group = "SERVER.SETTINGS", IsVisible = true, Order = 3 }); } var propertyTypes = Enum.GetValues(typeof(PropertyTemplateType)); foreach (var propertyType in propertyTypes) { var propertyTypeDb = context.PropertyTypes.SingleOrDefault(a => a.Type == Convert.ToInt64(propertyType)); var isNewObject = false; if (propertyTypeDb == null) { propertyTypeDb = new PropertyType { Type = (int)propertyType }; isNewObject = true; } var type = propertyType.GetType(); var memInfo = type.GetMember(propertyType.ToString()); var attributes = memInfo[0].GetCustomAttributes(typeof(PropertyTemplateTypeAttribute), false); if (attributes.Length > 0 && attributes[0] is PropertyTemplateTypeAttribute attribute) { propertyTypeDb.Name = attribute.Name; propertyTypeDb.Description = attribute.Description; propertyTypeDb.Meta = attribute.Meta; } else { propertyTypeDb.Name = propertyType.GetType().Name; propertyTypeDb.Description = propertyType.GetType().Name; propertyTypeDb.Meta = null; } if (isNewObject) { context.PropertyTypes.Add(propertyTypeDb); } else { context.PropertyTypes.Update(propertyTypeDb); } } var nodeDataTypes = Enum.GetValues(typeof(NodeDataType)); foreach (var nodeDataType in nodeDataTypes) { var nodeDataTypeDb = context.NodeDataTypes.SingleOrDefault(a => a.Type == Convert.ToInt64(nodeDataType)); var isNewObject = false; if (nodeDataTypeDb == null) { nodeDataTypeDb = new EF.Models.NodeDataType(); nodeDataTypeDb.Type = (int)nodeDataType; isNewObject = true; } var type = nodeDataType.GetType(); var memInfo = type.GetMember(nodeDataType.ToString()); var attributes = memInfo[0].GetCustomAttributes(typeof(NodeDataTypeEnumAttribute), false); if (attributes.Length > 0 && attributes[0] is NodeDataTypeEnumAttribute attribute) { nodeDataTypeDb.Name = attribute.Name; nodeDataTypeDb.Description = attribute.Description; } else { nodeDataTypeDb.Name = nodeDataType.GetType().Name; nodeDataTypeDb.Description = nodeDataType.GetType().Name; } if (isNewObject) { context.NodeDataTypes.Add(nodeDataTypeDb); } else { context.NodeDataTypes.Update(nodeDataTypeDb); } } context.SaveChanges(); visuInitFactory.Initialize(context, config); context.SaveChanges(); CreateInterfaceTypes(context); context.SaveChanges(); AddSystemTemplates(context); IDatabaseBoardType boardType = null; if (BoardTypes.Docker.Docker.InDocker) { boardType = new BoardTypes.Docker.Docker(); } else { boardType = new RaspberryPi(); } ServerInfo.BoardType = boardType; AddBoard(context, boardType); AddAreaData(context); CategoryGroup.GenerateDefault(context); context.SaveChanges(); CategoryInstance.GenerateDefault(context); context.SaveChanges(); if (!context.AreaInstances.Any()) { var projectInstance = new AreaInstance { ObjId = Guid.NewGuid(), Name = "Project", Description = "", Icon = "home", This2AreaTemplate = AreaTemplateAttribute.GetFromEnum(AreaTemplates.Project), This2Parent = null }; context.AreaInstances.Add(projectInstance); } if (dbCreated) { var rootNodeTemplate = context.NodeTemplates.SingleOrDefault(a => a.ObjId == GuidTemplateTypeAttribute.GetFromEnum(boardType.BoardType)); var rootNode = NodeInstanceFactory.CreateNodeInstanceFromTemplate(rootNodeTemplate); rootNode.Name = boardType.Name; rootNode.Description = ""; context.NodeInstances.Add(rootNode); var childs = context.NodeTemplates.Where(a => a.NeedsInterface2InterfacesType == rootNodeTemplate.ObjId); foreach (var child in childs) { if (child.NeedsInterface2InterfacesType == child.ProvidesInterface2InterfaceType) { continue; } var node = NodeInstanceFactory.CreateNodeInstanceFromTemplate(child); node.This2ParentNodeInstance = rootNode.ObjId; context.NodeInstances.Add(node); } var rulePage = new RulePage { ObjId = Guid.NewGuid(), Name = "Page1", Description = "", This2RulePageType = 1 }; context.RulePages.Add(rulePage); var visuPage = new VisuPage { ObjId = Guid.NewGuid(), Name = "Page1", Description = "", This2VisuPageType = 2, DefaultPage = true }; context.VisuPages.Add(visuPage); AddInitUserManagementData(context); context.SaveChanges(); } context.SaveChanges(); }
public static void Start(string[] args) { if (args.Length < 3) { TestMain.ErrorExit("io pi command requires functionality to test."); } RaspberryPi.Initialize(); switch (args[2].ToLower()) { case "digin": { if (args.Length < 4) { TestMain.ErrorExit("io pi digin command requires pin to test."); } int PinNum = int.Parse(args[3]); Log.Output(Log.Severity.INFO, Log.Source.HARDWAREIO, "Testing digital input on RPi pin " + PinNum); IDigitalIn Input = new DigitalInPi(PinNum); while (true) { Log.Output(Log.Severity.INFO, Log.Source.HARDWAREIO, "Current pin state: " + (Input.GetInput() ? "HIGH" : "LOW")); Thread.Sleep(250); } } case "digout": { if (args.Length < 4) { TestMain.ErrorExit("io pi digout command requires pin to test."); } int PinNum = int.Parse(args[3]); if (args.Length < 5) { TestMain.ErrorExit("io pi digout command requires output mode (high/low/blink)."); } if (args[4] != "high" && args[4] != "low" && args[4] != "blink") { TestMain.ErrorExit("Invalid digout test mode supplied."); } Log.Output(Log.Severity.INFO, Log.Source.HARDWAREIO, "Testing digital output on RPi pin " + PinNum); IDigitalOut Output = new DigitalOutPi(PinNum); if (args[4] == "high") { Output.SetOutput(true); } else if (args[4] == "low") { Output.SetOutput(false); } else { bool Out = false; while (true) { Output.SetOutput(Out); Out = !Out; Thread.Sleep(250); } } break; } case "pwm": { TestMain.ErrorExit("io pi pwm command not yet implemented."); // TODO: Remove when implementing. if (args.Length < 4) { TestMain.ErrorExit("io pi pwm command requires pin to test."); } int PinNum = int.Parse(args[3]); if (args.Length < 5) { TestMain.ErrorExit("io pi pwm command requires frequency."); } int Frequency = int.Parse(args[4]); if (args.Length < 6) { TestMain.ErrorExit("io pi pwm command requires output mode."); } if (args[5] != "per" && args[5] != "sine") { TestMain.ErrorExit("io pi pwm command invalid (per/sine)."); } if (args[5] == "per" && args.Length < 7) { TestMain.ErrorExit("io pi pwm per must be provided duty cycle."); } IPWMOutput Output = null; // TODO: Implement RPi PWM output. Output.SetFrequency(Frequency); Log.Output(Log.Severity.INFO, Log.Source.HARDWAREIO, "Testing PWM output on RPi pin " + PinNum + " at " + Frequency + "Hz."); if (args[5] == "per") { Output.SetOutput(int.Parse(args[6]) / 100F); Output.SetEnabled(true); Thread.Sleep(15000); // Not sure if it stops outputting when the program exits. } else { int Cycle = 0; while (true) { float Val = (float)((Math.Sin(Cycle * Math.PI / 180.000D) + 1) / 2); Output.SetOutput(Val); Thread.Sleep(50); Cycle += 20; } } break; } case "adc": { TestMain.ErrorExit("RPI does not have an ADC."); break; } case "int": { if (args.Length < 4) { TestMain.ErrorExit("io pi int command requires pin to test."); } int PinNum = int.Parse(args[3]); if (args.Length < 5) { TestMain.ErrorExit("io pi int command requires interrupt mode (rise/fall/both)."); } if (args[4] != "rise" && args[4] != "fall" && args[4] != "both") { TestMain.ErrorExit("Invalid interrupt mode supplied."); } IDigitalIn Input = new DigitalInPi(PinNum); Log.Output(Log.Severity.INFO, Log.Source.HARDWAREIO, "Testing interrupts on RPi pin " + PinNum); switch (args[4]) { case "rise": ((IInterruptSource)Input).RegisterInterruptHandler(GetInterrupt, InterruptType.RISING_EDGE); break; case "fall": ((IInterruptSource)Input).RegisterInterruptHandler(GetInterrupt, InterruptType.FALLING_EDGE); break; case "both": ((IInterruptSource)Input).RegisterInterruptHandler(GetInterrupt, InterruptType.ANY_EDGE); break; } while (true) { Thread.Sleep(50); } // Program needs to be running to receive. } case "outperf": { if (args.Length < 4) { TestMain.ErrorExit("io pi outperf command requires pin to test."); } int PinNum = int.Parse(args[3]); Log.Output(Log.Severity.INFO, Log.Source.HARDWAREIO, "Testing digital output speed on RPi pin " + PinNum); IDigitalOut Output = new DigitalOutPi(PinNum); bool Out = false; while (!Console.KeyAvailable) { Output.SetOutput(Out); Out = !Out; } Output.SetOutput(false); break; } } }
public void ParseCommands(int alive) { foreach (RaspberryPi s in rasPis) { Console.WriteLine(s); } string command = ""; do { menu = new MainMenu(alive); menu.printMenu(); command = Console.ReadLine(); Console.WriteLine(); switch (command) { case "1": menu = new StatusMenu(alive); menu.printMenu(); secondaryCommands(1); break; case "2": menu = new RebootMenu(alive); menu.printMenu(); secondaryCommands(2); break; case "3": menu = new UpdateMenu(alive); menu.printMenu(); secondaryCommands(3); break; case "4": menu = new TransferMenu(alive); menu.printMenu(); secondaryCommands(4); break; case "5": menu = new InstallMenu(alive); menu.printMenu(); secondaryCommands(5); break; case "6": //Special Case Console.WriteLine("This is a special case -- to be implemented."); menu = new SetupMenu(); menu.printMenu(); break; case "7": // Special Case menu = new ShellMenu(); menu.printMenu(); string id = Console.ReadLine(); List <RaspberryPi> tempList = new List <RaspberryPi>(); string hostname = "pi-sign-" + id; RaspberryPi pi = this.network.findPi(hostname); if (pi != null) { tempList.Add(this.network.findPi(hostname)); selectCommand(7, tempList); } else { Console.WriteLine("Invalid host. Please try again."); Console.ReadKey(); break; } //secondaryCommands(7); break; case "8": //Special Case menu = new InfoMenu(); menu.printMenu(); string option = ""; option = Console.ReadLine(); menu.printSecondaryMenu(option); break; case "9": return; default: Console.WriteLine("Not a valid command. Please try again."); break; } } while (command != "9"); }
public ConnectPins(RaspberryPi raspberry) { this.raspberry = raspberry; }
public void getData() { var request = new ScanRequest { TableName = "SensorTag", }; client.ScanAsync(request, (result) => { List <RaspberryPi> allRaspberryPis = new List <RaspberryPi>(); RaspberryPi rpi = new RaspberryPi(); List <SensorTag> allSensorTags = new List <SensorTag>(); foreach (var item in result.Response.Items) { SensorTag sensorTag = new SensorTag(); foreach (var kvp in item) { string attributeName = kvp.Key; AttributeValue value = kvp.Value; if (attributeName == "defRoute") { rpi.defRoute = value.S; } else if (attributeName == "myName") { rpi.myName = value.S; } if (value.IsMSet) { foreach (var key in value.M.Keys) { foreach (var val in value.M.Values) { if (val.IsMSet) { foreach (var k in val.M) { AttributeValue valu; val.M.TryGetValue(k.Key, out valu); if (k.Key.Trim() == "Air Pressure (hPa)") { sensorTag.airpressure = k.Key + ": " + valu.N; //Debug.Log(sensorTag.airpressure); } else if (k.Key.Trim() == "RSSI (dBm)") { sensorTag.rssi = k.Key + ": " + valu.N; //Debug.Log(sensorTag.rssi); } else if (k.Key.Trim() == "Light (lux)") { sensorTag.light = k.Key + ": " + valu.N; //Debug.Log(sensorTag.light); } else if (k.Key.Trim() == "Seq #") { sensorTag.seq = k.Key + ": " + valu.N; //Debug.Log(sensorTag.seq); } else if (k.Key.Trim() == "Air Temp (C)") { sensorTag.airtemp = k.Key + ": " + valu.N; //Debug.Log(sensorTag.airtemp); } else if (k.Key.Trim() == "Object Temp (C)") { sensorTag.objecttemp = k.Key + ": " + valu.N; //Debug.Log(sensorTag.objecttemp); } else if (k.Key.Trim() == "Acc Y (G)") { sensorTag.accy = k.Key + ": " + valu.N; //Debug.Log(sensorTag.accy); } else if (k.Key.Trim() == "Gyro Z (deg per sec)") { sensorTag.gyroz = k.Key + ": " + valu.N; //Debug.Log(sensorTag.gyroz); } else if (k.Key.Trim() == "Gyro X (deg per sec)") { sensorTag.gyrox = k.Key + ": " + valu.N; //Debug.Log(sensorTag.gyrox); } else if (k.Key.Trim() == "HDC Humidity (%RH)") { sensorTag.hdchumidity = k.Key + ": " + valu.N; //Debug.Log(sensorTag.hdchumidity); } else if (k.Key.Trim() == "Uptime (sec)") { sensorTag.uptime = k.Key + ": " + valu.N; //Debug.Log(sensorTag.uptime); } else if (k.Key.Trim() == "defRoute") { sensorTag.defroute = k.Key + ": " + valu.S; //Debug.Log(sensorTag.defroute); } else if (k.Key.Trim() == "Battery Temp (C)") { sensorTag.batterytemp = k.Key + ": " + valu.N; //Debug.Log(sensorTag.batterytemsp); } else if (k.Key.Trim() == "HDC Temp (C)") { sensorTag.hdctemp = k.Key + ": " + valu.N; //Debug.Log(sensorTag.hdctemp); } else if (k.Key.Trim() == "Ambient Temp (C)") { sensorTag.ambienttemp = k.Key + ": " + valu.N; //Debug.Log(sensorTag.ambienttemp); } else if (k.Key.Trim() == "Gyro Y (deg per sec)") { sensorTag.gyroy = k.Key + ": " + valu.N; //Debug.Log(sensorTag.gyroy); } else if (k.Key.Trim() == "myName") { sensorTag.shortName = valu.S + ""; sensorTag.name = k.Key + ": " + sensorTag.shortName; //Debug.Log(sensorTag.name); } else if (k.Key.Trim() == "Acc X (G)") { sensorTag.accx = k.Key + ": " + valu.N; //Debug.Log(sensorTag.accx); } else if (k.Key.Trim() == "Battery Volt (mV)") { sensorTag.batteryvolt = k.Key + ": " + valu.N; //Debug.Log(sensorTag.batteryvolt); } else if (k.Key.Trim() == "Acc Z (G)") { sensorTag.accz = k.Key + ": " + valu.N; //Debug.Log(sensorTag.accz); } } } } } } } allSensorTags.Add(sensorTag); } List <SensorTag> oldSensorTags = rpi.sensorTags; rpi.sensorTags = allSensorTags; allRaspberryPis.Add(rpi); if (!canvas.isActiveAndEnabled) { updateSensorTags(allRaspberryPis, oldSensorTags); } else { //displaySensorData(currentSensorTag); test(allRaspberryPis); } }); }