Git Product home page Git Product logo

node-divoom-timebox-evo's Introduction

node-divoom-timebox-evo

This module helps you generate the appropriate message to use against the divoom timebox evo.

The communication part is not implemented here and you can use the bluetooth-serial-port module to communicate with the timebox.

Here's how you could do it:

const TIMEBOX_ADDRESS = "11:22:33:44:55:66";
var btSerial = new (require('bluetooth-serial-port')).BluetoothSerialPort();
var Divoom = require('node-divoom-timebox-evo');

btSerial.findSerialPortChannel(TIMEBOX_ADDRESS, function(channel) {
  btSerial.connect(address, channel, function() {
    console.log('connected');

    btSerial.on('data', function(buffer) {
      console.log(buffer.toString('ascii'));
    });
  }, function () {
    console.log('cannot connect');
  });
}, function() {
  console.log('found nothing');
});


var d = (new Divoom.TimeboxEvo()).createRequest('animation');
d.read('animation.gif').then(result => {
  result.asBinaryBuffer().forEach(elt => {
    btSerial.write(elt,
      function(err, bytesWritten) {
        if (err) console.log(err);
      }
    );
  })
}).catch(err => {
  throw err;
});

Protocol Documentation

See Protocol

Install

npm i node-divoom-timebox-evo

Some Examples

See the complete documentation here

Create a request

You'll always have to create a request first:

var Divoom = require('node-divoom-timebox-evo');
var d = (new Divoom.TimeboxEvo()).createRequest('REQUEST_TYPE');

// d.messages.asBinaryBuffer() is an array of messages you have to send to your Timebox Evo over bluetooth as is. It returns an array of Buffers with Binary content.
console.log(d.messages.asBinaryBuffer());

The different REQUEST_TYPE are:

RAW Command

There's no need to calculate the size or the CRC of the messages. This will be done automatically.

var Divoom = require('node-divoom-timebox-evo');

var d = (new Divoom.TimeboxEvo()).createRequest('raw');
d.push("4505");
d.messages.forEach(m => {
  console.log(m.message);
}) // Will display the list of messages as hexadecimals strings
console.log(d.messages.asBinaryBuffer());

Displaying an animation or a picture

var Divoom = require('node-divoom-timebox-evo');

var d = (new Divoom.TimeboxEvo()).createRequest('animation');
d.read('file.png').then(result => {
  console.log(result.asBinaryBuffer());
  // send toSend to the Divoom
  // use https://github.com/eelcocramer/node-bluetooth-serial-port
}).catch(err => {
  throw err;
});

Displaying Text

You have a number of baked in palettes:

  • PALETTE_TEXT_ON_BACKGROUND(text?: ColorInput, background?: ColorInput): Sets the text color and the background color
  • PALETTE_BLACK_ON_RAINBOW: Black text on a rainbow background
  • PALETTE_BLACK_ON_CMY_RAINBOW: Black text on a CMY rainbow background

And a number of baked in animations:

  • ANIM_STATIC_BACKGROUND: Background will not change color (useful with PALETTE_TEXT_ON_BACKGROUND)
  • ANIM_UNI_GRADIANT_BACKGROUND: Uniform background which will loop over all the colors of your palette
  • ANIM_VERTICAL_GRADIANT_BACKGROUND: Vertical gradient background which will loop over all the colors of your palette
  • ANIM_HORIZONTAL_GRADIANT_BACKGROUND: Horizontal gradient background which will loop over all the colors of your palette
var Divoom = require('node-divoom-timebox-evo');

var d = (new Divoom.TimeboxEvo()).createRequest('text', {text: "Hi friends!"});
d.paletteFn = d.PALETTE_BLACK_ON_CMY_RAINBOW; // Baked in color palette, but you can define your own
d.animFn = d.ANIM_HORIZONTAL_GRADIANT_BACKGROUND; // Baked in animation, but you can define your own

// This contains what is required to bootstrap the display on the Timebox
console.log(d.messages.asBinaryBuffer());

// Then you have to send your animation frame by frame, I suggest that you do no go over 30 message per second, if you do, the timebox will disconnect.
// This would generate 512 animation frames.
for (i = 0; i < 512; i++){
    console.log(d.getNextAnimationFrame().asBinaryBuffer());
}

You can define your own palette, the function has to return an array of 256 colors in Hex.
The text's color will be the item (background_color + 127) % 256. This is the code which generates the PALETTE_BLACK_ON_RAINBOW:

d.paletteFn = function() {
  function number2HexString(int: number): string {
    return Math.round(int).toString(16).padStart(2, "0");
  }

  let palette: string[] = [];
  const size = 127;
  function sin_to_hex(i: number, phase: number) {
    let sin = Math.sin(Math.PI / size * 2 * i + phase);
    let int = Math.floor(sin * 127) + 128;
    return number2HexString(int);
  }

  for (let i = 0; i < size; i++) {
    let red = sin_to_hex(i, 0 * Math.PI * 2 / 3); // 0   deg
    let blue = sin_to_hex(i, 1 * Math.PI * 2 / 3); // 120 deg
    let green = sin_to_hex(i, 2 * Math.PI * 2 / 3); // 240 deg
    palette.push(red + green + blue);
  }

  // Completes the palette (everything after the 127th item in the array) with black color so that the text is actually only black
  for (let i = palette.length; i < 256; i++) {
    palette.push("000000");
  }
  return palette;
}

You can also define your own animation. It should be an array of 256 entries each one representing a pixel and referencing the index of the color to be displayed, taken from the palette. The function takes a frame number as a parameter.
Example which generated the horizontal gradient background (ANIM_HORIZONTAL_GRADIANT_BACKGROUND):

d.animFn = function(frame) {
  let pixelArray = [];
  for (let y = 0; y < 16; y++) {
    for (let x = 0; x < 16; x++) {
      pixelArray.push((x + frame) % 127)
    }
  }
  return pixelArray;
}

node-divoom-timebox-evo's People

Contributors

romrider avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

node-divoom-timebox-evo's Issues

Some more examples

Hello,
I'm playing whit this gadget for a past couple of days now, but with very little results.

Connection to TIMEBOX is successful.

After no luck with (more complex) examples I decided to start with raw.

The only visible result I can get is switching to clock

  var d = (new Divoom.TimeboxEvo()).createRequest('raw');
  d.push("4500");
  d.messages.forEach(m => {
    btSerial.write(Buffer.from(m.message, 'hex'), function (err, bytesWritten) {
      if (err) {
        D('send N0K', err);
      }
      else {
        D('send 0K');
      }
    })
  }) // Will display the list of messages as hexadecimals strings
  D('d.messages.asBinaryBuffer()');
  D(d.messages.asBinaryBuffer());

and with 4507 (not 4506) I switch to "score board"

What would a command for setting number on score board would be?

I tried:

  • d.push("4507 0001 0002");
  • d.push("450700 0001 0002");
  • d.push("450700"+getScoreBoardEncoded(1,2));

Compatibility with last firmware ?

Hello
I try to communicate with the timebox-evo but lot of command doesn't work now
Since 4 year I think they are change
Im ok with the visualisation section ( 4504 string )
but lot of problem with the 4501 for exp
thank a lot

Collaboration offer

I'm also working on reverse engineering the bluetooth protocol and would be happy to work together...

The Github is https://github.com/panoramicdata/Divoom.Api

Though it's in broken English, there are some solid clues here: http://doc.divoom-gz.com/web/#/12?page_id=464 , including some interesting ordering to the response information, which we could assume matches the response byte order, or at least contains the same information in a different order:

Brightness | Number | 0~100, the system brightness
RotationFlag | Number | 1: it will switch to display faces and gifs
ClockTime | Number | the time of displaying faces and it will be active with RotationFlag = 1
GalleryTime | Number | the time of displaying gifs and it will be active with RotationFlag = 1
SingleGalleyTime | Number | the time of displaying each gif
PowerOnChannelId | Number | device will display the channle when it powers on
CurClockId | Number | the running’s face id
Time24Flag | Number | the display hour flag
TemperatureMode | Number | the display temperature flag
GyrateAngle | Number | the rotation angle:0: normal;1:90;2:180;3:270
MirrorFlag | Number | the mirror mode
LightSwitch | Number | the screen switch

Support for Divoom Pixoo (Max)

I'm using this in combination with the Divoom Pixoo Max but run into the following things:

  • Show picture works with DisplayAnimation but sending a GIF doesn't.
  • Showing text with DisplayText does show animated gradient but no text.
  • Brightness command works.
  • Time channel works.

Thanks for the work, awesome stuff!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.