Beispiel #1
0
 public Task StopAsync(CancellationToken cancellationToken)
 {
     _logger.LogInformation("Stopping GPIO switch daemon.");
     _timer?.Change(Timeout.Infinite, Timeout.Infinite);
     _switchService?.Dispose();
     _switchService = null;
     return(Task.CompletedTask);
 }
Beispiel #2
0
        public Task StartAsync(CancellationToken cancellationToken)
        {
            _pin = _config.Value?.Pin ?? 0;
            _logger.LogInformation("Starting GPIO switch daemon; PIN: {pin}", _pin);
            _switchOnHour  = _config.Value?.SwitchOnHour ?? 9;
            _switchOffHour = _config.Value?.SwitchOffHour ?? 23;
            if (_switchOnHour > _switchOffHour)
            {
                _logger.LogWarning("Wrong switch hours order: swapping");
                var tmp = _switchOffHour;
                _switchOffHour = _switchOnHour;
                _switchOnHour  = tmp;
            }
            _logger.LogInformation("Starting GPIO switch daemon; SwitchOn: {_switchOnHour}; SwitchOff: {_switchOffHour}", _switchOnHour, _switchOffHour);

            _switchService = new SwitchPinService(_pin, _logger);

            _timer = new Timer(new TimerCallback(ServiceTick), _pin, FIVE_SEC, FIVE_SEC);

            return(Task.CompletedTask);
        }