Giter Site home page Giter Site logo

bb-froggy / accel-data-stream Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pebble-examples/accel-data-stream

0.0 0.0 0.0 144 KB

Example app demonstrating how to stream accelerometer data using AppMessage callbacks.

License: MIT License

Java 21.26% C 72.07% Python 6.67%

accel-data-stream's Introduction

accel-data-stream

Example app demonstrating how to stream accelerometer data using AppMessage callbacks. To do this, accelerometer data is gathered via the AccelDataService:

static void accel_data_handler(AccelData *data, uint32_t num_samples) {
  // ...

  send(data, num_samples);

  // ...
}

Each set of samples received is transmitted to the Android app for display via AppMessage:

static void send(AccelData *data, uint32_t num_samples) {
  if(comm_send_data(data, num_samples)) {
    
    // ...

  }
}
bool comm_send_data(AccelData *data, uint32_t num_samples) {
  DictionaryIterator *out;
  AppMessageResult result = app_message_outbox_begin(&out);
  if(result == APP_MSG_OK) {
    for(uint32_t i = 0; i < num_samples; i++) {
      dict_write_int16(out, (COMM_NUM_PACKET_ELEMENTS * i) + 0, data[i].x);
      dict_write_int16(out, (COMM_NUM_PACKET_ELEMENTS * i) + 1, data[i].y);
      dict_write_int16(out, (COMM_NUM_PACKET_ELEMENTS * i) + 2, data[i].z);
    }

    if(app_message_outbox_send() == APP_MSG_OK) {
      s_busy = true;
      return true;
    }

    // ...

  }
}

The availability of the channel is tracked using AppMessage callbacks to prevent transmission attempts before the previous packet has been acknowledged.

static void outbox_sent_handler(DictionaryIterator *iterator, void *context) {
  // Message acknowledged, no longer busy
  s_busy = false;
}
if(comm_is_busy()) {
  APP_LOG(APP_LOG_LEVEL_WARNING, "Accel sample arrived early");
  window_set_background_color(s_window, GColorRed);
} else {
  send(data, num_samples);
}

accel-data-stream's People

Contributors

bb-froggy avatar c-d-lewis avatar

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.