gpt4 book ai didi

javascript - 我需要帮助组合或翻译 c 和 JS

转载 作者:行者123 更新时间:2023-11-30 15:15:44 24 4
gpt4 key购买 nike

我有一些 JavaScript 代码,可以很好地运行,并通过发布到粒子微 Controller 来控制我的 watch 上的灯光。

我需要的部分是

 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

最佳答案

C 代码在 watch 上运行,因此无法像您显示的 JavaScript 代码那样直接进行 http 调用。基于 watch 的代码的功能非常有限。

最好的选择是将基于 watch 的 C 代码设置为 send a message到手机上运行的配套应用程序,并让该配套应用程序调用您需要的 http 请求。由于配套应用程序 can be written in JavaScript您应该能够重用现有的代码。

关于javascript - 我需要帮助组合或翻译 c 和 JS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33423690/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com