|
1 | 1 | var fs = require('fs'); |
2 | | -var winston = require('winston'); |
3 | 2 | var my = require('./my'); |
4 | 3 | var parse = require('./parse'); |
5 | 4 | var eeprom = require('./eeprom'); |
6 | 5 |
|
7 | 6 | 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 | +} |
8 | 13 |
|
9 | 14 | var gpioFile = {}; |
10 | 15 | var pwmPrefix = {}; |
@@ -228,26 +233,28 @@ exports.writeGPIOEdge = function(pin, mode) { |
228 | 233 | }; |
229 | 234 |
|
230 | 235 | 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] + ');'); |
232 | 237 | var path = pwmPrefix[pin.pwm.name]; |
233 | 238 | try { |
234 | 239 | 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); |
235 | 242 | 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 |
240 | 247 | try { |
241 | 248 | if(debug) winston.debug('Updating PWM period: ' + period); |
242 | 249 | fs.writeFileSync(path+'/period', period + "\n"); |
243 | 250 | } catch(ex2) { |
244 | 251 | period = fs.readFileSync(path+'/period'); |
245 | 252 | winston.info('Unable to update PWM period, period is set to ' |
246 | 253 | + period |
247 | | - + "\nIs other half of PWM enabled?"); |
| 254 | + + "\tIs other half of PWM enabled?"); |
248 | 255 | } |
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"); |
251 | 258 | } |
252 | 259 | var duty = Math.round( period * value ); |
253 | 260 | if(debug) winston.debug('Updating PWM duty: ' + duty); |
|
0 commit comments