Ejemplo n.º 1
0
/*---------------------------------------------------------------------------*/
static int barometer_open(struct baro_priv *baro)
{
    int err, max_retry = 3, retry_period = 100, retry;
    unsigned int flags = 1;
    err = 0;
    if (baro->fd == -1) 
	{
          baro->fd = open("/dev/barometer", O_RDONLY);
          if (baro->fd < 0) 
		  {
            FBLOGE("Couldn't open '%s' (%s)", baro->dev, strerror(errno));
            return -1;
          }
		  //
		  if ((err = ioctl(baro->fd, BAROMETER_IOCTL_INIT, NULL))) 
		  {
             FBLOGE("read press : %d(%s)\n", errno, strerror(errno));
             return err;
         }
                
        
    }
    FBLOGD("%s() %d\n", __func__, baro->fd);
    return 0;
}
Ejemplo n.º 2
0
std::string loadScriptFromAssets(
    AAssetManager *manager,
    const std::string& assetName) {
  #ifdef WITH_FBSYSTRACE
  FbSystraceSection s(TRACE_TAG_REACT_CXX_BRIDGE, "reactbridge_jni_loadScriptFromAssets",
    "assetName", assetName);
  #endif
  if (manager) {
    auto asset = AAssetManager_open(
      manager,
      assetName.c_str(),
      AASSET_MODE_STREAMING); // Optimized for sequential read: see AssetManager.java for docs
    if (asset) {
      std::stringbuf buf;
      char BUF[0x800];
      int readbytes;
      while ((readbytes = AAsset_read(asset, BUF, sizeof(BUF))) > 0) {
        buf.sputn(BUF, readbytes);
      }
      AAsset_close(asset);
      if (readbytes == 0) { // EOF!
        return buf.str();
      }
    }
  }
  FBLOGE("Unable to load script from assets: %s", assetName.c_str());
  return "";
}
Ejemplo n.º 3
0
/*---------------------------------------------------------------------------*/
static int barometer_update_info(struct baro_priv *baro)
{
    int err = -EINVAL;
    int temp_dat, press_dat;
    if (baro->fd == -1) {
        FBLOGE("invalid fd\n");
        return -EINVAL;
    } else if ((err = ioctl(baro->fd, BAROMETER_GET_PRESS_DATA, &press_dat))) {
        FBLOGE("read press : %d(%s)\n", errno, strerror(errno));
        return err;
    } else if ((err = ioctl(baro->fd, BAROMETER_GET_TEMP_DATA, &temp_dat))) {
        FBLOGE("read temp: %d(%s)\n", errno, strerror(errno));
        return err;
    }
	
    baro->temp_raw = temp_dat;
    baro->press_raw = press_dat;
    return 0;
}
Ejemplo n.º 4
0
/* static */
JNIEnv* Environment::current() {
  JNIEnv* env = g_env->get();
  if ((env == nullptr) && (g_vm != nullptr)) {
    if (g_vm->GetEnv((void**) &env, JNI_VERSION_1_6) != JNI_OK) {
      FBLOGE("Error retrieving JNI Environment, thread is probably not attached to JVM");
      env = nullptr;
    } else {
      g_env->reset(env);
    }
  }
  return env;
}
Ejemplo n.º 5
0
std::string loadScriptFromFile(const std::string& fileName) {
  #ifdef WITH_FBSYSTRACE
  FbSystraceSection s(TRACE_TAG_REACT_CXX_BRIDGE, "reactbridge_jni_loadScriptFromFile",
    "fileName", fileName);
  #endif
  std::ifstream jsfile(fileName);
  if (jsfile) {
    std::string output;
    jsfile.seekg(0, std::ios::end);
    output.reserve(jsfile.tellg());
    jsfile.seekg(0, std::ios::beg);
    output.assign(
      (std::istreambuf_iterator<char>(jsfile)),
      std::istreambuf_iterator<char>());
    return output;
  }

  FBLOGE("Unable to load script from file: %s", fileName.c_str());
  return "";
}
Ejemplo n.º 6
0
/*---------------------------------------------------------------------------*/
static void *barometer_update_iv_thread(void *priv)
{
    struct baro_data *dat = (struct baro_data *)priv; 
    struct baro_priv *baro = &dat->baro;
    struct itemview *iv = dat->iv;    
    int err = 0, len = 0;
    char *status;

    LOGD(TAG "%s: Start\n", __FUNCTION__);
    if ((err = barometer_open(baro))) {
    	memset(dat->info, 0x00, sizeof(dat->info));
        sprintf(dat->info, "INIT FAILED\n");
        iv->redraw(iv);
        FBLOGE("barometer() err = %d(%s)\n", err, dat->info);
        pthread_exit(NULL);
        return NULL;
    }
        
    while (1) {
        
        if (dat->exit_thd)
            break;
            
        if ((err = barometer_update_info(baro)))
            continue;     

        len = 0;
        len += snprintf(dat->info+len, sizeof(dat->info)-len, "TEMP: %f \n", baro->temp_raw/100);      
        len += snprintf(dat->info+len, sizeof(dat->info)-len, "PRESS : %f\n", baro->press_raw/100);
        iv->set_text(iv, &dat->text);
        iv->redraw(iv);
    }
    barometer_close(baro);
    LOGD(TAG "%s: Exit\n", __FUNCTION__);    
    pthread_exit(NULL);    
    return NULL;
}
Ejemplo n.º 7
0
static JSValueRef evaluateScriptWithJSC(
    JSGlobalContextRef ctx,
    JSStringRef script,
    JSStringRef sourceURL) {
  JSValueRef exn;
  auto result = JSEvaluateScript(ctx, script, nullptr, sourceURL, 0, &exn);
  if (result == nullptr) {
    JSValueProtect(ctx, exn);
    std::string exceptionText = Value(ctx, exn).toString().str();
    FBLOGE("Got JS Exception: %s", exceptionText.c_str());
    auto line = Value(ctx, JSObjectGetProperty(ctx,
      JSValueToObject(ctx, exn, nullptr),
      JSStringCreateWithUTF8CString("line"), nullptr
    ));
    std::ostringstream lineInfo;
    if (line != nullptr && line.isNumber()) {
      lineInfo << " (line " << line.asInteger() << " in the generated bundle)";
    } else {
      lineInfo << " (no line info)";
    }
    throwNewJavaException("com/facebook/react/bridge/JSExecutionException", (exceptionText + lineInfo.str()).c_str());
  }
  return result;
}