Skip to content

Commit

Permalink
Added repeat and fixed GUI config
Browse files Browse the repository at this point in the history
  • Loading branch information
rnilssoncx committed Jan 22, 2022
1 parent dc83a86 commit f53b5c2
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 9 deletions.
7 changes: 6 additions & 1 deletion accessory.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,20 @@ class PicoRemote {
if (!Array.isArray(this.repeat)) {
this.repeat = [this.repeat]
}
this.repeatmax = sw.repeatmax || 10;
this.version = version;
this.longname = longname;
this.buttons = {};
}

repeatTime(button) {
repeatButton(button) {
return this.repeat.includes(parseInt(button))
}

repeatMax() {
return this.repeatmax;
}

getServices() {
let services = [];
let index = 1;
Expand Down
55 changes: 55 additions & 0 deletions config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@
"title": "PJ2-4B-XXX-L41",
"enum": ["PJ2-4B-XXX-L41"]
},
{
"title": "Simple (Two Button)",
"enum": ["simple"]
},
{
"title": "Dimmer (No favorite button)",
"enum": ["dimmer"]
},
{
"title": "Dimmer (Favorite button)",
"enum": ["favorite"]
},
{
"title": "custom",
"enum": ["custom"]
Expand All @@ -109,6 +121,21 @@
"required": true
}
},
"repeat": {
"type": "array",
"required": false,
"items": {
"title": "Button",
"type": "integer",
"required": true
}
},
"repeatmax": {
"title": "Maximum repeats",
"type": "integer",
"required": false,
"default": 10
},
"pico": {
"type": "array",
"required": true,
Expand All @@ -129,6 +156,34 @@
"type": "boolean",
"required": false,
"default": false
},
"clicktime": {
"title": "Double click detection time",
"type": "integer",
"required": false,
"default": 500
},
"slowextra": {
"title": "Additional time for slower pico buttons",
"type": "integer",
"required": false,
"default": 250
},
"repeattime": {
"title": "Delay between repeated long presses",
"type": "integer",
"required": false,
"default": 500
},
"slowbuttons": {
"type": "array",
"required": false,
"items": {
"title": "Button",
"type": "integer",
"required": true
},
"default": [5,6]
}
}
}
Expand Down
18 changes: 11 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ class Pico {
clickTime += this.slowExtra
}
this.clickProcessor[eventKey] = new Click(event, clickTime, this.repeatTime, this.log,
this.servers[event.host][event.device].repeatTime(event.button), this.clickHandler.bind(this));
this.servers[event.host][event.device].repeatButton(event.button),
this.servers[event.host][event.device].repeatMax(), this.clickHandler.bind(this));
} else {
this.clickProcessor[eventKey].click(event);
}
Expand All @@ -90,16 +91,17 @@ class Pico {
}

class Click {
constructor(event, doubleClickTime, repeatTime, log, repeat, callback) {
constructor(event, doubleClickTime, repeatTime, log, repeat, repeatMax, callback) {
this.host = event.host
this.device = event.device
this.button = event.button
this.doubleClickTime = doubleClickTime
this.repeatTime = repeatTime
this.repeatMax = repeatMax
this.log = log
this.repeat = repeat
this.callback = callback
this.repeating = false
this.repeatCount = 0
this.log(`[${this.host}] Device ${this.device} Button ${this.button} Repeat ${this.repeat} Click ${doubleClickTime} - Created tracker`)
this.click(event)
}
Expand Down Expand Up @@ -141,16 +143,18 @@ class Click {
} else if (this.ups == 0) {
event.click = 2
if (this.repeat) {
this.repeating = true
this._setTimer(this.repeatTime)
if (this.repeatCount++ < this.repeatMax)
this._setTimer(this.repeatTime)
else
this.repeatCount = 0;
}
} else {
event.click = 0
}
if (!this.repeating || (this.repeating && event.click == 2)) {
if (this.repeatcount == 0 || (this.repeatCount > 0 && event.click == 2)) {
this.callback(event)
} else {
this.repeating = false
this.repeatCount = 0
}
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "homebridge-pico",
"version": "1.2.0",
"version": "1.2.1",
"description": "A HomeBridge plugin to expose Lutron Pico Remotes",
"funding": {
"type": "paypal",
Expand Down

0 comments on commit f53b5c2

Please sign in to comment.