首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我需要帮助组合或翻译c和JS。

我需要帮助组合或翻译c和JS。
EN

Stack Overflow用户
提问于 2015-10-30 04:10:20
回答 1查看 81关注 0票数 0

我在JavaScript中有一些代码,可以很好地工作,并通过发布到粒子微控制器来控制我的手表上的灯光。

我需要的部分是

代码语言:javascript
复制
 ajax(
      {
        url: particleAPIURL + 'devices/' + particleDeviceID + '/fanIO',
        method: 'post',
        data: {access_token: particleAPIKey, args: fanIO}
      });

打开了我的风扇。

我还有一个用c编写的代码,它可以进行语音控制。

代码语言:javascript
复制
#include <pebble.h>



static Window *s_main_window;
static TextLayer *s_output_layer;

static DictationSession *s_dictation_session;
static char s_last_text[100];
int desk = 0;
int bright = 0;
int fan = 0;
/******************************* Dictation API ********************************/

static void dictation_session_callback(DictationSession *session, DictationSessionStatus status,
                                       char *transcription, void *context) {

    //Show the text
    /********** IMPORTANT**************************************************/


  if(status == DictationSessionStatusSuccess) {
    // Display the dictated text

        if (strcmp(transcription, "Desk light") == 0) {


        snprintf(s_last_text, sizeof(s_last_text), "It Worked");
        text_layer_set_text(s_output_layer, s_last_text);

            if(desk == 0) {
                desk = 1;
              //I NEED TO DO WHAT THE JS DOES HERE
            }

    }
        else {

            snprintf(s_last_text, sizeof(s_last_text), "I'm sorry, blank. I'm afraid I can't do that...");
        text_layer_set_text(s_output_layer, s_last_text);


        }



  }

    //ERROR
    else {
    // Display the reason for any error
    static char s_failed_buff[128];
    snprintf(s_failed_buff, sizeof(s_failed_buff), "Transcription failed.\n\nError ID:\n%d", (int)status);
    text_layer_set_text(s_output_layer, s_failed_buff);
  }
}

/************************************ App *************************************/

//Click the middle button
static void select_click_handler(ClickRecognizerRef recognizer, void *context) {



    // Start voice dictation UI
  dictation_session_start(s_dictation_session);

}



static void click_config_provider(void *context) {
  window_single_click_subscribe(BUTTON_ID_SELECT, select_click_handler);
}



static void window_load(Window *window) {
  Layer *window_layer = window_get_root_layer(window);
  GRect bounds = layer_get_bounds(window_layer);

  s_output_layer = text_layer_create(GRect(bounds.origin.x, (bounds.size.h - 24) / 2, bounds.size.w, bounds.size.h));
  text_layer_set_text(s_output_layer, "Press Select to get input!");
  text_layer_set_text_alignment(s_output_layer, GTextAlignmentCenter);
  layer_add_child(window_layer, text_layer_get_layer(s_output_layer));
}

//What to do when exit app
static void window_unload(Window *window) {
  text_layer_destroy(s_output_layer);
}


static void init() {
  s_main_window = window_create();
  window_set_click_config_provider(s_main_window, click_config_provider);
  window_set_window_handlers(s_main_window, (WindowHandlers) {
    .load = window_load,
    .unload = window_unload,
  });
  window_stack_push(s_main_window, true);




  // Create new dictation session

    //s_last_text is size of info you can input
  s_dictation_session = dictation_session_create(sizeof(s_last_text), dictation_session_callback, NULL);
}

static void deinit() {
  // Free the last session data
  dictation_session_destroy(s_dictation_session);

  window_destroy(s_main_window);
}

int main() {
  init();
  app_event_loop();
  deinit();
}

注释在哪里,我需要做javascript在那里做的事情,也就是打开我的灯。

有人知道我是怎么做到的吗?如果需要,我可以提供更多的js。我没有太多的编程经验,所以我会喜欢描述性的答案。

TYIA

EN

回答 1

Stack Overflow用户

发布于 2015-10-30 05:02:21

C代码在手表上运行,因此不能像JavaScript代码那样直接进行http调用。基于手表的代码所能做的非常有限。

最好的办法是让你的基于手表的C代码send a message到手机上运行的一个配套应用程序,并让那个配套应用程序调用你需要的http请求。因为配套的应用程序是can be written in JavaScript的,你应该能够重用你现有的代码。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33423690

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档