Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support SetWaveform for flashing, pulsing and other effects #21

Open
MariusRumpf opened this issue Oct 28, 2015 · 10 comments
Open

Support SetWaveform for flashing, pulsing and other effects #21

MariusRumpf opened this issue Oct 28, 2015 · 10 comments

Comments

@MariusRumpf
Copy link
Owner

This could be utilized to create effects like breath, pulsing and other.

@MariusRumpf MariusRumpf added this to the 0.4.0 milestone Dec 21, 2015
@MariusRumpf
Copy link
Owner Author

MariusRumpf commented Dec 21, 2015

Release 0.4.0 does contain the setWaveform packet, which can be created using the packet directly.

var Lifx = require('./lib/lifx').Client;
var packet = require('./lib/lifx').packet;
var constants = require('./lib/lifx').constants;

var client = new Lifx();

var packetObj = packet.create('setWaveform', {
  isTransient: true,
  color: {hue: 0, saturation: 65535 , brightness: 65535, kelvin: 3500},
  period: 1,
  cycles: 5,
  skewRatio: 1,
  // SAW, SINE, HALF_SINE, TRIANGLE, PULSE
  waveform: constants.LIGHT_WAVEFORMS.indexOf('SAW')
}, client.source);
packetObj.target = 'F37A4311B857'; // light id

client.init();

client.send(packetObj, callback);

There is no direct integration yet since this packet has lots of parameters and would be complex to abstract. It might make sense to utilize this in another module like node-lifx-effects, another idea might be to document this better in a wiki or new readme file.

@MariusRumpf MariusRumpf removed this from the 0.4.0 milestone Dec 21, 2015
@devbobo
Copy link
Contributor

devbobo commented Jan 26, 2016

I'm trying to get this to work...

The first error I got was...

/Users/david/Development/NodeJS/node-lifx/lib/lifx/packets/setWaveform.js:144
    throw new TypeError('obj.waveform value must be given for setWaveform LIFX
          ^
TypeError: obj.waveform value must be given for setWaveform LIFX packet
    at Object.Packet.toBuffer (/Users/david/Development/NodeJS/node-lifx/lib/lifx/packets/setWaveform.js:144:11)
    at Object.Packet.toBuffer (/Users/david/Development/NodeJS/node-lifx/lib/lifx/packet.js:271:48)
    at Client.send (/Users/david/Development/NodeJS/node-lifx/lib/lifx/client.js:421:24)
    at Object.<anonymous> (/Users/david/Development/NodeJS/node-lifx/cli2.js:16:8)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:501:10)
    at startup (node.js:129:16)

That was easy enough to fix...
waveform: constants.LIGHT_WAVEFORMS[1]

I'm know getting this error....

dgram.js:286
    throw new RangeError('Port should be > 0 and < 65536');
          ^
RangeError: Port should be > 0 and < 65536
    at Socket.send (dgram.js:286:11)
    at Client.sendingProcess (/Users/david/Development/NodeJS/node-lifx/lib/lifx/client.js:183:19)
    at wrapper [as _onTimeout] (timers.js:265:14)
    at Timer.listOnTimeout (timers.js:110:15)

I haven't done any digging yet...but any ideas ?

Thanks,

David

@devbobo
Copy link
Contributor

devbobo commented Jan 27, 2016

Any chance you could add a setWaveform function to Light ?

@ristomatti
Copy link
Collaborator

@devbobo I get the same RangeError: Port should be > 0 and < 65536 error if try to run two instances of my script that uses node-lifx as the port 56700 is already in use. Were you trying to do that by any chance?

@MariusRumpf
Copy link
Owner Author

I have not tested it, it is more of a brainstorming how to do it (in the light.js file for the library). The error is due to the fact that the initmethod is not called before send in my example and there is not connection to use. I updated the example but I will have to test it if I find time for it.

@devbobo The problem I see is that this method is rather complex with all its parameters. I would prefer a solution where there are simple methods like flash, breath and so on. But I am open to suggestions.

@devbobo
Copy link
Contributor

devbobo commented Jan 28, 2016

@MariusRumpf, yeah I'm all for breathe and pulse effect methods, just the Lifx remote API.

@MariusRumpf
Copy link
Owner Author

setWaveform should be a part of a 1.0 release.

@MariusRumpf MariusRumpf added this to the 1.0 milestone Jul 27, 2016
@liamnichols
Copy link

liamnichols commented Oct 9, 2016

Good work on this module, from my usage things are looking pretty flawless!

I did however just struggle why the following line in the above example made no impact on the output:

waveform: constants.LIGHT_WAVEFORMS[0]

I was changing it to 0,1,2,3 or 4 and not seeing any change when sending the packet. Turns out the constants file is defining an array of strings:

// Waveform values, order is important here
LIGHT_WAVEFORMS: [
    'SAW',
    'SINE',
    'HALF_SINE',
    'TRIANGLE',
    'PULSE'
  ], 

(indexes map to https://github.com/ppelleti/lifx-protocol-docs/blob/8a38d3d5060bd6cba562fa940459d9b637d55726/messages/light.md#waveform)

But the code in toBuffer() of setWaveform.js is expecting an 8 bit unsigned integer value.

  if (obj.waveform === undefined) {
    throw new TypeError('obj.waveform value must be given for setWaveform LIFX packet');
  }
  if (typeof obj.waveform !== 'number' && obj.waveform < 0 || obj.waveform > (constants.LIGHT_WAVEFORMS.length - 1)) {
    throw new RangeError('Invalid waveform value given for setWaveform LIFX packet, must be a number between 0 and ' + (constants.LIGHT_WAVEFORMS.length - 1));
  }
  buf.writeUInt8(obj.waveform, offset);
  offset += 1;

So the above sample is actually writing constants.LIGHT_WAVEFORMS[0] (SAW) as a UInt8 to the buffer that coincidently ends up as 0x00 anyway.

I was going to raise a PR to address this but I don't know the best approach to take? Should we just use the integer directly or should we be able to pass a string from the constants in and let that map back to it's int equivalent?

@MariusRumpf
Copy link
Owner Author

@liamnichols Thanks, you are right. I updated my example above to pass digits to the packet creation wrapper by using the indexOf function. It is correct that the package creation method expects a number. The wrapper for the package creation that will be created in the light.js will expose a more user friendly version should expect the strings then.

@MariusRumpf
Copy link
Owner Author

Just added an example how to use the raw method in 45c7ab8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants