public static void Run() { //ExStart:InterruptMonitorSupport string dataDir = RunExamples.GetDataDir_DrawingAndFormattingImages(); ImageOptionsBase saveOptions = new PngOptions(); InterruptMonitor monitor = new InterruptMonitor(); SaveImageWorker worker = new SaveImageWorker(dataDir + "aspose-logo_tn.jpg", dataDir + "big_out.png", saveOptions, monitor); Thread thread = new Thread(new ThreadStart(worker.ThreadProc)); try { thread.Start(); // The timeout should be less than the time required for full image conversion (without interruption). Thread.Sleep(3000); // Interrupt the process monitor.Interrupt(); Console.WriteLine("Interrupting the save thread #{0} at {1}", thread.ManagedThreadId, System.DateTime.Now); // Wait for interruption... thread.Join(); } finally { // If the file to be deleted does not exist, no exception is thrown. File.Delete(dataDir + "big_out.png"); } }
public Task ApplyAsync() { var hsrt16 = _ccToolsBoardService.RegisterHSRT16("HSRT16", new I2CSlaveAddress(32)); var garden = _areaService.RegisterArea("Garden"); var parkingLotLamp = new LogicalBinaryOutput(hsrt16[HSRT16Pin.Relay6], hsrt16[HSRT16Pin.Relay7], hsrt16[HSRT16Pin.Relay8]); _actuatorFactory.RegisterLamp(garden, Garden.LampParkingLot, parkingLotLamp); // Relay 9 is free. _actuatorFactory.RegisterSocket(garden, Garden.SocketPavillion, hsrt16[HSRT16Pin.Relay10]); _actuatorFactory.RegisterLamp(garden, Garden.LampRearArea, hsrt16[HSRT16Pin.Relay11]); _actuatorFactory.RegisterLamp(garden, Garden.SpotlightRoof, hsrt16[HSRT16Pin.Relay12]); _actuatorFactory.RegisterLamp(garden, Garden.LampTap, hsrt16[HSRT16Pin.Relay13]); _actuatorFactory.RegisterLamp(garden, Garden.LampGarage, hsrt16[HSRT16Pin.Relay14]); _actuatorFactory.RegisterLamp(garden, Garden.LampTerrace, hsrt16[HSRT16Pin.Relay15]); var stateMachine = _actuatorFactory.RegisterStateMachine(garden, Garden.StateMachine, InitializeStateMachine); var button = _sensorFactory.RegisterButton(garden, Garden.Button, _pi2GpioService.GetInput(4).WithInvertedState()); button.PressedShortTrigger.Attach(() => stateMachine.TrySetNextState()); button.PressedLongTrigger.Attach(() => stateMachine.TryTurnOff()); _automationFactory.RegisterConditionalOnAutomation(garden, Garden.LampParkingLotAutomation) .WithComponent(garden.GetLamp(Garden.LampParkingLot)) .WithOnAtNightRange() .WithOffBetweenRange(TimeSpan.Parse("22:30:00"), TimeSpan.Parse("05:00:00")); var ioBoardsInterruptMonitor = new InterruptMonitor(_pi2GpioService.GetInput(4), _logService); ioBoardsInterruptMonitor.AddCallback(_ccToolsBoardService.PollInputBoardStates); ioBoardsInterruptMonitor.Start(); return(Task.FromResult(0)); }
/// <summary> /// Initializes a new instance of the <see cref="SaveImageWorker" /> class. /// </summary> /// <param name="inputPath">The path to the input image.</param> /// <param name="outputPath">The path to the output image.</param> /// <param name="saveOptions">The save options.</param> /// <param name="monitor">The interrupt monitor.</param> public SaveImageWorker(string inputPath, string outputPath, ImageOptionsBase saveOptions, InterruptMonitor monitor) { this.inputPath = inputPath; this.outputPath = outputPath; this.saveOptions = saveOptions; this.monitor = monitor; }
public Task ApplyAsync() { var hsrt16 = _ccToolsBoardService.RegisterHSRT16(InstalledDevice.CellarHSRT16, new I2CSlaveAddress(32)); var garden = _areaService.CreateArea(Room.Garden); var parkingLotLamp = new LogicalBinaryOutput(hsrt16[HSRT16Pin.Relay6], hsrt16[HSRT16Pin.Relay7], hsrt16[HSRT16Pin.Relay8]); _actuatorFactory.RegisterLamp(garden, Garden.LampParkingLot, parkingLotLamp); // Relay 9 is free. _actuatorFactory.RegisterSocket(garden, Garden.SocketPavillion, hsrt16[HSRT16Pin.Relay10]); _actuatorFactory.RegisterLamp(garden, Garden.LampRearArea, hsrt16[HSRT16Pin.Relay11]); _actuatorFactory.RegisterLamp(garden, Garden.SpotlightRoof, hsrt16[HSRT16Pin.Relay12]); _actuatorFactory.RegisterLamp(garden, Garden.LampTap, hsrt16[HSRT16Pin.Relay13]); _actuatorFactory.RegisterLamp(garden, Garden.LampGarage, hsrt16[HSRT16Pin.Relay14]); _actuatorFactory.RegisterLamp(garden, Garden.LampTerrace, hsrt16[HSRT16Pin.Relay15]); _actuatorFactory.RegisterStateMachine(garden, Garden.StateMachine, InitializeStateMachine); _sensorFactory.RegisterButton(garden, Garden.Button, _pi2GpioService.GetInput(4).WithInvertedState()); garden.GetStateMachine(Garden.StateMachine).ConnectMoveNextAndToggleOffWith(garden.GetButton(Garden.Button)); _automationFactory.RegisterConditionalOnAutomation(garden, Garden.LampParkingLotAutomation) .WithActuator(garden.GetLamp(Garden.LampParkingLot)) .WithOnAtNightRange() .WithOffBetweenRange(TimeSpan.Parse("22:30:00"), TimeSpan.Parse("05:00:00")); var ioBoardsInterruptMonitor = new InterruptMonitor(_pi2GpioService.GetInput(4)); ioBoardsInterruptMonitor.InterruptDetected += (s, e) => _ccToolsBoardService.PollInputBoardStates(); ioBoardsInterruptMonitor.Start(); return(Task.FromResult(0)); }
protected override async Task ConfigureAsync() { AddDevice(new BuiltInI2CBus()); var pi2PortController = new Pi2PortController(); var ccToolsBoardController = new CCToolsBoardController(this, GetDevice <II2CBus>()); AddDevice(pi2PortController); AddDevice(ccToolsBoardController); ServiceLocator.RegisterService( typeof(OpenWeatherMapWeatherService), new OpenWeatherMapService(ApiController, ServiceLocator.GetService <IDateTimeService>(), ServiceLocator.GetService <ISchedulerService>(), ServiceLocator.GetService <ISystemInformationService>())); var configurationParser = new ConfigurationParser(this); configurationParser.RegisterConfigurationExtender(new DefaultConfigurationExtender(configurationParser, this)); configurationParser.RegisterConfigurationExtender(new CCToolsConfigurationExtender(configurationParser, this)); configurationParser.RegisterConfigurationExtender(new I2CHardwareBridgeConfigurationExtender(configurationParser, this)); configurationParser.ParseConfiguration(); InitializeAzureCloudApiEndpoint(); var ioBoardsInterruptMonitor = new InterruptMonitor(pi2PortController.GetInput(4)); ioBoardsInterruptMonitor.InterruptDetected += (s, e) => ccToolsBoardController.PollInputBoardStates(); ioBoardsInterruptMonitor.Start(); await base.ConfigureAsync(); }
protected override void Initialize() { InitializeHealthMonitor(LedGpio); var pi2PortController = new Pi2PortController(); var ccToolsBoardController = new CCToolsBoardController(this, GetDevice <II2CBus>()); AddDevice(new BuiltInI2CBus()); AddDevice(pi2PortController); AddDevice(ccToolsBoardController); RegisterService(new OpenWeatherMapWeatherService(Timer, ApiController)); var configurationParser = new ConfigurationParser(this); configurationParser.RegisterConfigurationExtender(new DefaultConfigurationExtender(configurationParser, this)); configurationParser.RegisterConfigurationExtender(new CCToolsConfigurationExtender(configurationParser, this)); configurationParser.RegisterConfigurationExtender(new I2CHardwareBridgeConfigurationExtender(configurationParser, this)); configurationParser.ParseConfiguration(); InitializeAzureCloudApiEndpoint(); var ioBoardsInterruptMonitor = new InterruptMonitor(pi2PortController.GetInput(4)); ioBoardsInterruptMonitor.InterruptDetected += (s, e) => ccToolsBoardController.PollInputBoardStates(); ioBoardsInterruptMonitor.StartPollingAsync(); }
protected override async Task ConfigureAsync() { AddDevice(new BuiltInI2CBus()); var ccToolsBoardController = new CCToolsBoardController(this, GetDevice <II2CBus>()); AddDevice(new Pi2PortController()); AddDevice(ccToolsBoardController); AddDevice(new I2CHardwareBridge(new I2CSlaveAddress(50), GetDevice <II2CBus>(), ServiceLocator.GetService <ISchedulerService>())); AddDevice(SetupRemoteSwitchController()); ServiceLocator.RegisterService(typeof(SynonymService), new SynonymService()); ServiceLocator.RegisterService(typeof(OpenWeatherMapService), new OpenWeatherMapService( ApiController, ServiceLocator.GetService <IDateTimeService>(), ServiceLocator.GetService <ISchedulerService>(), ServiceLocator.GetService <ISystemInformationService>())); SetupTelegramBot(); SetupTwitterClient(); ServiceLocator.GetService <SynonymService>().TryLoadPersistedSynonyms(); ccToolsBoardController.CreateHSPE16InputOnly(InstalledDevice.Input0, new I2CSlaveAddress(42)); ccToolsBoardController.CreateHSPE16InputOnly(InstalledDevice.Input1, new I2CSlaveAddress(43)); ccToolsBoardController.CreateHSPE16InputOnly(InstalledDevice.Input2, new I2CSlaveAddress(47)); ccToolsBoardController.CreateHSPE16InputOnly(InstalledDevice.Input3, new I2CSlaveAddress(45)); ccToolsBoardController.CreateHSPE16InputOnly(InstalledDevice.Input4, new I2CSlaveAddress(46)); ccToolsBoardController.CreateHSPE16InputOnly(InstalledDevice.Input5, new I2CSlaveAddress(44)); new BedroomConfiguration(this).Setup(); new OfficeConfiguration(this).Setup(); new UpperBathroomConfiguration(this).Setup(); new ReadingRoomConfiguration(this).Setup(); new ChildrensRoomRoomConfiguration(this).Setup(); new KitchenConfiguration(this).Setup(); new FloorConfiguration(this).Setup(); new LowerBathroomConfiguration(this).Setup(); new StoreroomConfiguration(this).Setup(); new LivingRoomConfiguration(this).Setup(); ServiceLocator.GetService <SynonymService>().RegisterDefaultComponentStateSynonyms(this); InitializeAzureCloudApiEndpoint(); var ioBoardsInterruptMonitor = new InterruptMonitor(GetDevice <Pi2PortController>().GetInput(4)); ioBoardsInterruptMonitor.InterruptDetected += (s, e) => ccToolsBoardController.PollInputBoardStates(); ioBoardsInterruptMonitor.Start(); await base.ConfigureAsync(); }
protected override void Initialize() { InitializeHealthMonitor(22); var pi2PortController = new Pi2PortController(); AddDevice(new BuiltInI2CBus(Logger)); AddDevice(new I2CHardwareBridge(new DeviceId("HB"), new I2CSlaveAddress(50), Device <II2CBus>(), Timer)); AddDevice(new OpenWeatherMapWeatherStation(OpenWeatherMapWeatherStation.DefaultDeviceId, Timer, HttpApiController, Logger)); var ccToolsBoardController = new CCToolsBoardController(this, Device <II2CBus>(), HttpApiController, Logger); var configurationParser = new ConfigurationParser(this); configurationParser.RegisterConfigurationExtender(new CCToolsConfigurationExtender(configurationParser, this)); configurationParser.ParseConfiguration(); ccToolsBoardController.CreateHSPE16InputOnly(Main.Device.Input0, new I2CSlaveAddress(42)); ccToolsBoardController.CreateHSPE16InputOnly(Main.Device.Input1, new I2CSlaveAddress(43)); ccToolsBoardController.CreateHSPE16InputOnly(Main.Device.Input2, new I2CSlaveAddress(47)); ccToolsBoardController.CreateHSPE16InputOnly(Main.Device.Input3, new I2CSlaveAddress(45)); ccToolsBoardController.CreateHSPE16InputOnly(Main.Device.Input4, new I2CSlaveAddress(46)); ccToolsBoardController.CreateHSPE16InputOnly(Main.Device.Input5, new I2CSlaveAddress(44)); RemoteSocketController remoteSwitchController = SetupRemoteSwitchController(); new BedroomConfiguration(this, ccToolsBoardController).Setup(); new OfficeConfiguration().Setup(this, ccToolsBoardController, remoteSwitchController); new UpperBathroomConfiguration(this, ccToolsBoardController).Setup(); new ReadingRoomConfiguration().Setup(this, ccToolsBoardController); new ChildrensRoomRoomConfiguration().Setup(this, ccToolsBoardController); new KitchenConfiguration().Setup(this, ccToolsBoardController); new FloorConfiguration().Setup(this, ccToolsBoardController); new LowerBathroomConfiguration().Setup(this); new StoreroomConfiguration().Setup(this, ccToolsBoardController); new LivingRoomConfiguration().Setup(this, ccToolsBoardController); //AttachAzureEventHubPublisher(home); var localCsvFileWriter = new CsvHistory(Logger, HttpApiController); localCsvFileWriter.ConnectActuators(this); localCsvFileWriter.ExposeToApi(HttpApiController); var ioBoardsInterruptMonitor = new InterruptMonitor(pi2PortController.GetInput(4), Logger); ioBoardsInterruptMonitor.InterruptDetected += (s, e) => ccToolsBoardController.PollInputBoardStates(); ioBoardsInterruptMonitor.StartPollingAsync(); }
public Task ApplyAsync() { _synonymService.TryLoadPersistedSynonyms(); _ccToolsBoardService.RegisterHSPE16InputOnly(InstalledDevice.Input0, new I2CSlaveAddress(42)); _ccToolsBoardService.RegisterHSPE16InputOnly(InstalledDevice.Input1, new I2CSlaveAddress(43)); _ccToolsBoardService.RegisterHSPE16InputOnly(InstalledDevice.Input2, new I2CSlaveAddress(47)); _ccToolsBoardService.RegisterHSPE16InputOnly(InstalledDevice.Input3, new I2CSlaveAddress(45)); _ccToolsBoardService.RegisterHSPE16InputOnly(InstalledDevice.Input4, new I2CSlaveAddress(46)); _ccToolsBoardService.RegisterHSPE16InputOnly(InstalledDevice.Input5, new I2CSlaveAddress(44)); var i2CHardwareBridge = new I2CHardwareBridge(new I2CSlaveAddress(50), _i2CBusService, _schedulerService); _deviceService.AddDevice(i2CHardwareBridge); _remoteSocketService.Sender = new LPD433MHzSignalSender(i2CHardwareBridge, LDP433MhzSenderPin, _apiService); var brennenstuhl = new BrennenstuhlCodeSequenceProvider(); _remoteSocketService.RegisterRemoteSocket(0, brennenstuhl.GetSequencePair(BrennenstuhlSystemCode.AllOn, BrennenstuhlUnitCode.A)); _containerService.GetInstance <BedroomConfiguration>().Apply(); _containerService.GetInstance <OfficeConfiguration>().Apply(); _containerService.GetInstance <UpperBathroomConfiguration>().Apply(); _containerService.GetInstance <ReadingRoomConfiguration>().Apply(); _containerService.GetInstance <ChildrensRoomRoomConfiguration>().Apply(); _containerService.GetInstance <KitchenConfiguration>().Apply(); _containerService.GetInstance <FloorConfiguration>().Apply(); _containerService.GetInstance <LowerBathroomConfiguration>().Apply(); _containerService.GetInstance <StoreroomConfiguration>().Apply(); _containerService.GetInstance <LivingRoomConfiguration>().Apply(); _synonymService.RegisterDefaultComponentStateSynonyms(); var ioBoardsInterruptMonitor = new InterruptMonitor(_pi2GpioService.GetInput(4)); ioBoardsInterruptMonitor.InterruptDetected += (s, e) => _ccToolsBoardService.PollInputBoardStates(); ioBoardsInterruptMonitor.Start(); return(Task.FromResult(0)); }
public static void Run() { string dataDir = RunExamples.GetDataDir_PNG(); //ExStart:SupportForInterruptMonitor ImageOptionsBase saveOptions = new PngOptions(); InterruptMonitor monitor = new InterruptMonitor(); string source = Path.Combine(dataDir, "big2.psb"); string output = Path.Combine(dataDir, "big_out.png"); SaveImageWorker worker = new SaveImageWorker(source, output, saveOptions, monitor); Thread thread = new Thread(new ThreadStart(worker.ThreadProc)); try { thread.Start(); // The timeout should be less than the time required for full image conversion (without interruption). Thread.Sleep(3000); // Interrupt the process monitor.Interrupt(); Console.WriteLine("Interrupting the save thread #{0} at {1}", thread.ManagedThreadId, System.DateTime.Now); // Wait for interruption... thread.Join(); } finally { // Delete the output file. if (File.Exists(output)) { File.Delete(output); } } //ExEnd:SupportForInterruptMonitor }
public Task ApplyAsync() { _ccToolsBoardService.RegisterHSPE16InputOnly(InstalledDevice.Input0.ToString(), new I2CSlaveAddress(42)); _ccToolsBoardService.RegisterHSPE16InputOnly(InstalledDevice.Input1.ToString(), new I2CSlaveAddress(43)); _ccToolsBoardService.RegisterHSPE16InputOnly(InstalledDevice.Input2.ToString(), new I2CSlaveAddress(47)); _ccToolsBoardService.RegisterHSPE16InputOnly(InstalledDevice.Input3.ToString(), new I2CSlaveAddress(45)); _ccToolsBoardService.RegisterHSPE16InputOnly(InstalledDevice.Input4.ToString(), new I2CSlaveAddress(46)); _ccToolsBoardService.RegisterHSPE16InputOnly(InstalledDevice.Input5.ToString(), new I2CSlaveAddress(44)); var i2CHardwareBridge = new I2CHardwareBridge(new I2CSlaveAddress(50), _i2CBusService, _schedulerService); _deviceService.AddDevice(i2CHardwareBridge); _remoteSocketService.Adapter = new I2CHardwareBridgeLdp433MhzBridgeAdapter(i2CHardwareBridge, 10); var codeSequenceProvider = new DipswitchCodeProvider(); _remoteSocketService.RegisterRemoteSocket("OFFICE_0", codeSequenceProvider.GetCodePair(DipswitchSystemCode.AllOn, DipswitchUnitCode.A)); _containerService.GetInstance <BedroomConfiguration>().Apply(); _containerService.GetInstance <OfficeConfiguration>().Apply(); _containerService.GetInstance <UpperBathroomConfiguration>().Apply(); _containerService.GetInstance <ReadingRoomConfiguration>().Apply(); _containerService.GetInstance <ChildrensRoomRoomConfiguration>().Apply(); _containerService.GetInstance <KitchenConfiguration>().Apply(); _containerService.GetInstance <FloorConfiguration>().Apply(); _containerService.GetInstance <LowerBathroomConfiguration>().Apply(); _containerService.GetInstance <StoreroomConfiguration>().Apply(); _containerService.GetInstance <LivingRoomConfiguration>().Apply(); var ioBoardsInterruptMonitor = new InterruptMonitor(_pi2GpioService.GetInput(4), _logService); ioBoardsInterruptMonitor.AddCallback(_ccToolsBoardService.PollInputBoardStates); ioBoardsInterruptMonitor.Start(); return(Task.FromResult(0)); }