Custom Vibe sequence in Pebble.js?

259 views Asked by At

I have developed a Watchapp with Pebble.js that fetches a remote file, containing an integer, and emits that many "short" Vibe events.

The trouble is: Vibe events do not happen if one is currently in process. I have resorted to something like this to try to spread them out (where BUMP_COUNT_INT == number of Vibes to emit):

    for (var i = 0; i < BUMP_COUNT_INT; i++) {
      setTimeout(function(){ 
        Vibe.vibrate('short'); 
    }, 900*i);

However, even the 900ms( * Vibes) isn't consistent. There is sometimes more or less space between them, and they sometimes merge (causing fewer Vibes than expected).

It appears that the C SDK is capable of custom sequences.

I was hoping someone had come across a cleaner workaround, or a more stable way to pull this off using Pebble.js ... ?

Should I just accept that I'll have to spread the Vibes out even further, if I want to continue with Pebble.js?

What would you do?

1

There are 1 answers

1
sarfata On BEST ANSWER

Custom patterns are not available in Pebble.js but you could easily add a new 'type' of vibe in Pebble.js and implement it as a custom pattern in the C side of Pebble.js.

The steps would be:

  1. Clone the Pebble.js project on GitHub and get a local copy. You will need to download and install the Pebble SDK to compile it locally on your computer (this will not work on CloudPebble).

  2. Declare a new type of vibe command in src/js/ui/simply-pebble.js (the Pebble.js JavaScript library):

    var vibeTypes = [
      'short',
      'long',
      'double',
      'custom'
    ];
    
    var VibeType = makeArrayType(vibeTypes);
    
  3. Create a new type of Vibe in src/simply/simply_msg.c

    enum VibeType {
      VibeShort = 0,
      VibeLong = 1,
      VibeDouble = 2,
      VibeCustom = 3,
    };
    
  4. And then extend the Vibe command handler to support this new type of vibe in src/simply/simply_msg.c

    static void handle_vibe_packet(Simply *simply, Packet *data) {
      VibePacket *packet = (VibePacket*) data;
      switch (packet->type) {
        case VibeShort: vibes_short_pulse(); break;
        case VibeLong: vibes_break_pulse(); break;
        case VibeDouble: vibes_double_pulse(); break;
        case VibeCustom: 
          static const uint32_t const segments[] = { 200, 100, 400 };
          VibePattern pat = {
            .durations = segments,
            .num_segments = ARRAY_LENGTH(segments),
          };
          vibes_enqueue_custom_pattern(pat);
          break;
      }
    }
    

An even better solution would be to suggest a patch so that any custom pattern could be designed on the JavaScript side and sent to the watch.