Skip to content

Commit e3157b8

Browse files
committed
Added color to winston.
pwm now changed period before duty_cycle. pwm no longer disables when changing period
1 parent e57aea0 commit e3157b8

1 file changed

Lines changed: 16 additions & 9 deletions

File tree

src/hw_mainline.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
var fs = require('fs');
2-
var winston = require('winston');
32
var my = require('./my');
43
var parse = require('./parse');
54
var eeprom = require('./eeprom');
65

76
var debug = process.env.DEBUG ? true : false;
7+
if(debug) {
8+
var util = require('util');
9+
var winston = require('winston');
10+
winston.remove(winston.transports.Console);
11+
winston.add(winston.transports.Console, {colorize: true});
12+
}
813

914
var gpioFile = {};
1015
var pwmPrefix = {};
@@ -228,26 +233,28 @@ exports.writeGPIOEdge = function(pin, mode) {
228233
};
229234

230235
exports.writePWMFreqAndValue = function(pin, pwm, freq, value, resp, callback) {
231-
if(debug) winston.debug('hw.writePWMFreqAndValue(' + [pin.key,pwm,freq,value,resp] + ');');
236+
if(debug) winston.debug('hw.writePWMFreqAndValue(' + [pin.key,util.inspect(pwm),freq,value,resp] + ');');
232237
var path = pwmPrefix[pin.pwm.name];
233238
try {
234239
var period = Math.round( 1.0e9 / freq ); // period in ns
240+
if(debug) winston.debug('hw.writePWMFreqAndValue: pwm.freq='+pwm.freq
241+
+', freq='+freq+', period='+period);
235242
if(pwm.freq != freq) {
236-
if(debug) winston.debug('Stopping PWM');
237-
fs.writeFileSync(path+'/enable', "0\n");
238-
if(debug) winston.debug('Setting duty_cycle to 0');
239-
fs.writeFileSync(path+'/duty_cycle', "0\n");
243+
// if(debug) winston.debug('Stopping PWM');
244+
// fs.writeFileSync(path+'/enable', "0\n");
245+
// It appears that the first time you set the pwm you have to
246+
// set the period before you set the duty_cycle
240247
try {
241248
if(debug) winston.debug('Updating PWM period: ' + period);
242249
fs.writeFileSync(path+'/period', period + "\n");
243250
} catch(ex2) {
244251
period = fs.readFileSync(path+'/period');
245252
winston.info('Unable to update PWM period, period is set to '
246253
+ period
247-
+ "\nIs other half of PWM enabled?");
254+
+ "\tIs other half of PWM enabled?");
248255
}
249-
if(debug) winston.debug('Starting PWM');
250-
fs.writeFileSync(path+'/enable', "1\n");
256+
// if(debug) winston.debug('Starting PWM');
257+
// fs.writeFileSync(path+'/enable', "1\n");
251258
}
252259
var duty = Math.round( period * value );
253260
if(debug) winston.debug('Updating PWM duty: ' + duty);

0 commit comments

Comments
 (0)