Esempio n. 1
0
        public void Setup(int frequency)
        {
            var config = __PCA9685_MODE1_RESTART_DISABLED
                         | __PCA9685_MODE1_EXTCLK_DISABLED
                         | __PCA9685_MODE1_AI_DISABLED
                         | __PCA9685_MODE1_SLEEP_DISABLED
                         | __PCA9685_MODE1_SUB1_DISABLED
                         | __PCA9685_MODE1_SUB1_DISABLED
                         | __PCA9685_MODE1_SUB3_DISABLED
                         | __PCA9685_MODE1_ALLCALL_DISABLED // [BEM] disable now, enable later
            ;

            device.WriteAddressByte(__PCA9685_REG_MODE1, (byte)config);

            config = __PCA9685_MODE2_INVRT_DISABLED
                     | __PCA9685_MODE2_OCH_STOP
                     | __PCA9685_MODE2_OUTDRV_OPENDRAIN
                     | __PCA9685_MODE2_OUTDRV_TOTEMPOLE
                     | __PCA9685_MODE2_OUTNE_0
            ;

            device.WriteAddressByte(__PCA9685_REG_MODE2, (byte)config);

            SetAllPwm(0, 0);
            SetPwmClock(frequency);
        }
Esempio n. 2
0
        public bool Lunch()
        {
            try
            {
                //检查依赖
                if (!EquipmentBus.ControllerRegister.CheckRely(RelyEquipment))
                {
                    throw new Exception($"依赖设备尚未启动{string.Join("、", RelyEquipment)}");
                }

                I2CDevice = I2CDriver.I2CBus.AddDevice(Addr);
                I2CDevice.WriteAddressByte(MODE1, 0x00);
                SetPWMFreq(Freq);
                EquipmentData.IsEnable = true;
                EquipmentBus.ControllerRegister.Register(RegisterType.Pca9685, false);
            }
            catch (Exception ex)
            {
                EquipmentData.AddError(LogType.Error, $"启动地址为{Addr},频率为{Freq}的PCA9685失败!", ex);
                Logger.Add(LogType.Error, $"启动地址为{Addr},频率为{Freq}的PCA9685失败!", ex);
                EquipmentData.IsEnable = false;
                return(false);
            }
            return(true);
        }
Esempio n. 3
0
 public static void Write(II2CDevice device, byte reg, byte command, string exceptionMessage)
 {
     try
     {
         device.WriteAddressByte(reg, command);
     }
     catch (Exception exception)
     {
         throw new SensorException(exceptionMessage, exception);
     }
 }
Esempio n. 4
0
        public void Setup()
        {
            var config = __PCA9685_MODE1_RESTART_DISABLED
                         | __PCA9685_MODE1_EXTCLK_DISABLED
                         | __PCA9685_MODE1_AI_DISABLED
                         | __PCA9685_MODE1_SLEEP_DISABLED
                         | __PCA9685_MODE1_SUB1_DISABLED
                         | __PCA9685_MODE1_SUB1_DISABLED
                         | __PCA9685_MODE1_SUB3_DISABLED
                         | __PCA9685_MODE1_ALLCALL_DISABLED
            ;

            device.WriteAddressByte(__PCA9685_REG_MODE1, (byte)config);

            config = __PCA9685_MODE2_INVRT_DISABLED
                     | __PCA9685_MODE2_OCH_STOP
                     | __PCA9685_MODE2_OUTDRV_TOTEMPOLE
                     | __PCA9685_MODE2_OUTNE_0
            ;

            device.WriteAddressByte(__PCA9685_REG_MODE2, (byte)config);

            SetAllPwm(0, 0);
        }
Esempio n. 5
0
 //Method to write 0x03 to the humidity control register
 private void WriteControlRegisterHumidity()
 {
     bme280.WriteAddressByte((byte)eRegisters.BME280_REGISTER_CONTROLHUMID, 0x03);
     Thread.Sleep(1);
     return;
 }