Ejemplo n.º 1
0
        public LightController(string n, StepperMotorDevice fence, OnOffDevice light) : base(n, new PhysicalDevice[] { fence, light })
        {
            _blindingFence = fence;
            _lightBulb     = light;

            _lightBulb.Off();
            Task.Delay(20);
            _blindingFence.PosizionaFineCorsaAntiOrario();
            Task.Delay(20);
            _stepTotali             = _blindingFence.CalculateStepNumberAndGoToEnd();
            _posizioneAttualeInStep = 0;
            _percentuale            = 0;
            _blindingFence.Folle();
            InvokeWriteLog("Device setted up");
        }
Ejemplo n.º 2
0
        public MainPage()
        {
            this.InitializeComponent();

            _physicalFL = new FileLogger(PHYSICAL_LOG_FILE_NAME);
            _masterFL   = new FileLogger(MASTER_LOG_FILE_NAME);

            _converter = new MCP3208ADC(SERIAL_NUMBER);

            _shiftR = new ShiftRegister(SHIFT_REGISTER_BUS_LENGHT, DATA_SHIFT_REGISTER_PIN, CLOCK_SHIFT_REGISTER_PIN, LATCH_SHIFT_REGISTER_PIN);
            _lcd    = new LCD(_shiftR, LCD_BIT0_PIN, LCD_BIT1_PIN, LCD_BIT2_PIN, LCD_BIT3_PIN, LCD_ENABLE_PIN, LCD_REGISTER_SELECT_PIN);

            _sensori = new SensoreAnalogico[]
            {
                new SensoreLuminosita(_converter, LUM_SHIFT_NUMBER),
                new SensoreCO2(_converter, CO2_SHIFT_NUMBER),
                new SensoreUmiditaAria(_converter, UA_SHIFT_NUMBER),
                new SensoreUmiditaTerreno(_converter, UT_SHIFT_NUMBER),
                new SensoreTemperatura(_converter, TEMP_SHIFT_NUMBER)
            };

            _printStatus.Interval = TimeSpan.FromMilliseconds(CHANGE_STATUS_MILLISECONDS_TIMER);
            _printStatus.Tick    += PrintStatus_Tick;
            _printStatus.Start();

            _lightFence                = new StepperMotorDevice("Blinding Fence", _shiftR, A1_STEPPER_PIN, A2_STEPPER_PIN, B1_STEPPER_PIN, B2_STEPPER_PIN, STOP_ORARIO_PIN, STOP_ANTIORARIO_PIN);
            _lightFence.WriteLog      += WritePhysicalLogAsync;
            _lightBulb                 = new OnOffDevice("Agro Light Bulb", _shiftR, LIGHT_BULB_PIN);
            _lightBulb.WriteLog       += WritePhysicalLogAsync;
            _lightController           = new LightController("Light Controller", _lightFence, _lightBulb);
            _lightController.WriteLog += WriteMasterLogAsync;

            _heatResistor           = new PwmDevice("Heat Resistor", HEAT_RES_PIN);
            _heatResistor.WriteLog += WritePhysicalLogAsync;

            _airCicleFan           = new PwmDevice("Air Circle Fan", AIR_CIRLE_FAN_PIN);
            _airCicleFan.WriteLog += WritePhysicalLogAsync;

            _airCicleFan.ChangeDutyCycle(50);
            _airCicleFan.Start();
            _heatResistor.ChangeDutyCycle(50);
            _heatResistor.Start();
            Task.Delay(1000).Wait();
            _airCicleFan.Stop();
            _heatResistor.Stop();

            txtStatus.Text = "Running...";
        }