我在JavaScript中使用了一些功能良好的代码,并通过发布到粒子微控制器来控制我手表中的灯光。
我需要的部分是
ajax(
{
url: particleAPIURL + 'devices/' + particleDeviceID + '/fanIO',
method: 'post',
data: {access_token: particleAPIKey, args: fanIO}
});
这打开了我的粉丝。
我在c中也有代码进行语音控制。
#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
答案 0 :(得分:1)
C代码在手表上运行,因此无法直接进行http调用,就像您显示的JavaScript代码所做的那样。基于手表的代码在它可以做的事情上非常有限。
您最好的选择是将基于手表的C代码send a message发送到手机上运行的随播应用,并让该随播应用调用您需要的http请求。自协同应用can be written in JavaScript以来,您应该可以重复使用现有代码。