homebridge-i2c-pca9685
Version:
Raspberry Pi I2C controlled PWM control for LED Strips
114 lines (90 loc) • 3.02 kB
JavaScript
var i2c = require('raspi-i2c');
var Service, Characteristic;
//definition of PCA9685 related values
const DeviceAdress = 0x40;
const PWMResolution = 0x1000;
const PWMFrequency = 60;
const PowerUpAllCallAddress = 0xE0;
const PowerUpSubCall1Address = 0xE2;
const PowerUpSubCall2Address = 0xE4;
const PowerUpSubCall3Address = 0xE8;
const SoftwareResetAddress = 0x06;
const Mode1Register = 0x00;
const Mode2Register = 0x01;
const SubAddress1 = 0x02;
const SubAddress2 = 0x03;
const SubAddress3 = 0x04;
const AllCallAddress = 0x05;
const AllLEDOnLowAddress = 0xFA;
const AllLEDOnHighAddress = 0xFB;
const AllLEDOffLowAddress = 0xFC;
const AllLEDOffHighAddress = 0xFD;
const LED1OnLowAddress = 0x0A;
const LED1OnHighAddress = 0x0B;
const LED1OffLowAddress = 0x0C;
const LED1OffHighAddress = 0x0D;
const LED2OnLowAddress = 0x0E;
const LED2OnHighAddress = 0x0F;
const LED2OffLowAddress = 0x10;
const LED2OffHighAddress = 0x11;
const LED5OnLowAddress = 0x1A;
const LED5OnHighAddress = 0x1B;
const LED5OffLowAddress = 0x1C;
const LED5OffHighAddress = 0x1D;
const LED6OnLowAddress = 0x1E;
const LED6OnHighAddress = 0x1F;
const LED6OffLowAddress = 0x20;
const LED6OffHighAddress = 0x21;
const LED8OnLowAddress = 0x26;
const LED8OnHighAddress = 0x27;
const LED8OffLowAddress = 0x28;
const LED8OffHighAddress = 0x29;
const LED9OnLowAddress = 0x2A;
const LED9OnHighAddress = 0x2B;
const LED9OffLowAddress = 0x2C;
const LED9OffHighAddress = 0x2D;
const LED12OnLowAddress = 0x36;
const LED12OnHighAddress = 0x37;
const LED12OffLowAddress = 0x38;
const LED12OffHighAddress = 0x39;
const LED13OnLowAddress = 0x3A;
const LED13OnHighAddress = 0x3B;
const LED13OffLowAddress = 0x3C;
const LED13OffHighAddress = 0x3D;
module.exports = function(homebridge) {
Service = homebridge.hap.Service;
Characteristic = homebridge.hap.Characteristic;
homebridge.registerAccessory('homebridge-i2c-pca9685', 'TVBacklight', TVLightAccessory);
}
function TVLightAccessory(log, config) {
this.log = log;
this.name = config['name'];
this.channel = config['channel'];
this.service = 'Lightbulb';
//this.service = new Service.Lightbulb(this.name);
}
TVLightAccessory.prototype.getServices = function() {
var informationService = new Service.AccessoryInformation();
var lightbulbService = new Service.Lightbulb(this.name);
informationService
.setCharacteristic(Characteristic.Manufacturer, 'KnooT')
.setCharacteristic(Characteristic.Model, 'I2C PWM Controller')
.setCharacteristic(Characteristic.SerialNumber, 'ABCD1234');
lightbulbService
.getCharacteristic(Characteristic.On)
.on('set', this.setOn.bind(this));
lightbulbService
.addCharacteristic(Characteristic.Brightness)
.on('set', this.setBrightness.bind(this));
return [lightbulbService];
}
TVLightAccessory.prototype.getOn(callback) {
//read register via i2c
console.log("GetOn");
}
TVLightAccessory.prototype.setOn(number, callback) {
console.log("SetOn");
}
TVLightAccessory.prototype.setBrightness(value, callback) {
console.log("Brightness");
}