-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
190 lines (125 loc) · 4.37 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
'use strict';
var libQ = require('kew');
var fs = require('fs-extra');
var config = new(require('v-conf'))();
var exec = require('child_process').exec;
var execSync = require('child_process').execSync;
var io = require('socket.io-client');
var lcdDisplay = require('./lcdDisplay');
module.exports = ControllerlcdHD47780;
function Controllerlcdhd47780(context) {
// This fixed variable will let us refer to 'this' object at deeper scopes
var self = this;
this.context = context;
this.commandRouter = this.context.coreCommand;
this.logger = this.context.logger;
this.configManager = this.context.configManager;
}
Controllerlcdhd47780.prototype.onVolumioStart = function() {
var self = this;
var configFile=this.commandRouter.pluginManager.getConfigurationFile(this.context,'config.json');
this.config = new (require('v-conf'))();
this.config.loadFile(configFile);
self.logger.info('[lcdHD47780] Plugin initialized');
return libQ.resolve();
};
Controllerlcdhd47780.prototype.onStart = function() {
var self = this;
var defer = libQ.defer();
try {
self.lcdDisplay = new lcdDisplay(self.context,self.config);
self.socket = io.connect('http://localhost:3000');
self.socket.on('pushState', this.updateLcd.bind(this));
self.logger.info('[lcdHD47780] Plugin started');
// Once the Plugin has successfull started resolve the promise
defer.resolve();
} catch(err) {
self.logger.error('[lcdHD47780] Plugin startup failed: ' + err);
defer.reject(err);
}
return defer.promise;
};
Controllerlcdhd47780.prototype.onStop = function() {
var self = this;
var defer = libQ.defer();
try {
self.lcdDisplay.close();
// TODO: Close socket
self.logger.info("[lcdHD47780] Plugin stopped");
// Once the Plugin has successfull stopped resolve the promise
defer.resolve();
} catch(err) {
self.logger.error('[lcdHD47780] Plugin stop failed: ' + err);
defer.reject(err);
}
return libQ.resolve();
};
Controllerlcdhd47780.prototype.onRestart = function() {
var self = this;
try {
self.logger.info('[lcdHD47780] Plugin restarting...');
self.lcdDisplay.close();
// TODO: Close socket
self.lcdDisplay = new lcdDisplay(self.context,self.config);
// TODO: Setup new socket
self.logger.info('[lcdHD47780] Plugin started');
} catch(err) {
self.logger.error('[lcdHD47780] Restart failed: ' + err);
}
};
Controllerlcdhd47780.prototype.updateLcd = function(state) {
var self = this;
self.logger.info('[lcdHD47780] Push State recieved:');
self.logger.info(state);
self.lcdDisplay.pushState(state);
self.logger.info('[lcdHD47780] Push State Completed');
};
// Configuration Methods -----------------------------------------------------------------------------
Controllerlcdhd47780.prototype.getConfigurationFiles = function()
{
return ['config.json'];
}
Controllerlcdhd47780.prototype.getUIConfig = function() {
var defer = libQ.defer();
var self = this;
var lang_code = this.commandRouter.sharedVars.get('language_code');
self.commandRouter.i18nJson(__dirname+'/i18n/strings_'+lang_code+'.json',
__dirname+'/i18n/strings_en.json',
__dirname + '/UIConfig.json')
.then(function(uiconf) {
uiconf.sections[0].content[0].value = self.config.get('RS');
uiconf.sections[0].content[1].value = self.config.get('E');
uiconf.sections[0].content[2].value = self.config.get('D4');
uiconf.sections[0].content[3].value = self.config.get('D5');
uiconf.sections[0].content[4].value = self.config.get('D6');
uiconf.sections[0].content[5].value = self.config.get('D7');
defer.resolve(uiconf);
})
.fail(function() {
defer.reject(new Error());
});
return defer.promise;
};
Controllerlcdhd47780.prototype.setUIConfig = function(data) {
var self = this;
//Perform your installation tasks here
};
Controllerlcdhd47780.prototype.getConf = function(varName) {
var self = this;
//Perform your installation tasks here
};
Controllerlcdhd47780.prototype.setConf = function(varName, varValue) {
var self = this;
//Perform your installation tasks here
};
Controllerlcdhd47780.prototype.saveGPIOConfig = function(data) {
var self = this;
self.config.set('RS',data.RS);
self.config.set('E',data.E);
self.config.set('D4',data.D4);
self.config.set('D5',data.D5);
self.config.set('D6',data.D6);
self.config.set('D7',data.D7);
self.onRestart();
self.commandRouter.pushToastMessage('success',"Save","GPIO Settings saved");
};