Skip to content

Commit 1dc73a0

Browse files
authored
Update node_helper.js
1 parent e6e2110 commit 1dc73a0

File tree

1 file changed

+19
-72
lines changed

1 file changed

+19
-72
lines changed

node_helper.js

Lines changed: 19 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,15 @@ const Gpio = require('onoff').Gpio;
1313
const moment = require('moment');//needed for time
1414
var NodeHelper = require("node_helper");
1515
//Variables
16-
seq_contacts = '';
17-
seq_value = '';
1816
action = '';
19-
last_time = '';
2017
helfer = '';
2118
value_a = '';
2219
value_b = '';
23-
value_c = '';
2420

2521
module.exports = NodeHelper.create({
2622
// Subclass start method.
27-
start: function() {
28-
var self = this;
29-
//console.log("Starting node helper for: " + self.name);
30-
//this.intializeButtons();
23+
start: function() {
24+
var self = this;
3125
this.loaded = false;
3226
},
3327

@@ -44,102 +38,55 @@ module.exports = NodeHelper.create({
4438
if (err) {
4539
throw err;
4640
}
47-
//console.log('A triggered: ' + value)
4841
value_a = value;
4942
if(value_b != ''){
5043
helfer = f3('B');
5144
}
5245
});
5346

54-
B.watch(function (err, value) {
47+
B.watch(function (err, value) {
5548
if (err) {
5649
throw err;
5750
}
58-
//console.log('B triggered: ' + value)
5951
value_b = value;
6052
if(value_a != ''){
6153
helfer = f3('A');
6254
}
6355
});
6456

65-
C.watch(function (err, value) {
57+
C.watch(function (err, value) {
6658
if (err) {
6759
throw err;
6860
}
69-
//console.log('C triggered: ' + value)
70-
helfer = f2('C',value);
71-
});
72-
73-
function f2(contact, value){
74-
seq_contacts = seq_contacts + contact;
75-
seq_value = seq_value + value;
76-
if(last_time==''){//set if not already set
77-
last_time = moment();
78-
}
79-
var b = moment();
80-
var vdiff = b.diff(last_time,'millisecond');
81-
82-
//for A & B ist timediff needed, for C not really
83-
if(seq_contacts.indexOf('C')!=-1){//only react on C0 which is C-Button Press (not C-Button UP)
84-
if(vdiff>10){
85-
//action = frichtung('C0');
86-
action = 'PRESSED';
87-
//console.log('Zeitdifferenz:',b.diff(last_time,'millisecond'));
88-
//console.log('seq_contacts/value:', seq_contacts+seq_value);
89-
//console.log('action: ',action);
90-
sleep_ms(250);
91-
//reset variables
92-
last_time = '';
93-
seq_contacts = '';
94-
seq_value = '';
95-
96-
}else if(vdiff>40){
97-
//console.log('Zeitdifferenz:',b.diff(last_time,'millisecond'));
98-
//console.log('seq_contacts/value:', seq_contacts+seq_value);
99-
//reset variables
100-
last_time = '';
101-
seq_contacts = '';
102-
seq_value = '';
103-
}
104-
}
105-
106-
if(action=='PRESSED'){
107-
self.sendSocketNotification('PRESSED',{inputtype: 'PRESSED'});
108-
action = '';
109-
return;
61+
if(value == 0){
62+
helfer = f3('C');
11063
}
111-
action = '';
112-
return;
113-
}
64+
});
11465

115-
function f3(contact){
66+
function f3(contact){
11667
if(contact == 'A'){
11768
action = 'CW';
11869
}else if(contact == 'B'){
11970
action = 'CCW';
71+
}else if(contact == 'C'){
72+
action = 'PRESSED';
12073
}
12174

12275
//reset variables
12376
contact = '';
12477
value_a = '';
12578
value_b = '';
12679

127-
if(action=='CW'){
128-
self.sendSocketNotification('CW',{inputtype: 'CW'});
129-
action = '';
130-
return;
131-
}else if(action=='CCW'){
132-
self.sendSocketNotification('CCW',{inputtype: 'CCW'});
133-
action = '';
134-
return;
80+
if(action=='CW' || action=='CCW' || action=='PRESSED'){
81+
self.sendSocketNotification(action,{inputtype: ""+action+""});
13582
}
136-
}
83+
}
13784

138-
// Milliseconds
139-
function sleep_ms(millisecs) {
140-
var initiation = new Date().getTime();
141-
while ((new Date().getTime() - initiation) < millisecs);
142-
}
85+
// Milliseconds
86+
function sleep_ms(millisecs) {
87+
var initiation = new Date().getTime();
88+
while ((new Date().getTime() - initiation) < millisecs);
89+
}
14390
},
14491

14592
// Override socketNotificationReceived method.
@@ -151,7 +98,7 @@ module.exports = NodeHelper.create({
15198
}else if (notification === 'BUTTON_CONFIG') {
15299
this.config = payload.config;
153100
this.intializeButtons();
154-
};
101+
}
155102
},
156103

157104
});

0 commit comments

Comments
 (0)