aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJimmy Huang <jimmy.huang@linux.intel.com>2018-02-01 15:11:31 -0800
committerGeoff Gustafson <geoff@linux.intel.com>2018-02-01 15:11:31 -0800
commit6e84215b43382f142b1a257305f7b028acd423fa (patch)
treeb05956991ebfdfcfaae4393445384267aa2df4a4
parent4324cf215b8b10c6371aee88412dd317fe193b8a (diff)
[general] Style cleanup with clang (#1794)
Signed-off-by: Jimmy Huang <jimmy.huang@intel.com>
-rw-r--r--arc/src/arc_aio.c2
-rw-r--r--arc/src/arc_curie_pme.h4
-rw-r--r--src/ashell/term-cmd.c6
-rw-r--r--src/ashell/term-ihex.c4
-rw-r--r--src/ashell/term-uart.c4
-rw-r--r--src/jerry-port/zjs_jerry_port.c2
-rw-r--r--src/main.c73
-rw-r--r--src/zjs_aio.c22
-rw-r--r--src/zjs_aio_a101.c25
-rw-r--r--src/zjs_ble.c6
-rw-r--r--src/zjs_buffer.c3
-rw-r--r--src/zjs_callbacks.c10
-rw-r--r--src/zjs_common.h16
-rw-r--r--src/zjs_event.c6
-rw-r--r--src/zjs_event.h20
-rw-r--r--src/zjs_fs.c4
-rw-r--r--src/zjs_gfx.c263
-rw-r--r--src/zjs_gpio.c17
-rw-r--r--src/zjs_grove_lcd.c7
-rw-r--r--src/zjs_grove_lcd_ipm.c7
-rw-r--r--src/zjs_i2c.c4
-rw-r--r--src/zjs_modules.c30
-rw-r--r--src/zjs_net.c52
-rw-r--r--src/zjs_net_config.c20
-rw-r--r--src/zjs_ocf_client.c54
-rw-r--r--src/zjs_ocf_common.c133
-rw-r--r--src/zjs_ocf_encoder.h28
-rw-r--r--src/zjs_ocf_server.c2
-rw-r--r--src/zjs_pinmux.c10
-rw-r--r--src/zjs_pme.c4
-rw-r--r--src/zjs_pwm.c10
-rw-r--r--src/zjs_sensor.c4
-rw-r--r--src/zjs_spi.c6
-rw-r--r--src/zjs_timers.c11
-rw-r--r--src/zjs_uart.c4
-rw-r--r--src/zjs_util.c7
-rw-r--r--src/zjs_util.h63
-rw-r--r--src/zjs_web_sockets.c19
-rw-r--r--src/zjs_webusb.c31
39 files changed, 493 insertions, 500 deletions
diff --git a/arc/src/arc_aio.c b/arc/src/arc_aio.c
index 2eb6045..27fa348 100644
--- a/arc/src/arc_aio.c
+++ b/arc/src/arc_aio.c
@@ -32,7 +32,7 @@ void arc_aio_cleanup()
u32_t arc_pin_read(u8_t pin)
{
struct adc_seq_entry entry = {
- .sampling_delay = 30, // anything smaller might give an error
+ .sampling_delay = 30, // anything smaller might give an error
.channel_id = pin,
.buffer = seq_buffer,
.buffer_length = ADC_BUFFER_SIZE,
diff --git a/arc/src/arc_curie_pme.h b/arc/src/arc_curie_pme.h
index b11f9fa..64350d2 100644
--- a/arc/src/arc_curie_pme.h
+++ b/arc/src/arc_curie_pme.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2017, Intel Corporation.
+// Copyright (c) 2017-2018, Intel Corporation.
#ifndef _ARC_CURIE_PME_H_
#define _ARC_CURIE_PME_H_
@@ -112,7 +112,7 @@ typedef enum {
CAT_CATEGORY = 0x7FFF, // the category associated with a neuron
GCR_DIST = 0x0080, // distance type, 1 = Lsup, 0 = L1
GCR_GLOBAL = 0x007F, // the context of the neuron
- NSR_CLASS_MODE = 0x0020, // Classifier mode 1 = KNN, 0 = RBF
+ NSR_CLASS_MODE = 0x0020, // Classifier mode 1 = KNN, 0 = RBF
NSR_NET_MODE = 0x0010, // 1 = save/restore 0 = learn/recognize
NSR_ID_FLAG = 0x0008, // Indicates positive identification
NSR_UNCERTAIN_FLAG = 0x0004, // Indicates uncertain identification
diff --git a/src/ashell/term-cmd.c b/src/ashell/term-cmd.c
index ebcaee7..056cf2a 100644
--- a/src/ashell/term-cmd.c
+++ b/src/ashell/term-cmd.c
@@ -1,4 +1,4 @@
-// Copyright (c) 2016-2017, Intel Corporation.
+// Copyright (c) 2016-2018, Intel Corporation.
/**
* @file
@@ -7,10 +7,10 @@
// C includes
#include <ctype.h>
+#include <malloc.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
-#include <malloc.h>
// Zephyr includes
#include "file-utils.h"
@@ -24,9 +24,9 @@
#endif
// ZJS includes
-#include "term-uart.h"
#include "term-cmd.h"
#include "term-ihex.h"
+#include "term-uart.h"
#include "../zjs_util.h"
// JerryScript includes
diff --git a/src/ashell/term-ihex.c b/src/ashell/term-ihex.c
index 7847149..0ec148f 100644
--- a/src/ashell/term-ihex.c
+++ b/src/ashell/term-ihex.c
@@ -1,4 +1,4 @@
-// Copyright (c) 2016-2017, Intel Corporation.
+// Copyright (c) 2016-2018, Intel Corporation.
/**
* @file
@@ -18,9 +18,9 @@
#include "jerry-code.h"
// ZJS includes
+#include "ihex/kk_ihex_read.h"
#include "term-cmd.h"
#include "term-uart.h"
-#include "ihex/kk_ihex_read.h"
#include "file-utils.h"
diff --git a/src/ashell/term-uart.c b/src/ashell/term-uart.c
index 12415ee..df07575 100644
--- a/src/ashell/term-uart.c
+++ b/src/ashell/term-uart.c
@@ -1,4 +1,4 @@
-// Copyright (c) 2016-2017, Intel Corporation.
+// Copyright (c) 2016-2018, Intel Corporation.
/**
* @file
@@ -38,8 +38,8 @@
#include "jerry-code.h"
// ZJS includes
-#include "term-uart.h"
#include "term-cmd.h"
+#include "term-uart.h"
#ifndef CONFIG_USB_CDC_ACM
#include "webusb_serial.h"
diff --git a/src/jerry-port/zjs_jerry_port.c b/src/jerry-port/zjs_jerry_port.c
index a72f276..eaf59e0 100644
--- a/src/jerry-port/zjs_jerry_port.c
+++ b/src/jerry-port/zjs_jerry_port.c
@@ -1,4 +1,4 @@
-// Copyright (c) 2017, Intel Corporation.
+// Copyright (c) 2017-2018, Intel Corporation.
#include "jerryscript.h"
#include "jerryscript-port.h"
diff --git a/src/main.c b/src/main.c
index 4fedfc8..819a0f4 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,4 +1,4 @@
-// Copyright (c) 2016-2017, Intel Corporation.
+// Copyright (c) 2016-2018, Intel Corporation.
// C includes
#include <string.h>
@@ -210,37 +210,37 @@ int main(int argc, char *argv[])
#endif
#ifdef ZJS_ASHELL
-if (config_mode_detected()) {
- // go into IDE mode if connected GPIO button is pressed
- ashell_mode = true;
-} else {
- // boot to cfg file if found
- char filename[MAX_FILENAME_SIZE];
- if (fs_get_boot_cfg_filename(NULL, filename) == 0) {
- // read JS stored in filesystem
- fs_file_t *js_file = fs_open_alloc(filename, "r");
- if (!js_file) {
- ZJS_PRINT("\nFile %s not found on filesystem, \
- please boot into IDE mode, exiting!\n",
- filename);
- goto error;
- }
- script_len = fs_size(js_file);
- script = zjs_malloc(script_len + 1);
- ssize_t count = fs_read(js_file, script, script_len);
- if (script_len != count) {
- ZJS_PRINT("\nfailed to read JS file\n");
- zjs_free(script);
+ if (config_mode_detected()) {
+ // go into IDE mode if connected GPIO button is pressed
+ ashell_mode = true;
+ } else {
+ // boot to cfg file if found
+ char filename[MAX_FILENAME_SIZE];
+ if (fs_get_boot_cfg_filename(NULL, filename) == 0) {
+ // read JS stored in filesystem
+ fs_file_t *js_file = fs_open_alloc(filename, "r");
+ if (!js_file) {
+ ZJS_PRINT("\nFile %s not found on filesystem, \
+ please boot into IDE mode, exiting!\n",
+ filename);
+ goto error;
+ }
+ script_len = fs_size(js_file);
+ script = zjs_malloc(script_len + 1);
+ ssize_t count = fs_read(js_file, script, script_len);
+ if (script_len != count) {
+ ZJS_PRINT("\nfailed to read JS file\n");
+ zjs_free(script);
+ goto error;
+ }
+ script[script_len] = '\0';
+ ZJS_PRINT("JS boot config found, booting JS %s...\n\n\n", filename);
+ } else {
+ // boot cfg file not found
+ ZJS_PRINT("\nNo JS found, please boot into IDE mode, exiting!\n");
goto error;
}
- script[script_len] = '\0';
- ZJS_PRINT("JS boot config found, booting JS %s...\n\n\n", filename);
- } else {
- // boot cfg file not found
- ZJS_PRINT("\nNo JS found, please boot into IDE mode, exiting!\n");
- goto error;
}
-}
#endif
#ifndef ZJS_SNAPSHOT_BUILD
@@ -276,9 +276,9 @@ if (config_mode_detected()) {
#endif
#ifdef ZJS_DEBUGGER
-if (start_debug_server) {
- jerry_debugger_init(debug_port);
-}
+ if (start_debug_server) {
+ jerry_debugger_init(debug_port);
+ }
#endif
#ifndef ZJS_SNAPSHOT_BUILD
@@ -325,8 +325,8 @@ if (start_debug_server) {
err = bt_enable(NULL);
#endif
if (err) {
- ERR_PRINT("Failed to enable Bluetooth, error %d\n", err);
- goto error;
+ ERR_PRINT("Failed to enable Bluetooth, error %d\n", err);
+ goto error;
}
#endif
@@ -372,7 +372,7 @@ if (start_debug_server) {
serviced = 1;
}
#ifdef ZJS_LINUX_BUILD
- // FIXME - reverted patch #1542 to old timer implementation
+ // FIXME - reverted patch #1542 to old timer implementation
u64_t wait = zjs_timers_process_events();
if (wait != ZJS_TICKS_FOREVER) {
serviced = 1;
@@ -394,8 +394,7 @@ if (start_debug_server) {
#ifdef BUILD_MODULE_PROMISE
// run queued jobs for promises
result = jerry_run_all_enqueued_jobs();
- if (jerry_value_has_error_flag(result))
- {
+ if (jerry_value_has_error_flag(result)) {
DBG_PRINT("Error running JS in promise jobqueue\n");
zjs_print_error_message(result, ZJS_UNDEFINED);
goto error;
diff --git a/src/zjs_aio.c b/src/zjs_aio.c
index d3e2b61..f934820 100644
--- a/src/zjs_aio.c
+++ b/src/zjs_aio.c
@@ -1,4 +1,4 @@
-// Copyright (c) 2017, Intel Corporation.
+// Copyright (c) 2017-2018, Intel Corporation.
// enable to use function tracing for debug purposes
#if 0
@@ -108,11 +108,7 @@ static ZJS_DECL_FUNC_ARGS(aio_pin_read, bool async)
static ZJS_DECL_FUNC(zjs_aio_pin_read)
{
FTRACE_JSAPI;
- return aio_pin_read(function_obj,
- this,
- argv,
- argc,
- false);
+ return aio_pin_read(function_obj, this, argv, argc, false);
}
// Asynchronous Operations
@@ -122,11 +118,7 @@ static ZJS_DECL_FUNC(zjs_aio_pin_read_async)
// args: callback
ZJS_VALIDATE_ARGS(Z_FUNCTION);
- return aio_pin_read(function_obj,
- this,
- argv,
- argc,
- true);
+ return aio_pin_read(function_obj, this, argv, argc, true);
}
static ZJS_DECL_FUNC(zjs_aio_pin_close)
@@ -157,11 +149,9 @@ static ZJS_DECL_FUNC(zjs_aio_open)
int pin = zjs_board_find_aio(pin_val, devname, 20);
if (pin == FIND_PIN_INVALID) {
return TYPE_ERROR("bad pin argument");
- }
- else if (pin == FIND_DEVICE_FAILURE) {
+ } else if (pin == FIND_DEVICE_FAILURE) {
return zjs_error("device not found");
- }
- else if (pin < 0) {
+ } else if (pin < 0) {
return zjs_error("pin not found");
}
struct device *aiodev = device_get_binding(devname);
@@ -235,7 +225,7 @@ static void zjs_aio_cleanup(void *native)
}
static const jerry_object_native_info_t aio_module_type_info = {
- .free_cb = zjs_aio_cleanup
+ .free_cb = zjs_aio_cleanup
};
jerry_value_t zjs_aio_init()
diff --git a/src/zjs_aio_a101.c b/src/zjs_aio_a101.c
index 0fb88d5..1a143da 100644
--- a/src/zjs_aio_a101.c
+++ b/src/zjs_aio_a101.c
@@ -1,4 +1,4 @@
-// Copyright (c) 2016-2017, Intel Corporation.
+// Copyright (c) 2016-2018, Intel Corporation.
#ifdef BUILD_MODULE_AIO
#ifndef QEMU_BUILD
@@ -172,7 +172,8 @@ static jerry_value_t aio_pin_read(const jerry_value_t function_obj,
if (async) {
#ifdef ZJS_FIND_FUNC_NAME
- zjs_obj_add_string(argv[0], ZJS_HIDDEN_PROP("function_name"), "readAsync");
+ zjs_obj_add_string(argv[0], ZJS_HIDDEN_PROP("function_name"),
+ "readAsync");
#endif
zjs_callback_id id = zjs_add_callback_once(argv[0], this, NULL, NULL);
zjs_signal_callback(id, &result, sizeof(result));
@@ -184,11 +185,7 @@ static jerry_value_t aio_pin_read(const jerry_value_t function_obj,
static ZJS_DECL_FUNC(zjs_aio_pin_read)
{
- return aio_pin_read(function_obj,
- this,
- argv,
- argc,
- false);
+ return aio_pin_read(function_obj, this, argv, argc, false);
}
// Asynchronous Operations
@@ -197,11 +194,7 @@ static ZJS_DECL_FUNC(zjs_aio_pin_read_async)
// args: callback
ZJS_VALIDATE_ARGS(Z_FUNCTION);
- return aio_pin_read(function_obj,
- this,
- argv,
- argc,
- true);
+ return aio_pin_read(function_obj, this, argv, argc, true);
}
static ZJS_DECL_FUNC(zjs_aio_pin_close)
@@ -234,11 +227,9 @@ static ZJS_DECL_FUNC(zjs_aio_open)
int pin = zjs_board_find_aio(pin_val, devname, 20);
if (pin == FIND_PIN_INVALID) {
return TYPE_ERROR("bad pin argument");
- }
- else if (pin == FIND_DEVICE_FAILURE) {
+ } else if (pin == FIND_DEVICE_FAILURE) {
return zjs_error("device not found");
- }
- else if (pin < 0) {
+ } else if (pin < 0) {
return zjs_error("pin not found");
}
@@ -278,7 +269,7 @@ static void zjs_aio_cleanup(void *native)
}
static const jerry_object_native_info_t aio_module_type_info = {
- .free_cb = zjs_aio_cleanup
+ .free_cb = zjs_aio_cleanup
};
jerry_value_t zjs_aio_init()
diff --git a/src/zjs_ble.c b/src/zjs_ble.c
index e140a8e..de3da52 100644
--- a/src/zjs_ble.c
+++ b/src/zjs_ble.c
@@ -1,4 +1,4 @@
-// Copyright (c) 2016-2017, Intel Corporation.
+// Copyright (c) 2016-2018, Intel Corporation.
#ifdef BUILD_MODULE_BLE
#ifndef QEMU_BUILD
@@ -1304,7 +1304,6 @@ static void zjs_ble_cleanup(void *native)
ble_handle = NULL;
}
-
// INTERRUPT SAFE FUNCTION: No JerryScript VM, allocs, or release prints!
void ble_bt_ready(int err)
{
@@ -1349,7 +1348,8 @@ static jerry_value_t zjs_ble_init()
#ifdef ZJS_ASHELL
if (bt_enable(ble_bt_ready)) {
- ERR_PRINT("Failed to enable Bluetooth and may not be enabled again, please reboot\n");
+ ERR_PRINT("Failed to enable Bluetooth and may not be enabled again, ",
+ "please reboot\n");
}
#endif
return ble_obj;
diff --git a/src/zjs_buffer.c b/src/zjs_buffer.c
index 5428920..67bd687 100644
--- a/src/zjs_buffer.c
+++ b/src/zjs_buffer.c
@@ -424,8 +424,7 @@ static ZJS_DECL_FUNC(zjs_buffer_fill)
source[2] = (0x0000ff00 & srcnum) >> 8;
source[3] = 0x000000ff & srcnum;
srclen = sizeof(u32_t);
- }
- else if (zjs_value_is_buffer(argv[0])) {
+ } else if (zjs_value_is_buffer(argv[0])) {
zjs_buffer_t *srcbuf = zjs_buffer_find(argv[0]);
source = (char *)srcbuf->buffer;
srclen = srcbuf->bufsize;
diff --git a/src/zjs_callbacks.c b/src/zjs_callbacks.c
index 5926716..ccf59bf 100644
--- a/src/zjs_callbacks.c
+++ b/src/zjs_callbacks.c
@@ -205,7 +205,8 @@ typedef struct deferred_work {
char data[0]; // user data
} deferred_work_t;
-static void deferred_work_callback(void *handle, const void *args) {
+static void deferred_work_callback(void *handle, const void *args)
+{
const deferred_work_t *deferred = (const deferred_work_t *)args;
#ifdef DEBUG_CALLBACKS
@@ -300,7 +301,7 @@ zjs_callback_id add_callback_priv(jerry_value_t js_func,
cb_map[new_cb->id] = new_cb;
DBG_PRINT("adding new callback id %d, js_func=%p, once=%u\n", new_cb->id,
- (void *)(uintptr_t)new_cb->js_func, once);
+ (void *)(uintptr_t)new_cb->js_func, once);
#ifdef INSTRUMENT_CALLBACKS
set_info_string(cb_map[new_cb->id]->creator, file, func);
@@ -351,8 +352,7 @@ static void zjs_remove_callback_priv(zjs_callback_id id, bool skip_flush)
}
}
DBG_PRINT("removing callback id %d\n", id);
- }
- else {
+ } else {
CB_UNLOCK();
}
}
@@ -494,7 +494,7 @@ void print_callbacks(void)
if (jerry_value_is_function(cb_map[i]->js_func)) {
ZJS_PRINT("Single Function\n");
ZJS_PRINT("\tjs_func: %p\n",
- (void *)(uintptr_t)cb_map[i]->js_func);
+ (void *)(uintptr_t)cb_map[i]->js_func);
ZJS_PRINT("\tonce: %u\n", GET_ONCE(cb_map[i]->flags));
} else {
ZJS_PRINT("js_func is not a function\n");
diff --git a/src/zjs_common.h b/src/zjs_common.h
index 2427840..390ba31 100644
--- a/src/zjs_common.h
+++ b/src/zjs_common.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2016-2017, Intel Corporation.
+// Copyright (c) 2016-2018, Intel Corporation.
#ifndef __zjs_common_h__
#define __zjs_common_h__
@@ -56,13 +56,13 @@ int zjs_get_ms(void);
#elif defined(ZJS_VERBOSE) && ZJS_VERBOSE >= 2
// Verbosity level 2 just shows function/line
#define DBG_PRINT \
- ZJS_PRINT("\n%s:%d %s():\n(INFO) ", zjs_shorten_filepath(__FILE__), \
- __LINE__, __func__); \
+ ZJS_PRINT("\n%s:%d %s():\n(INFO) ", zjs_shorten_filepath(__FILE__), \
+ __LINE__, __func__); \
ZJS_PRINT
-#define ERR_PRINT \
- ZJS_PRINT("\n%s:%d %s():\n(ERROR) ", zjs_shorten_filepath(__FILE__), \
- __LINE__, __func__); \
+#define ERR_PRINT \
+ ZJS_PRINT("\n%s:%d %s():\n(ERROR) ", zjs_shorten_filepath(__FILE__), \
+ __LINE__, __func__); \
ZJS_PRINT
#else
// Verbosity level 1 just shows text
@@ -72,8 +72,8 @@ int zjs_get_ms(void);
#else // !DEBUG_BUILD
#define DBG_PRINT(fmt...) do {} while (0)
-#define ERR_PRINT \
- ZJS_PRINT("\n%d:(ERROR) ", __LINE__); \
+#define ERR_PRINT \
+ ZJS_PRINT("\n%d:(ERROR) ", __LINE__); \
ZJS_PRINT
#endif // DEBUG_BUILD
diff --git a/src/zjs_event.c b/src/zjs_event.c
index c8dabf7..62e9f6f 100644
--- a/src/zjs_event.c
+++ b/src/zjs_event.c
@@ -319,7 +319,8 @@ typedef struct emit_event {
char data[0]; // data is user data followed by null-terminated event name
} emit_event_t;
-static void emit_event_callback(void *handle, const void *args) {
+static void emit_event_callback(void *handle, const void *args)
+{
const emit_event_t *emit = (const emit_event_t *)args;
void *user_handle = zjs_event_get_user_handle(emit->obj);
@@ -452,7 +453,8 @@ void *zjs_event_get_user_handle(jerry_value_t obj)
return NULL;
}
-static void zjs_event_init_prototype() {
+static void zjs_event_init_prototype()
+{
if (!zjs_event_emitter_prototype) {
zjs_native_func_t array[] = {
{ add_listener, "on" },
diff --git a/src/zjs_event.h b/src/zjs_event.h
index c21fe9e..7b19d7b 100644
--- a/src/zjs_event.h
+++ b/src/zjs_event.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2016-2017, Intel Corporation.
+// Copyright (c) 2016-2018, Intel Corporation.
#ifndef __zjs_event_h__
#define __zjs_event_h__
@@ -133,11 +133,10 @@ jerry_value_t zjs_add_event_listener(jerry_value_t obj, const char *event_name,
* @return True if there were listeners
*/
#if DEBUG_TRACE_EMIT
-#define zjs_defer_emit_event(obj, name, buffer, bytes, pre, post) \
- { \
- ZJS_PRINT("[EVENT] %s:%d Deferring '%s'\n", __FILE__, \
- __LINE__, name); \
- zjs_defer_emit_event_priv(obj, name, buffer, bytes, pre, post); \
+#define zjs_defer_emit_event(obj, name, buffer, bytes, pre, post) \
+ { \
+ ZJS_PRINT("[EVENT] %s:%d Deferring '%s'\n", __FILE__, __LINE__, name); \
+ zjs_defer_emit_event_priv(obj, name, buffer, bytes, pre, post); \
}
#else
#define zjs_defer_emit_event zjs_defer_emit_event_priv
@@ -159,11 +158,10 @@ void zjs_defer_emit_event_priv(jerry_value_t obj, const char *name,
* @return True if there were listeners called
*/
#if DEBUG_TRACE_EMIT
-#define zjs_emit_event(obj, name, argv, argc) \
- ({ \
- ZJS_PRINT("[EVENT] %s:%d Emitting '%s'\n", __FILE__, \
- __LINE__, name); \
- zjs_emit_event_priv(obj, name, argv, argc); \
+#define zjs_emit_event(obj, name, argv, argc) \
+ ({ \
+ ZJS_PRINT("[EVENT] %s:%d Emitting '%s'\n", __FILE__, __LINE__, name); \
+ zjs_emit_event_priv(obj, name, argv, argc); \
})
#else
#define zjs_emit_event zjs_emit_event_priv
diff --git a/src/zjs_fs.c b/src/zjs_fs.c
index 4e40317..695f3cd 100644
--- a/src/zjs_fs.c
+++ b/src/zjs_fs.c
@@ -1,4 +1,4 @@
-// Copyright (c) 2016-2017, Intel Corporation.
+// Copyright (c) 2016-2018, Intel Corporation.
#ifdef BUILD_MODULE_FS
@@ -987,7 +987,7 @@ static void zjs_fs_cleanup(void *native)
}
static const jerry_object_native_info_t fs_module_type_info = {
- .free_cb = zjs_fs_cleanup
+ .free_cb = zjs_fs_cleanup
};
static jerry_value_t zjs_fs_init()
diff --git a/src/zjs_gfx.c b/src/zjs_gfx.c
index 274e38a..97e63de 100644
--- a/src/zjs_gfx.c
+++ b/src/zjs_gfx.c
@@ -7,10 +7,10 @@
#include "zjs_buffer.h"
#include "zjs_callbacks.h"
#include "zjs_error.h"
-#include "zjs_util.h"
#include "zjs_gfx_font.h"
+#include "zjs_util.h"
-#define COLORBYTES 2 // Number of bytes needed to represent the color
+#define COLORBYTES 2 // Number of bytes needed to represent the color
#define MAXPIXELS 1000 * COLORBYTES
typedef struct gfx_handle {
@@ -19,10 +19,10 @@ typedef struct gfx_handle {
jerry_value_t pixels;
zjs_buffer_t *pixelsPtr;
// Touched pixels values will hold a rectangle containing the buffer to draw
- u16_t tpX0; // Touched pixels x start
- u16_t tpX1; // Touched pixels x end
- u16_t tpY0; // Touched pixels y start
- u16_t tpY1; // Touched pixels y end
+ u16_t tpX0; // Touched pixels x start
+ u16_t tpX1; // Touched pixels x end
+ u16_t tpY0; // Touched pixels y start
+ u16_t tpY1; // Touched pixels y end
bool touched;
u8_t fillStyle[COLORBYTES];
jerry_value_t screenInitCB;
@@ -45,7 +45,8 @@ static jerry_value_t zjs_gfx_prototype;
bool drawImmediate = true;
// Draw function depends on whether we are in immediate draw mode or not.
// It gets set by init
-void (*zjs_gfx_draw_pixels)(int32_t, int32_t, u32_t, u32_t, u8_t[], gfx_handle_t*);
+void (*zjs_gfx_draw_pixels)(int32_t, int32_t, u32_t, u32_t, u8_t[],
+ gfx_handle_t *);
static void zjs_gfx_callback_free(void *native)
{
@@ -58,7 +59,7 @@ static void zjs_gfx_callback_free(void *native)
}
static const jerry_object_native_info_t gfx_type_info = {
- .free_cb = zjs_gfx_callback_free
+ .free_cb = zjs_gfx_callback_free
};
// Extracts the args from jerry values and puts them into the data struct
@@ -78,17 +79,16 @@ static void args_to_data(gfx_data_t *data, u32_t argc, const jerry_value_t argv[
data->coords[i] = (int32_t)jerry_get_number_value(argv[i]);
else
data->size = (u32_t)jerry_get_number_value(argv[i]);
- }
- else if (jerry_value_is_string(argv[i])) {
+ } else if (jerry_value_is_string(argv[i])) {
data->text = zjs_alloc_from_jstring(argv[i], &data->textSize);
if (!data->text) {
ERR_PRINT("GFX failed to copy text\n");
}
- }
- else if (jerry_value_is_array(argv[i])) {
+ } else if (jerry_value_is_array(argv[i])) {
for (u8_t j = 0; j < COLORBYTES; j++) {
- data->color[j] = (u8_t)jerry_get_number_value(jerry_get_property_by_index(argv[i], j));
- }
+ data->color[j] = (u8_t)jerry_get_number_value(
+ jerry_get_property_by_index(argv[i], j));
+ }
}
}
}
@@ -103,28 +103,28 @@ static void zjs_gfx_reset_touched_pixels(gfx_handle_t *gfxHandle)
gfxHandle->touched = false;
}
-static void zjs_gfx_touch_pixels(int32_t x, int32_t y, u32_t w, u32_t h, u8_t color[], gfx_handle_t *gfxHandle)
+static void zjs_gfx_touch_pixels(int32_t x, int32_t y, u32_t w, u32_t h,
+ u8_t color[], gfx_handle_t *gfxHandle)
{
// Check that x and y aren't past the screen
- if (x >= gfxHandle->screenW || y >= gfxHandle->screenH || (int32_t)(x + w) <= 0 || (int32_t)(y + h) <= 0)
+ if (x >= gfxHandle->screenW || y >= gfxHandle->screenH ||
+ (int32_t)(x + w) <= 0 || (int32_t)(y + h) <= 0) {
return;
+ }
if (x < 0) {
if (x + w <= gfxHandle->screenW) {
gfxHandle->tpX0 = 0;
gfxHandle->tpX1 = x + w - 1;
- }
- else {
+ } else {
gfxHandle->tpX0 = 0;
gfxHandle->tpX1 = gfxHandle->screenW;
}
- }
- else if (x < gfxHandle->screenW) {
+ } else if (x < gfxHandle->screenW) {
if (x + w <= gfxHandle->screenW) {
gfxHandle->tpX0 = x;
gfxHandle->tpX1 = x + w - 1;
- }
- else {
+ } else {
gfxHandle->tpX0 = x;
gfxHandle->tpX1 = gfxHandle->screenW;
}
@@ -134,18 +134,15 @@ static void zjs_gfx_touch_pixels(int32_t x, int32_t y, u32_t w, u32_t h, u8_t co
if (y + h <= gfxHandle->screenH) {
gfxHandle->tpY0 = 0;
gfxHandle->tpY1 = y + h - 1;
- }
- else {
+ } else {
gfxHandle->tpY0 = 0;
gfxHandle->tpY1 = gfxHandle->screenH;
}
- }
- else if (y < gfxHandle->screenH) {
+ } else if (y < gfxHandle->screenH) {
if (y + h <= gfxHandle->screenH) {
gfxHandle->tpY0 = y;
gfxHandle->tpY1 = y + h - 1;
- }
- else {
+ } else {
gfxHandle->tpY0 = y;
gfxHandle->tpY1 = gfxHandle->screenH;
}
@@ -166,7 +163,8 @@ static void zjs_gfx_touch_pixels(int32_t x, int32_t y, u32_t w, u32_t h, u8_t co
for (u16_t iX = x; iX < x + w; iX++) {
// Each pixel can be several bytes, fill them in accordingly
for (u8_t cbyte = 0; cbyte < COLORBYTES; cbyte++) {
- gfxHandle->pixelsPtr->buffer[pixelsIndex + cbyte] = color[cbyte];
+ gfxHandle->pixelsPtr->buffer[pixelsIndex + cbyte] =
+ color[cbyte];
}
pixelsIndex += COLORBYTES;
}
@@ -175,16 +173,22 @@ static void zjs_gfx_touch_pixels(int32_t x, int32_t y, u32_t w, u32_t h, u8_t co
gfxHandle->touched = true;
}
-static jerry_value_t zjs_gfx_call_cb(u32_t x, u32_t y, u32_t w, u32_t h, jerry_value_t data, gfx_handle_t *gfxHandle)
+static jerry_value_t zjs_gfx_call_cb(u32_t x, u32_t y, u32_t w, u32_t h,
+ jerry_value_t data,
+ gfx_handle_t *gfxHandle)
{
- jerry_value_t args[] = {jerry_create_number(x), jerry_create_number(y),
- jerry_create_number(w),
- jerry_create_number(h),
- data};
+ jerry_value_t args[] = {
+ jerry_create_number(x),
+ jerry_create_number(y),
+ jerry_create_number(w),
+ jerry_create_number(h),
+ data
+ };
- jerry_value_t ret = jerry_call_function(gfxHandle->drawDataCB, gfxHandle->jsThis, args, 5);
+ jerry_value_t ret = jerry_call_function(gfxHandle->drawDataCB,
+ gfxHandle->jsThis, args, 5);
- if (jerry_value_has_error_flag (ret)) {
+ if (jerry_value_has_error_flag(ret)) {
ERR_PRINT("JS callback failed with %u..\n", (u32_t)ret);
return ret;
}
@@ -193,34 +197,36 @@ static jerry_value_t zjs_gfx_call_cb(u32_t x, u32_t y, u32_t w, u32_t h, jerry_v
static jerry_value_t zjs_gfx_flush(gfx_handle_t *gfxHandle)
{
- if (!gfxHandle->touched)
+ if (!gfxHandle->touched) {
return ZJS_UNDEFINED;
+ }
u32_t tpW = gfxHandle->tpX1 - gfxHandle->tpX0 + 1;
u32_t tpH = gfxHandle->tpY1 - gfxHandle->tpY0 + 1;
u32_t pixels = tpW * tpH * COLORBYTES;
zjs_buffer_t *recBuf = NULL;
u16_t bufferIndex = 0;
u32_t origIndex = 0;
- u8_t passes = 1; // Number of times the data buffer needs to be sent
+ u8_t passes = 1; // Number of times the data buffer needs to be sent
jerry_value_t ret;
if (pixels > MAXPIXELS) {
- u32_t bytesPerRow = tpW * COLORBYTES;
- u32_t rowsPerBuf = MAXPIXELS / bytesPerRow;
- passes = pixels / ( bytesPerRow * rowsPerBuf);
+ u32_t bytesPerRow = tpW * COLORBYTES;
+ u32_t rowsPerBuf = MAXPIXELS / bytesPerRow;
+ passes = pixels / (bytesPerRow * rowsPerBuf);
// If passes has a remainder, add a pass
- if (pixels % ( bytesPerRow * rowsPerBuf) != 0)
+ if (pixels % (bytesPerRow * rowsPerBuf) != 0) {
passes++;
+ }
- pixels = bytesPerRow * rowsPerBuf;
+ pixels = bytesPerRow * rowsPerBuf;
}
// If there are a lot of passes, it will be faster to draw the whole buffer
// Not valid for draw immidiate mode
if (passes > 5 && !drawImmediate) {
- ret = zjs_gfx_call_cb(0, 0, gfxHandle->screenW, gfxHandle->screenH, gfxHandle->pixels, gfxHandle);
- }
- else {
- ZVAL recBufObj = zjs_buffer_create(pixels, &recBuf);
+ ret = zjs_gfx_call_cb(0, 0, gfxHandle->screenW, gfxHandle->screenH,
+ gfxHandle->pixels, gfxHandle);
+ } else {
+ ZVAL recBufObj = zjs_buffer_create(pixels, &recBuf);
u32_t xStart = gfxHandle->tpX0;
u32_t yStart = gfxHandle->tpY0;
u32_t currX = xStart;
@@ -229,40 +235,45 @@ static jerry_value_t zjs_gfx_flush(gfx_handle_t *gfxHandle)
u32_t currH = 0;
u16_t currPass = 0;
- for (u16_t j = gfxHandle->tpY0; currPass < passes ; j++) {
+ for (u16_t j = gfxHandle->tpY0; currPass < passes; j++) {
currH++;
currY++;
xStart = gfxHandle->tpX0;
- for (u16_t i = gfxHandle->tpX0; i <= gfxHandle->tpX1 && currPass < passes; i++) {
+ for (u16_t i = gfxHandle->tpX0;
+ i <= gfxHandle->tpX1 && currPass < passes; i++) {
origIndex = (i + gfxHandle->screenW * j) * COLORBYTES;
// Fill the pixel
for (u8_t k = 0; k < COLORBYTES; k++) {
if (!drawImmediate) {
// Use cached pixel map
- recBuf->buffer[bufferIndex + k] = gfxHandle->pixelsPtr->buffer[origIndex + k];
- }
- else {
+ recBuf->buffer[bufferIndex + k] =
+ gfxHandle->pixelsPtr->buffer[origIndex + k];
+ } else {
// We are just drawing a solid rectangle, use fillStyle
- recBuf->buffer[bufferIndex + k] = gfxHandle->fillStyle[k];
+ recBuf->buffer[bufferIndex + k] =
+ gfxHandle->fillStyle[k];
}
}
- bufferIndex+=COLORBYTES;
+ bufferIndex += COLORBYTES;
// Width shouldn't be larger than touched pixel width
// This keeps track of widest point of the current buffer
if (currW < tpW) {
currW++;
}
// Send the buffer once its full or we are at the end
- if (bufferIndex == recBuf->bufsize || currY > gfxHandle->tpY1 + 1) {
- // If we didn't fill the last buffer completely, reset the size
+ if (bufferIndex == recBuf->bufsize ||
+ currY > gfxHandle->tpY1 + 1) {
+ // If we didn't fill the last buffer completely, reset the
+ // size
if (bufferIndex < recBuf->bufsize) {
recBuf->bufsize = bufferIndex;
}
- ret = zjs_gfx_call_cb(xStart, yStart, currW, currH, recBufObj, gfxHandle);
- if (jerry_value_has_error_flag (ret)) {
+ ret = zjs_gfx_call_cb(xStart, yStart, currW, currH,
+ recBufObj, gfxHandle);
+ if (jerry_value_has_error_flag(ret)) {
zjs_gfx_reset_touched_pixels(gfxHandle);
return ret;
}
@@ -283,7 +294,8 @@ static jerry_value_t zjs_gfx_flush(gfx_handle_t *gfxHandle)
return ZJS_UNDEFINED;
}
-static void zjs_gfx_fill_rect_priv (int32_t x, int32_t y, u32_t w, u32_t h, u8_t color[], gfx_handle_t *gfxHandle)
+static void zjs_gfx_fill_rect_priv(int32_t x, int32_t y, u32_t w, u32_t h,
+ u8_t color[], gfx_handle_t *gfxHandle)
{
zjs_gfx_touch_pixels(x, y, w, h, color, gfxHandle);
for (u8_t cbyte = 0; cbyte < COLORBYTES; cbyte++) {
@@ -294,20 +306,23 @@ static void zjs_gfx_fill_rect_priv (int32_t x, int32_t y, u32_t w, u32_t h, u8_t
}
// Draws the rectangles needed to create the given char
-static jerry_value_t zjs_gfx_draw_char_priv(u32_t x, u32_t y, char c, u8_t color[], u32_t size, gfx_handle_t *gfxHandle)
+static jerry_value_t zjs_gfx_draw_char_priv(u32_t x, u32_t y, char c,
+ u8_t color[], u32_t size,
+ gfx_handle_t *gfxHandle)
{
- u32_t asciiIndex = (u8_t)c - 32; // To save size our font doesn't include the first 32 chars
+ // To save size our font doesn't include the first 32 chars
+ u32_t asciiIndex = (u8_t)c - 32;
// Check that character is supported
if (asciiIndex < 0 || asciiIndex > 93) {
ERR_PRINT("GFX doesn't support '%c'\n", c);
- asciiIndex = 31; // Set char to ?
+ asciiIndex = 31; // Set char to ?
}
u8_t fontBytes = font_data_descriptors[asciiIndex][0] * 2;
u16_t index = font_data_descriptors[asciiIndex][1];
zjs_buffer_t *charBuf = NULL;
- ZVAL charBufObj = zjs_buffer_create(fontBytes, &charBuf);
+ ZVAL charBufObj = zjs_buffer_create(fontBytes, &charBuf);
if (charBuf) {
for (int i = 0; i < fontBytes; i++) {
@@ -315,11 +330,12 @@ static jerry_value_t zjs_gfx_draw_char_priv(u32_t x, u32_t y, char c, u8_t color
}
}
- for(int i = 0; i < fontBytes; i+=2) {
- u16_t line = (((u16_t)charBuf->buffer[i]) << 8) | charBuf->buffer[i+1];
- for(int j = 0; j < 16; j++) {
- if((line >> j) & 1) {
- int recX = x + (i/2) * size;
+ for (int i = 0; i < fontBytes; i += 2) {
+ u16_t line = (((u16_t)charBuf->buffer[i]) << 8) |
+ charBuf->buffer[i + 1];
+ for (int j = 0; j < 16; j++) {
+ if ((line >> j) & 1) {
+ int recX = x + (i / 2) * size;
int recY = y + j * size;
// Draw each bit
zjs_gfx_draw_pixels(recX, recY, size, size, color, gfxHandle);
@@ -354,7 +370,8 @@ static ZJS_DECL_FUNC(zjs_gfx_fill_rect)
ZJS_GET_HANDLE(this, gfx_handle_t, handle, gfx_type_info);
gfx_data_t argData;
args_to_data(&argData, argc, argv);
- zjs_gfx_draw_pixels(argData.coords[0], argData.coords[1], argData.coords[2], argData.coords[3], argData.color, handle);
+ zjs_gfx_draw_pixels(argData.coords[0], argData.coords[1], argData.coords[2],
+ argData.coords[3], argData.color, handle);
return ZJS_UNDEFINED;
}
@@ -371,7 +388,8 @@ static ZJS_DECL_FUNC(zjs_gfx_draw_pixel)
ZJS_GET_HANDLE(this, gfx_handle_t, handle, gfx_type_info);
gfx_data_t argData;
args_to_data(&argData, argc, argv);
- zjs_gfx_draw_pixels(argData.coords[0], argData.coords[1], 1, 1, argData.color, handle);
+ zjs_gfx_draw_pixels(argData.coords[0], argData.coords[1], 1, 1,
+ argData.color, handle);
return ZJS_UNDEFINED;
}
@@ -387,12 +405,17 @@ static ZJS_DECL_FUNC(zjs_gfx_draw_line)
//
// effects: Draws a line on the screen
- ZJS_VALIDATE_ARGS(Z_NUMBER, Z_NUMBER, Z_NUMBER, Z_NUMBER, Z_ARRAY, Z_OPTIONAL Z_NUMBER);
+ ZJS_VALIDATE_ARGS(Z_NUMBER, Z_NUMBER, Z_NUMBER, Z_NUMBER, Z_ARRAY,
+ Z_OPTIONAL Z_NUMBER);
ZJS_GET_HANDLE(this, gfx_handle_t, handle, gfx_type_info);
gfx_data_t argData;
args_to_data(&argData, argc, argv);
- int xLen = argData.coords[2] > argData.coords[0] ? argData.coords[2] - argData.coords[0] + 1 : argData.coords[0] - argData.coords[2] + 1;
- int yLen = argData.coords[3] > argData.coords[1] ? argData.coords[3] - argData.coords[1] + 1 : argData.coords[1] - argData.coords[3] + 1;
+ int xLen = argData.coords[2] > argData.coords[0]
+ ? argData.coords[2] - argData.coords[0] + 1
+ : argData.coords[0] - argData.coords[2] + 1;
+ int yLen = argData.coords[3] > argData.coords[1]
+ ? argData.coords[3] - argData.coords[1] + 1
+ : argData.coords[1] - argData.coords[3] + 1;
bool neg = false;
if (xLen <= yLen) {
@@ -406,15 +429,17 @@ static ZJS_DECL_FUNC(zjs_gfx_draw_line)
argData.coords[3] = tmp;
}
// Line is going up
- if (argData.coords[3] < argData.coords[1])
- neg = true;
+ if (argData.coords[3] < argData.coords[1]) {
+ neg = true;
+ }
int32_t pos;
- if (argData.coords[0] == argData.coords[2] && argData.coords[1] > argData.coords[3])
+ if (argData.coords[0] == argData.coords[2] &&
+ argData.coords[1] > argData.coords[3]) {
pos = argData.coords[3];
- else
+ } else {
pos = argData.coords[1];
-
+ }
u32_t step = yLen / xLen;
u32_t trueStep = (yLen * 100) / xLen;
u32_t stepRemain = trueStep - (step * 100);
@@ -425,16 +450,15 @@ static ZJS_DECL_FUNC(zjs_gfx_draw_line)
if (leftoverStep > 100) {
currStep = step + 1;
leftoverStep -= 100;
- }
- else {
+ } else {
currStep = step;
}
- zjs_gfx_draw_pixels(x, pos, argData.size, currStep, argData.color, handle);
+ zjs_gfx_draw_pixels(x, pos, argData.size, currStep, argData.color,
+ handle);
pos = neg == false ? pos + currStep : pos - currStep;
leftoverStep += stepRemain;
}
- }
- else {
+ } else {
// We always draw left to right, swap if argData.coords[1] is larger
if (argData.coords[1] > argData.coords[3]) {
int32_t tmp = argData.coords[0];
@@ -449,11 +473,12 @@ static ZJS_DECL_FUNC(zjs_gfx_draw_line)
neg = true;
int32_t pos;
- if (argData.coords[1] == argData.coords[3] && argData.coords[0] > argData.coords[2])
+ if (argData.coords[1] == argData.coords[3] &&
+ argData.coords[0] > argData.coords[2]) {
pos = argData.coords[2];
- else
+ } else {
pos = argData.coords[0];
-
+ }
u32_t step = xLen / yLen;
u32_t trueStep = (xLen * 100) / yLen;
u32_t stepRemain = trueStep - (step * 100);
@@ -463,11 +488,11 @@ static ZJS_DECL_FUNC(zjs_gfx_draw_line)
if (leftoverStep > 100) {
currStep = step + 1;
leftoverStep -= 100;
- }
- else {
+ } else {
currStep = step;
}
- zjs_gfx_draw_pixels(pos, y, currStep, argData.size, argData.color, handle);
+ zjs_gfx_draw_pixels(pos, y, currStep, argData.size, argData.color,
+ handle);
pos = neg == false ? pos + currStep : pos - currStep;
leftoverStep += stepRemain;
}
@@ -486,11 +511,13 @@ static ZJS_DECL_FUNC(zjs_gfx_draw_v_line)
//
// effects: Draws a vertical line on the screen.
- ZJS_VALIDATE_ARGS(Z_NUMBER, Z_NUMBER, Z_NUMBER, Z_ARRAY, Z_OPTIONAL Z_NUMBER);
+ ZJS_VALIDATE_ARGS(Z_NUMBER, Z_NUMBER, Z_NUMBER, Z_ARRAY,
+ Z_OPTIONAL Z_NUMBER);
ZJS_GET_HANDLE(this, gfx_handle_t, handle, gfx_type_info);
gfx_data_t argData;
args_to_data(&argData, argc, argv);
- zjs_gfx_draw_pixels(argData.coords[0], argData.coords[1], argData.size, argData.coords[2], argData.color, handle);
+ zjs_gfx_draw_pixels(argData.coords[0], argData.coords[1], argData.size,
+ argData.coords[2], argData.color, handle);
return ZJS_UNDEFINED;
}
@@ -505,11 +532,13 @@ static ZJS_DECL_FUNC(zjs_gfx_draw_h_line)
//
// effects: Draws a horizontal line on the screen
- ZJS_VALIDATE_ARGS(Z_NUMBER, Z_NUMBER, Z_NUMBER, Z_ARRAY, Z_OPTIONAL Z_NUMBER);
+ ZJS_VALIDATE_ARGS(Z_NUMBER, Z_NUMBER, Z_NUMBER, Z_ARRAY,
+ Z_OPTIONAL Z_NUMBER);
ZJS_GET_HANDLE(this, gfx_handle_t, handle, gfx_type_info);
gfx_data_t argData;
args_to_data(&argData, argc, argv);
- zjs_gfx_draw_pixels(argData.coords[0], argData.coords[1], argData.coords[2], argData.size, argData.color, handle);
+ zjs_gfx_draw_pixels(argData.coords[0], argData.coords[1], argData.coords[2],
+ argData.size, argData.color, handle);
return ZJS_UNDEFINED;
}
@@ -525,14 +554,21 @@ static ZJS_DECL_FUNC(zjs_gfx_draw_rect)
//
// effects: Draws a rectangle on the screen
- ZJS_VALIDATE_ARGS(Z_NUMBER, Z_NUMBER, Z_NUMBER, Z_NUMBER, Z_ARRAY, Z_OPTIONAL Z_NUMBER);
+ ZJS_VALIDATE_ARGS(Z_NUMBER, Z_NUMBER, Z_NUMBER, Z_NUMBER, Z_ARRAY,
+ Z_OPTIONAL Z_NUMBER);
ZJS_GET_HANDLE(this, gfx_handle_t, handle, gfx_type_info);
gfx_data_t argData;
args_to_data(&argData, argc, argv);
- zjs_gfx_draw_pixels(argData.coords[0], argData.coords[1], argData.coords[2], argData.size, argData.color, handle);
- zjs_gfx_draw_pixels(argData.coords[0], argData.coords[1] + argData.coords[3] - argData.size, argData.coords[2], argData.size, argData.color, handle);
- zjs_gfx_draw_pixels(argData.coords[0], argData.coords[1], argData.size, argData.coords[3], argData.color, handle);
- zjs_gfx_draw_pixels(argData.coords[0] + argData.coords[2] - argData.size, argData.coords[1], argData.size, argData.coords[3], argData.color, handle);
+ zjs_gfx_draw_pixels(argData.coords[0], argData.coords[1], argData.coords[2],
+ argData.size, argData.color, handle);
+ zjs_gfx_draw_pixels(argData.coords[0],
+ argData.coords[1] + argData.coords[3] - argData.size,
+ argData.coords[2], argData.size, argData.color, handle);
+ zjs_gfx_draw_pixels(argData.coords[0], argData.coords[1], argData.size,
+ argData.coords[3], argData.color, handle);
+ zjs_gfx_draw_pixels(argData.coords[0] + argData.coords[2] - argData.size,
+ argData.coords[1], argData.size, argData.coords[3],
+ argData.color, handle);
return ZJS_UNDEFINED;
}
@@ -548,11 +584,14 @@ static ZJS_DECL_FUNC(zjs_gfx_draw_char)
//
// effects: Draws a character on the screen
- ZJS_VALIDATE_ARGS(Z_NUMBER, Z_NUMBER, Z_STRING, Z_ARRAY, Z_OPTIONAL Z_NUMBER);
+ ZJS_VALIDATE_ARGS(Z_NUMBER, Z_NUMBER, Z_STRING, Z_ARRAY,
+ Z_OPTIONAL Z_NUMBER);
ZJS_GET_HANDLE(this, gfx_handle_t, handle, gfx_type_info);
gfx_data_t argData;
args_to_data(&argData, argc, argv);
- return zjs_gfx_draw_char_priv(argData.coords[0], argData.coords[1], argData.text[0], argData.color, argData.size, handle);
+ return zjs_gfx_draw_char_priv(argData.coords[0], argData.coords[1],
+ argData.text[0], argData.color, argData.size,
+ handle);
}
static ZJS_DECL_FUNC(zjs_gfx_draw_string)
@@ -566,7 +605,8 @@ static ZJS_DECL_FUNC(zjs_gfx_draw_string)
//
// effects: Draws a character on the screen
- ZJS_VALIDATE_ARGS(Z_NUMBER, Z_NUMBER, Z_STRING, Z_ARRAY, Z_OPTIONAL Z_NUMBER);
+ ZJS_VALIDATE_ARGS(Z_NUMBER, Z_NUMBER, Z_STRING, Z_ARRAY,
+ Z_OPTIONAL Z_NUMBER);
ZJS_GET_HANDLE(this, gfx_handle_t, handle, gfx_type_info);
gfx_data_t argData;
args_to_data(&argData, argc, argv);
@@ -574,20 +614,23 @@ static ZJS_DECL_FUNC(zjs_gfx_draw_string)
u32_t x = argData.coords[0];
for (u8_t i = 0; i < argData.textSize; i++) {
- u32_t asciiIndex = (u8_t)argData.text[i] - 32; // To save size our font doesn't include the first 32 chars
+ // To save size our font doesn't include the first 32 chars
+ u32_t asciiIndex = (u8_t)argData.text[i] - 32;
// Check that character is supported
if (asciiIndex < 0 || asciiIndex > 93) {
ERR_PRINT("GFX doesn't support '%c'\n", argData.text[i]);
- asciiIndex = 31; // Set char to ?
+ asciiIndex = 31; // Set char to ?
}
- ret = zjs_gfx_draw_char_priv(x, argData.coords[1], argData.text[i], argData.color, argData.size, handle);
- if (jerry_value_has_error_flag (ret)) {
+ ret = zjs_gfx_draw_char_priv(x, argData.coords[1], argData.text[i],
+ argData.color, argData.size, handle);
+ if (jerry_value_has_error_flag(ret)) {
return ret;
}
- u8_t charWidth = font_data_descriptors[asciiIndex][0] + 1; // Add a one for space
+ // Add a one for space
+ u8_t charWidth = font_data_descriptors[asciiIndex][0] + 1;
x = x + (charWidth * argData.size);
}
return ret;
@@ -604,7 +647,8 @@ static ZJS_DECL_FUNC(zjs_gfx_set_cb)
//
// effects: Initializes the GFX module
- ZJS_VALIDATE_ARGS(Z_NUMBER, Z_NUMBER, Z_FUNCTION, Z_FUNCTION, Z_BOOL, Z_OPTIONAL Z_OBJECT);
+ ZJS_VALIDATE_ARGS(Z_NUMBER, Z_NUMBER, Z_FUNCTION, Z_FUNCTION, Z_BOOL,
+ Z_OPTIONAL Z_OBJECT);
gfx_handle_t *handle = zjs_malloc(sizeof(gfx_handle_t));
if (!handle) {
@@ -628,8 +672,7 @@ static ZJS_DECL_FUNC(zjs_gfx_set_cb)
u32_t totalPixels = handle->screenW * handle->screenH * COLORBYTES;
handle->pixels = zjs_buffer_create(totalPixels, &handle->pixelsPtr);
zjs_gfx_draw_pixels = zjs_gfx_touch_pixels;
- }
- else {
+ } else {
handle->pixels = 0;
handle->pixelsPtr = NULL;
zjs_gfx_draw_pixels = zjs_gfx_fill_rect_priv;
@@ -648,7 +691,7 @@ static void zjs_gfx_cleanup(void *native)
}
static const jerry_object_native_info_t gfx_module_type_info = {
- .free_cb = zjs_gfx_cleanup
+ .free_cb = zjs_gfx_cleanup
};
static jerry_value_t zjs_gfx_init()
diff --git a/src/zjs_gpio.c b/src/zjs_gpio.c
index 58f9c3c..4274d22 100644
--- a/src/zjs_gpio.c
+++ b/src/zjs_gpio.c
@@ -1,4 +1,4 @@
-// Copyright (c) 2016-2017, Intel Corporation.
+// Copyright (c) 2016-2018, Intel Corporation.
// C includes
#include <stdlib.h>
@@ -224,11 +224,9 @@ static ZJS_DECL_FUNC(zjs_gpio_open)
int pin = zjs_board_find_gpio(pin_val, devname, 20);
if (pin == FIND_PIN_INVALID) {
return TYPE_ERROR("bad pin argument");
- }
- else if (pin == FIND_DEVICE_FAILURE) {
+ } else if (pin == FIND_DEVICE_FAILURE) {
return zjs_error("device not found");
- }
- else if (pin < 0) {
+ } else if (pin < 0) {
return zjs_error("pin not found");
}
DEVICE gpiodev = device_get_binding(devname);
@@ -333,10 +331,11 @@ static ZJS_DECL_FUNC(zjs_gpio_open)
return pin_obj;
}
-static void zjs_gpio_cleanup(void *native) {
- zjs_gpio_mock_cleanup();
- jerry_release_value(gpio_pin_prototype);
- gpio_pin_prototype = 0;
+static void zjs_gpio_cleanup(void *native)
+{
+ zjs_gpio_mock_cleanup();
+ jerry_release_value(gpio_pin_prototype);
+ gpio_pin_prototype = 0;
}
static const jerry_object_native_info_t gpio_module_type_info = {
diff --git a/src/zjs_grove_lcd.c b/src/zjs_grove_lcd.c
index 2117bce..7e2bba4 100644
--- a/src/zjs_grove_lcd.c
+++ b/src/zjs_grove_lcd.c
@@ -1,4 +1,4 @@
-// Copyright (c) 2016-2017, Intel Corporation.
+// Copyright (c) 2016-2018, Intel Corporation.
#ifdef BUILD_MODULE_GROVE_LCD
#ifndef QEMU_BUILD
@@ -178,7 +178,7 @@ static void zjs_grove_lcd_cleanup(void *native)
}
static const jerry_object_native_info_t grove_lcd_module_type_info = {
- .free_cb = zjs_grove_lcd_cleanup
+ .free_cb = zjs_grove_lcd_cleanup
};
// Note. setInputState is not supported in Zephyr driver yet
@@ -273,7 +273,8 @@ static jerry_value_t zjs_grove_lcd_init()
jerry_release_value(val);
// Set up cleanup function for when the object gets freed
- jerry_set_object_native_pointer(glcd_obj, NULL, &grove_lcd_module_type_info);
+ jerry_set_object_native_pointer(glcd_obj, NULL,
+ &grove_lcd_module_type_info);
return glcd_obj;
}
diff --git a/src/zjs_grove_lcd_ipm.c b/src/zjs_grove_lcd_ipm.c
index 9ee91ad..36c7247 100644
--- a/src/zjs_grove_lcd_ipm.c
+++ b/src/zjs_grove_lcd_ipm.c
@@ -1,4 +1,4 @@
-// Copyright (c) 2016-2017, Intel Corporation.
+// Copyright (c) 2016-2018, Intel Corporation.
#ifdef BUILD_MODULE_GROVE_LCD
#ifndef QEMU_BUILD
@@ -247,7 +247,7 @@ static void zjs_grove_lcd_cleanup(void *native)
}
static const jerry_object_native_info_t grove_lcd_module_type_info = {
- .free_cb = zjs_grove_lcd_cleanup
+ .free_cb = zjs_grove_lcd_cleanup
};
// Note. setInputState is not supported in Zephyr driver yet
@@ -347,7 +347,8 @@ static jerry_value_t zjs_grove_lcd_init()
jerry_release_value(val);
// Set up cleanup function for when the object gets freed
- jerry_set_object_native_pointer(glcd_obj, NULL, &grove_lcd_module_type_info);
+ jerry_set_object_native_pointer(glcd_obj, NULL,
+ &grove_lcd_module_type_info);
return glcd_obj;
}
diff --git a/src/zjs_i2c.c b/src/zjs_i2c.c
index 940537c..3d878d1 100644
--- a/src/zjs_i2c.c
+++ b/src/zjs_i2c.c
@@ -1,4 +1,4 @@
-// Copyright (c) 2016-2017, Intel Corporation.
+// Copyright (c) 2016-2018, Intel Corporation.
#ifndef QEMU_BUILD
// C includes
@@ -191,7 +191,7 @@ static void zjs_i2c_cleanup(void *native)
}
static const jerry_object_native_info_t i2c_module_type_info = {
- .free_cb = zjs_i2c_cleanup
+ .free_cb = zjs_i2c_cleanup
};
static jerry_value_t zjs_i2c_init()
diff --git a/src/zjs_modules.c b/src/zjs_modules.c
index fc9ec2f..ba1b1e3 100644
--- a/src/zjs_modules.c
+++ b/src/zjs_modules.c
@@ -43,7 +43,8 @@ struct routine_map svc_routine_map[NUM_SERVICE_ROUTINES];
#ifdef ZJS_ASHELL
// Eval the JavaScript, and return the module.
-static bool javascript_eval_code(const char *source_buffer, ssize_t size, jerry_value_t *ret_val)
+static bool javascript_eval_code(const char *source_buffer, ssize_t size,
+ jerry_value_t *ret_val)
{
(*ret_val) = jerry_eval((jerry_char_t *)source_buffer, size, false);
if (jerry_value_has_error_flag(*ret_val)) {
@@ -55,7 +56,8 @@ static bool javascript_eval_code(const char *source_buffer, ssize_t size, jerry_
#endif
// Find the module on the filestystem
-static bool load_js_module_fs(const jerry_value_t module_name, jerry_value_t *result)
+static bool load_js_module_fs(const jerry_value_t module_name,
+ jerry_value_t *result)
{
// Currently searching the filesystem is only supported on ashell
#ifdef ZJS_ASHELL
@@ -77,14 +79,14 @@ static bool load_js_module_fs(const jerry_value_t module_name, jerry_value_t *re
#else
return false;
#endif
-
}
-#else // ZJS_LINUX_BUILD
+#else // ZJS_LINUX_BUILD
/****************************************
* Linux JavaScript module resolver
*****************************************/
// Find the module on the filestystem
-static bool load_js_module_fs(const jerry_value_t module_name, jerry_value_t *result)
+static bool load_js_module_fs(const jerry_value_t module_name,
+ jerry_value_t *result)
{
// Linux can pass in the script at runtime, so we have to read in/parse any
// JS modules now rather than at compile time
@@ -111,8 +113,7 @@ static bool load_js_module_fs(const jerry_value_t module_name, jerry_value_t *re
if (jerry_value_has_error_flag(*result)) {
ERR_PRINT("failed to evaluate JS\n");
ret = false;
- }
- else {
+ } else {
ret = true;
}
zjs_free(str);
@@ -121,7 +122,8 @@ static bool load_js_module_fs(const jerry_value_t module_name, jerry_value_t *re
#endif // !ZJS_LINUX_BUILD
// Try to find the module in the main JS file
-static bool load_js_module_obj(const jerry_value_t module_name, jerry_value_t *result)
+static bool load_js_module_obj(const jerry_value_t module_name,
+ jerry_value_t *result)
{
jerry_size_t module_size = jerry_get_utf8_string_size(module_name) + 1;
char module[module_size];
@@ -175,9 +177,9 @@ static jerryx_module_resolver_t load_js_resolver =
// These execute in order until a matching module is found
static const jerryx_module_resolver_t *resolvers[] =
{
- &jerryx_module_native_resolver, // Check for a native module
- &load_js_resolver, // Check for a JS module in the code
- &load_fs_resolver // Check for a JS module on the FS
+ &jerryx_module_native_resolver, // Check for a native module
+ &load_js_resolver, // Check for a JS module in the code
+ &load_fs_resolver // Check for a JS module on the FS
};
// native require handler
@@ -199,8 +201,7 @@ static ZJS_DECL_FUNC(native_require_handler)
if (jerry_value_has_error_flag(result)) {
DBG_PRINT("Couldn't load module %s\n", module);
return NOTSUPPORTED_ERROR("Module not found");
- }
- else {
+ } else {
DBG_PRINT("Module %s loaded\n", module);
}
return result;
@@ -325,7 +326,8 @@ void zjs_register_service_routine(void *handle, zjs_service_routine func)
return;
}
-void zjs_unregister_service_routine(zjs_service_routine func) {
+void zjs_unregister_service_routine(zjs_service_routine func)
+{
for (int i = 0; i < num_routines; i++) {
if (svc_routine_map[i].func == func) {
svc_routine_map[i].handle = NULL;
diff --git a/src/zjs_net.c b/src/zjs_net.c
index fbf3280..bc01cf0 100644
--- a/src/zjs_net.c
+++ b/src/zjs_net.c
@@ -150,28 +150,32 @@ static server_handle_t *servers = &no_server;
// mutex to ensure only one thread uses handle lists at time
static struct k_mutex socket_mutex;
-#define S_LOCK() \
- LPRINT("Sockets lock..."); \
- k_mutex_lock(&socket_mutex, K_FOREVER); \
+#define S_LOCK() \
+ LPRINT("Sockets lock..."); \
+ k_mutex_lock(&socket_mutex, K_FOREVER); \
LPRINT("Sockets locked.")
-#define S_UNLOCK() \
- LPRINT("Sockets unlock..."); \
- k_mutex_unlock(&socket_mutex); \
+#define S_UNLOCK() \
+ LPRINT("Sockets unlock..."); \
+ k_mutex_unlock(&socket_mutex); \
LPRINT("Sockets unlocked.")
// get the socket handle from the object or NULL
-#define GET_SOCK_HANDLE(obj, var) \
+#define GET_SOCK_HANDLE(obj, var) \
sock_handle_t *var = (sock_handle_t *)zjs_event_get_user_handle(obj);
// get the socket handle or return a JS error
-#define GET_SOCK_HANDLE_JS(obj, var) \
- sock_handle_t *var = (sock_handle_t *)zjs_event_get_user_handle(obj); \
- if (!var) { return zjs_error("no socket handle"); }
+#define GET_SOCK_HANDLE_JS(obj, var) \
+ sock_handle_t *var = (sock_handle_t *)zjs_event_get_user_handle(obj); \
+ if (!var) { \
+ return zjs_error("no socket handle"); \
+ }
// get the net handle or return a JS error
#define GET_SERVER_HANDLE_JS(obj, var) \
server_handle_t *var = (server_handle_t *)zjs_event_get_user_handle(obj); \
- if (!var) { return zjs_error("no socket handle"); }
+ if (!var) { \
+ return zjs_error("no socket handle"); \
+ }
#define CHECK(x) \
ret = (x); \
@@ -198,13 +202,11 @@ static void zjs_copy_sockaddr(struct sockaddr *dst, struct sockaddr *src,
ZJS_ASSERT(!len || len == sizeof(struct sockaddr_in),
"expected IPv4 length");
*(struct sockaddr_in *)dst = *(struct sockaddr_in *)src;
- }
- else if (src->sa_family == AF_INET6) {
+ } else if (src->sa_family == AF_INET6) {
ZJS_ASSERT(!len || len == sizeof(struct sockaddr_in6),
"expected IPv6 length");
*(struct sockaddr_in6 *)dst = *(struct sockaddr_in6 *)src;
- }
- else {
+ } else {
ZJS_ASSERT(false, "invalid sockaddr struct");
}
}
@@ -344,8 +346,7 @@ static void release_close(void *handle, jerry_value_t argv[], u32_t argc)
// no more sockets open and not listening, close server
close_server(server_h);
}
- }
- else {
+ } else {
// for client sockets, we did get and need to do put
net_context_put(h->tcp_sock);
}
@@ -509,8 +510,7 @@ static void clear_closed(const void *buffer, u32_t length)
DBG_PRINT("cleared early closed for server %p\n", clear->server_h);
clear->server_h->early_closed = NULL;
- sock_handle_t *handle = find_connection(clear->server_h,
- clear->context);
+ sock_handle_t *handle = find_connection(clear->server_h, clear->context);
ZJS_ASSERT(handle, "handle not found");
if (handle) {
// clear context reference out of the handle so it no longer shows
@@ -559,8 +559,7 @@ static void tcp_received(struct net_context *context,
handle->closing = 1;
zjs_defer_emit_event(handle->socket, "close", NULL, 0, NULL,
release_close);
- }
- else {
+ } else {
ZJS_ASSERT(server_h != &no_server,
"client connections shouldn't get here");
if (server_h->early_closed) {
@@ -568,8 +567,7 @@ static void tcp_received(struct net_context *context,
// handle to remember one early-closed socket; could be
// increased to an array of them if need be
ERR_PRINT("Socket closed early with another in process\n");
- }
- else {
+ } else {
DBG_PRINT("socket closed before data received\n");
DBG_PRINT("marking server %p with early closed %p\n",
server_h, context);
@@ -885,8 +883,7 @@ static void accept_connection(const void *buffer, u32_t length)
// add new socket to list
S_LOCK();
- ZJS_LIST_PREPEND(sock_handle_t, accept->server_h->connections,
- sock_handle);
+ ZJS_LIST_PREPEND(sock_handle_t, accept->server_h->connections, sock_handle);
S_UNLOCK();
zjs_emit_event(accept->server_h->server, "connection", &sock, 1);
@@ -1169,8 +1166,7 @@ static bool connect_callback(void *h, jerry_value_t argv[], u32_t *argc,
FTRACE("h = %p, buffer = %p, bytes = %d\n", h, buffer, bytes);
sock_handle_t *handle = (sock_handle_t *)h;
zjs_obj_add_boolean(handle->socket, "connecting", false);
- zjs_add_event_listener(handle->socket, "connect",
- handle->connect_listener);
+ zjs_add_event_listener(handle->socket, "connect", handle->connect_listener);
return true;
}
@@ -1469,7 +1465,7 @@ static void zjs_net_cleanup(void *native)
}
static const jerry_object_native_info_t net_module_type_info = {
- .free_cb = zjs_net_cleanup
+ .free_cb = zjs_net_cleanup
};
static jerry_value_t zjs_net_init()
diff --git a/src/zjs_net_config.c b/src/zjs_net_config.c
index 96535d4..ecde99f 100644
--- a/src/zjs_net_config.c
+++ b/src/zjs_net_config.c
@@ -8,8 +8,8 @@ static char FTRACE_PREFIX[] = "net";
#include <net/net_if.h>
#ifdef BUILD_MODULE_NET_CONFIG
-#include <net/net_mgmt.h>
#include <net/net_context.h>
+#include <net/net_mgmt.h>
#endif
#ifdef CONFIG_NET_L2_BT
@@ -18,10 +18,10 @@ static char FTRACE_PREFIX[] = "net";
#include <gatt/ipss.h>
#endif
-#include "zjs_util.h"
-#include "zjs_net_config.h"
#include "zjs_callbacks.h"
#include "zjs_event.h"
+#include "zjs_net_config.h"
+#include "zjs_util.h"
#ifndef BUILD_MODULE_NET_CONFIG
static u8_t net_enabled = 0;
@@ -272,7 +272,7 @@ static ZJS_DECL_FUNC(dhcp)
struct net_if *iface;
net_mgmt_init_event_callback(&dhcp_cb, dhcp_callback,
- NET_EVENT_IPV4_ADDR_ADD);
+ NET_EVENT_IPV4_ADDR_ADD);
net_mgmt_add_event_callback(&dhcp_cb);
iface = net_if_get_default();
@@ -319,16 +319,14 @@ static ZJS_DECL_FUNC(set_ip)
if (net_addr_pton(AF_INET6, str, &tmp.sin6_addr) < 0) {
// check if v4
struct sockaddr_in tmp1 = { 0 };
- if(net_addr_pton(AF_INET,
- str,
- &tmp1.sin_addr) < 0) {
+ if (net_addr_pton(AF_INET, str, &tmp1.sin_addr) < 0) {
return TYPE_ERROR("String was not an IP address");
} else {
#ifndef CONFIG_NET_IPV4
return NOTSUPPORTED_ERROR("IPv4 not supported");
#else
if (!net_if_ipv4_addr_add(net_if_get_default(), &tmp1.sin_addr,
- NET_ADDR_MANUAL, 0)) {
+ NET_ADDR_MANUAL, 0)) {
return jerry_create_boolean(false);
}
#endif
@@ -338,7 +336,7 @@ static ZJS_DECL_FUNC(set_ip)
return NOTSUPPORTED_ERROR("IPv6 not supported");
#else
if (!net_if_ipv6_addr_add(net_if_get_default(), &tmp.sin6_addr,
- NET_ADDR_MANUAL, 0)) {
+ NET_ADDR_MANUAL, 0)) {
return jerry_create_boolean(false);
}
#endif
@@ -351,7 +349,7 @@ static jerry_value_t config;
static struct net_mgmt_event_callback cb;
static void iface_event(struct net_mgmt_event_callback *cb,
- u32_t mgmt_event, struct net_if *iface)
+ u32_t mgmt_event, struct net_if *iface)
{
FTRACE("cb = %p, mgmt_event = %x, iface = %p\n", cb, mgmt_event, iface);
if (mgmt_event == NET_EVENT_IF_UP) {
@@ -382,7 +380,7 @@ static jerry_value_t zjs_net_config_init(void)
}
// notify when networking goes up/down
net_mgmt_init_event_callback(&cb, iface_event,
- NET_EVENT_IF_UP | NET_EVENT_IF_DOWN);
+ NET_EVENT_IF_UP | NET_EVENT_IF_DOWN);
net_mgmt_add_event_callback(&cb);
#ifdef CONFIG_NET_L2_BT
diff --git a/src/zjs_ocf_client.c b/src/zjs_ocf_client.c
index 8f11487..4e5a7f3 100644
--- a/src/zjs_ocf_client.c
+++ b/src/zjs_ocf_client.c
@@ -1,4 +1,4 @@
-// Copyright (c) 2016-2017, Intel Corporation.
+// Copyright (c) 2016-2018, Intel Corporation.
#ifdef BUILD_MODULE_OCF
@@ -120,9 +120,9 @@ static char *create_url(const char *uuid, const char *path)
}
#ifdef DEBUG_BUILD
-#define do_print \
+#define do_print \
do_prefix(p); \
- ZJS_PRINT \
+ ZJS_PRINT
static void do_prefix(int p)
{
@@ -148,7 +148,7 @@ static void print_props_data(int prefix, oc_rep_t *data)
case BYTE_STRING:
case STRING:
do_print("%s: %s\n", oc_string(rep->name),
- oc_string(rep->value.string));
+ oc_string(rep->value.string));
break;
case OBJECT:
do_print("%s: {\n", oc_string(rep->name));
@@ -157,10 +157,10 @@ static void print_props_data(int prefix, oc_rep_t *data)
break;
case STRING_ARRAY:
do_print("%s: [", oc_string(rep->name));
- int sz = oc_string_array_get_allocated_size(rep->value.array);
+ int sz = oc_string_array_get_allocated_size(rep->value.array);
for (i = 0; i < sz; i++) {
ZJS_PRINT("\"%s\",",
- oc_string_array_get_item(rep->value.array, i));
+ oc_string_array_get_item(rep->value.array, i));
}
ZJS_PRINT("]\n");
break;
@@ -188,23 +188,21 @@ static void print_props_data(int prefix, oc_rep_t *data)
}
ZJS_PRINT("]\n");
break;
- case OBJECT_ARRAY:
- {
- oc_rep_t *iter = rep->value.object_array;
- do_print("%s: [", oc_string(rep->name));
- p++;
- while (iter) {
- ZJS_PRINT("{\n");
- print_props_data(p + 1, iter->value.object);
- iter = iter->next;
- do_print("}");
- ZJS_PRINT(",");
- }
- ZJS_PRINT("\n");
- p--;
- do_print("]\n");
+ case OBJECT_ARRAY: {
+ oc_rep_t *iter = rep->value.object_array;
+ do_print("%s: [", oc_string(rep->name));
+ p++;
+ while (iter) {
+ ZJS_PRINT("{\n");
+ print_props_data(p + 1, iter->value.object);
+ iter = iter->next;
+ do_print("}");
+ ZJS_PRINT(",");
}
- break;
+ ZJS_PRINT("\n");
+ p--;
+ do_print("]\n");
+ } break;
default:
break;
}
@@ -759,12 +757,10 @@ static void ocf_get_platform_info_handler(oc_client_response_t *data)
"manufacturerName",
oc_string(rep->value.string));
} else if (strequal(oc_string(rep->name), "pi")) {
- zjs_obj_add_readonly_string(platform_info,
- "id",
+ zjs_obj_add_readonly_string(platform_info, "id",
oc_string(rep->value.string));
} else if (strequal(oc_string(rep->name), "mnmo")) {
- zjs_obj_add_readonly_string(platform_info,
- "model",
+ zjs_obj_add_readonly_string(platform_info, "model",
oc_string(rep->value.string));
} else if (strequal(oc_string(rep->name), "mndt")) {
zjs_obj_add_readonly_string(platform_info,
@@ -775,8 +771,7 @@ static void ocf_get_platform_info_handler(oc_client_response_t *data)
"platformVersion",
oc_string(rep->value.string));
} else if (strequal(oc_string(rep->name), "mnos")) {
- zjs_obj_add_readonly_string(platform_info,
- "osVersion",
+ zjs_obj_add_readonly_string(platform_info, "osVersion",
oc_string(rep->value.string));
} else if (strequal(oc_string(rep->name), "mnfv")) {
zjs_obj_add_readonly_string(platform_info,
@@ -787,8 +782,7 @@ static void ocf_get_platform_info_handler(oc_client_response_t *data)
"manufacturerURL",
oc_string(rep->value.string));
} else if (strequal(oc_string(rep->name), "mnsl")) {
- zjs_obj_add_readonly_string(platform_info,
- "supportURL",
+ zjs_obj_add_readonly_string(platform_info, "supportURL",
oc_string(rep->value.string));
}
DBG_PRINT("%s\n", oc_string(rep->value.string));
diff --git a/src/zjs_ocf_common.c b/src/zjs_ocf_common.c
index 4494a3c..2912577 100644
--- a/src/zjs_ocf_common.c
+++ b/src/zjs_ocf_common.c
@@ -1,4 +1,4 @@
-// Copyright (c) 2016-2017, Intel Corporation.
+// Copyright (c) 2016-2018, Intel Corporation.
#ifdef BUILD_MODULE_OCF
@@ -137,7 +137,6 @@ static void zjs_ocf_encode_value_helper(jerry_value_t object, const char *name,
zjs_rep_set_text_string(encoder, name, str);
PROPS_PRINT(name, "\"%s\",", str);
}
-
}
void zjs_ocf_encode_value(jerry_value_t object)
@@ -163,93 +162,81 @@ static jerry_value_t decode_value_helper(jerry_value_t object, oc_rep_t *data)
switch (rep->type) {
case BOOL:
zjs_obj_add_boolean(object, oc_string(rep->name),
- rep->value.boolean);
+ rep->value.boolean);
break;
case INT:
zjs_obj_add_number(object, oc_string(rep->name),
- (double)rep->value.integer);
+ (double)rep->value.integer);
break;
case BYTE_STRING:
case STRING:
zjs_obj_add_string(object, oc_string(rep->name),
- oc_string(rep->value.string));
+ oc_string(rep->value.string));
break;
case DOUBLE:
zjs_obj_add_number(object, oc_string(rep->name),
- rep->value.double_p);
+ rep->value.double_p);
break;
- case STRING_ARRAY:
- {
- sz = oc_string_array_get_allocated_size(rep->value.array);
- ZVAL array = jerry_create_array(sz);
- for (i = 0; i < sz; i++) {
- ZVAL str = jerry_create_string(
- oc_string_array_get_item(rep->value.array, i));
- jerry_set_property_by_index(array, i, str);
- }
- zjs_set_property(object, oc_string(rep->name), array);
+ case STRING_ARRAY: {
+ sz = oc_string_array_get_allocated_size(rep->value.array);
+ ZVAL array = jerry_create_array(sz);
+ for (i = 0; i < sz; i++) {
+ ZVAL str = jerry_create_string(
+ oc_string_array_get_item(rep->value.array, i));
+ jerry_set_property_by_index(array, i, str);
}
- break;
- case DOUBLE_ARRAY:
- {
- sz = oc_double_array_size(rep->value.array);
- double *d_array = oc_double_array(rep->value.array);
- ZVAL array = jerry_create_array(sz);
- for (i = 0; i < sz; i++) {
- ZVAL d = jerry_create_number(d_array[i]);
- jerry_set_property_by_index(array, i, d);
- }
- zjs_set_property(object, oc_string(rep->name), array);
+ zjs_set_property(object, oc_string(rep->name), array);
+ } break;
+ case DOUBLE_ARRAY: {
+ sz = oc_double_array_size(rep->value.array);
+ double *d_array = oc_double_array(rep->value.array);
+ ZVAL array = jerry_create_array(sz);
+ for (i = 0; i < sz; i++) {
+ ZVAL d = jerry_create_number(d_array[i]);
+ jerry_set_property_by_index(array, i, d);
}
- break;
- case INT_ARRAY:
- {
- sz = oc_int_array_size(rep->value.array);
- int *i_array = oc_int_array(rep->value.array);
- ZVAL array = jerry_create_array(sz);
- for (i = 0; i < sz; i++) {
- ZVAL integer = jerry_create_number(i_array[i]);
- jerry_set_property_by_index(array, i, integer);
- }
- zjs_set_property(object, oc_string(rep->name), array);
+ zjs_set_property(object, oc_string(rep->name), array);
+ } break;
+ case INT_ARRAY: {
+ sz = oc_int_array_size(rep->value.array);
+ int *i_array = oc_int_array(rep->value.array);
+ ZVAL array = jerry_create_array(sz);
+ for (i = 0; i < sz; i++) {
+ ZVAL integer = jerry_create_number(i_array[i]);
+ jerry_set_property_by_index(array, i, integer);
}
- break;
- case BOOL_ARRAY:
- {
- sz = oc_bool_array_size(rep->value.array);
- bool *b_array = oc_bool_array(rep->value.array);
- ZVAL array = jerry_create_array(sz);
- for (i = 0; i < sz; i++) {
- ZVAL b = jerry_create_number(b_array[i]);
- jerry_set_property_by_index(array, i, b);
- }
- zjs_set_property(object, oc_string(rep->name), array);
+ zjs_set_property(object, oc_string(rep->name), array);
+ } break;
+ case BOOL_ARRAY: {
+ sz = oc_bool_array_size(rep->value.array);
+ bool *b_array = oc_bool_array(rep->value.array);
+ ZVAL array = jerry_create_array(sz);
+ for (i = 0; i < sz; i++) {
+ ZVAL b = jerry_create_number(b_array[i]);
+ jerry_set_property_by_index(array, i, b);
}
- break;
- case OBJECT:
- {
- jerry_value_t new_object = zjs_create_object();
- decode_value_helper(new_object, rep->value.object);
- if (!oc_string(rep->name)) {
- return new_object;
- }
- zjs_set_property(object, oc_string(rep->name), new_object);
- jerry_release_value(new_object);
+ zjs_set_property(object, oc_string(rep->name), array);
+ } break;
+ case OBJECT: {
+ jerry_value_t new_object = zjs_create_object();
+ decode_value_helper(new_object, rep->value.object);
+ if (!oc_string(rep->name)) {
+ return new_object;
}
- break;
- case OBJECT_ARRAY:
- {
- oc_rep_t *iter = rep->value.object_array;
- jerry_value_t array = jerry_create_array(0);
- while (iter) {
- ZVAL element = decode_value_helper(ZJS_UNDEFINED, iter);
- array = zjs_push_array(array, element);
- iter = iter->next;
- }
- zjs_set_property(object, oc_string(rep->name), array);
- jerry_release_value(array);
+ zjs_set_property(object, oc_string(rep->name), new_object);
+ jerry_release_value(new_object);
+ } break;
+ case OBJECT_ARRAY: {
+ oc_rep_t *iter = rep->value.object_array;
+ jerry_value_t array = jerry_create_array(0);
+ while (iter) {
+ ZVAL element = decode_value_helper(ZJS_UNDEFINED, iter);
+ array = zjs_push_array(array, element);
+ iter = iter->next;
}
- break;
+ zjs_set_property(object, oc_string(rep->name), array);
+ jerry_release_value(array);
+ } break;
default:
break;
}
@@ -535,7 +522,7 @@ static void zjs_ocf_cleanup(void *native)
}
static const jerry_object_native_info_t ocf_module_type_info = {
- .free_cb = zjs_ocf_cleanup
+ .free_cb = zjs_ocf_cleanup
};
static jerry_value_t zjs_ocf_init()
diff --git a/src/zjs_ocf_encoder.h b/src/zjs_ocf_encoder.h
index 1717f54..098efa2 100644
--- a/src/zjs_ocf_encoder.h
+++ b/src/zjs_ocf_encoder.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2016-2017, Intel Corporation.
+// Copyright (c) 2016-2018, Intel Corporation.
// Zephyr.js required its own versions of these macros from
// iotivity-constrained.
// in order to use the cbor_* API's in a dynamic way.
@@ -48,9 +48,9 @@ extern CborError g_err;
* @param key Child object (CborEncoder *)
* @param name Name of object (char *)
*/
-#define zjs_rep_set_object(object, key, name) \
- if (name) \
- g_err |= cbor_encode_text_string(object, name, strlen(name)); \
+#define zjs_rep_set_object(object, key, name) \
+ if (name) \
+ g_err |= cbor_encode_text_string(object, name, strlen(name)); \
zjs_rep_start_object(object, key)
/*
@@ -178,11 +178,11 @@ extern CborError g_err;
* @param key Name of boolean property
* @param value Value
*/
-#define zjs_rep_set_text_string(object, key, value) \
- do { \
- if (key) \
- g_err |= cbor_encode_text_string(object, key, strlen(key)); \
- g_err |= cbor_encode_text_string(object, value, strlen(value)); \
+#define zjs_rep_set_text_string(object, key, value) \
+ do { \
+ if (key) \
+ g_err |= cbor_encode_text_string(object, key, strlen(key)); \
+ g_err |= cbor_encode_text_string(object, value, strlen(value)); \
} while (0)
/*
@@ -192,11 +192,11 @@ extern CborError g_err;
* @param key Name of boolean property
* @param value Value
*/
-#define zjs_rep_set_byte_string(object, key, value) \
- do { \
- if (key) \
- g_err |= cbor_encode_text_string(object, key, strlen(key)); \
- g_err |= cbor_encode_byte_string(object, value, strlen(value)); \
+#define zjs_rep_set_byte_string(object, key, value) \
+ do { \
+ if (key) \
+ g_err |= cbor_encode_text_string(object, key, strlen(key)); \
+ g_err |= cbor_encode_byte_string(object, value, strlen(value)); \
} while (0)
#endif
diff --git a/src/zjs_ocf_server.c b/src/zjs_ocf_server.c
index a30d6d6..cf79e8f 100644
--- a/src/zjs_ocf_server.c
+++ b/src/zjs_ocf_server.c
@@ -306,7 +306,7 @@ static void ocf_get_handler(oc_request_t *request,
ZVAL request_val = create_request(h->res, OC_GET, h);
ZVAL flag = jerry_create_boolean(0);
- jerry_value_t argv[2] = {request_val, flag};
+ jerry_value_t argv[2] = { request_val, flag };
zjs_emit_event(h->res->object, "retrieve", argv, 2);
zjs_free(h->resp);
diff --git a/src/zjs_pinmux.c b/src/zjs_pinmux.c
index d11ef73..1c26655 100644
--- a/src/zjs_pinmux.c
+++ b/src/zjs_pinmux.c
@@ -1,4 +1,4 @@
-// Copyright (c) 2017, Intel Corporation.
+// Copyright (c) 2017-2018, Intel Corporation.
// This file is currently meant only for FRDM_K64F board
@@ -27,10 +27,10 @@ int frdm_k64f_pinmux_setup(struct device *unused)
// TODO: eventually we maybe need to analyze script to decide how to do
// pinmux, or have user provide a static configuration
struct device *porta = device_get_binding(CONFIG_PINMUX_MCUX_PORTA_NAME);
- pinmux_pin_set(porta, 0, PORT_PCR_MUX(kPORT_MuxAsGpio));
- pinmux_pin_set(porta, 1, PORT_PCR_MUX(kPORT_MuxAsGpio)); // D3
- pinmux_pin_set(porta, 2, PORT_PCR_MUX(kPORT_MuxAsGpio)); // D5
- pinmux_pin_set(porta, 4, PORT_PCR_MUX(kPORT_MuxAsGpio)); // SW3
+ pinmux_pin_set(porta, 0, PORT_PCR_MUX(kPORT_MuxAsGpio));
+ pinmux_pin_set(porta, 1, PORT_PCR_MUX(kPORT_MuxAsGpio)); // D3
+ pinmux_pin_set(porta, 2, PORT_PCR_MUX(kPORT_MuxAsGpio)); // D5
+ pinmux_pin_set(porta, 4, PORT_PCR_MUX(kPORT_MuxAsGpio)); // SW3
struct device *portb = device_get_binding(CONFIG_PINMUX_MCUX_PORTB_NAME);
pinmux_pin_set(portb, 9, PORT_PCR_MUX(kPORT_MuxAsGpio)); // D2
diff --git a/src/zjs_pme.c b/src/zjs_pme.c
index 1fd5697..82d215b 100644
--- a/src/zjs_pme.c
+++ b/src/zjs_pme.c
@@ -1,4 +1,4 @@
-// Copyright (c) 2017, Intel Corporation.
+// Copyright (c) 2017-2018, Intel Corporation.
// C includes
#include <string.h>
@@ -452,7 +452,7 @@ static void zjs_pme_cleanup(void *native)
}
static const jerry_object_native_info_t pme_module_type_info = {
- .free_cb = zjs_pme_cleanup
+ .free_cb = zjs_pme_cleanup
};
static jerry_value_t zjs_pme_init()
diff --git a/src/zjs_pwm.c b/src/zjs_pwm.c
index 7419e6f..9476164 100644
--- a/src/zjs_pwm.c
+++ b/src/zjs_pwm.c
@@ -1,4 +1,4 @@
-// Copyright (c) 2016-2017, Intel Corporation.
+// Copyright (c) 2016-2018, Intel Corporation.
#ifdef BUILD_MODULE_PWM
@@ -170,11 +170,9 @@ static ZJS_DECL_FUNC(zjs_pwm_open)
int pin = zjs_board_find_pwm(pin_val, devname, 20);
if (pin == FIND_PIN_INVALID) {
return TYPE_ERROR("bad pin argument");
- }
- else if (pin == FIND_DEVICE_FAILURE) {
+ } else if (pin == FIND_DEVICE_FAILURE) {
return zjs_error("device not found");
- }
- else if (pin < 0) {
+ } else if (pin < 0) {
return zjs_error("pin not found");
}
struct device *pwmdev = device_get_binding(devname);
@@ -209,7 +207,7 @@ static void zjs_pwm_cleanup(void *native)
}
static const jerry_object_native_info_t pwm_module_type_info = {
- .free_cb = zjs_pwm_cleanup
+ .free_cb = zjs_pwm_cleanup
};
static jerry_value_t zjs_pwm_init()
diff --git a/src/zjs_sensor.c b/src/zjs_sensor.c
index a961d4a..fb88a9c 100644
--- a/src/zjs_sensor.c
+++ b/src/zjs_sensor.c
@@ -1,4 +1,4 @@
-// Copyright (c) 2016-2017, Intel Corporation.
+// Copyright (c) 2016-2018, Intel Corporation.
// C includes
#include <string.h>
@@ -33,7 +33,7 @@ static void zjs_sensor_free_cb(void *native)
}
static const jerry_object_native_info_t sensor_type_info = {
- .free_cb = zjs_sensor_free_cb
+ .free_cb = zjs_sensor_free_cb
};
static sensor_handle_t *zjs_sensor_alloc_handle()
diff --git a/src/zjs_spi.c b/src/zjs_spi.c
index a1cdc2d..931dde8 100644
--- a/src/zjs_spi.c
+++ b/src/zjs_spi.c
@@ -1,4 +1,4 @@
-// Copyright (c) 2017, Intel Corporation.
+// Copyright (c) 2017-2018, Intel Corporation.
// C includes
#include <stdlib.h>
@@ -50,7 +50,7 @@ static void zjs_spi_callback_free(void *native)
}
static const jerry_object_native_info_t spi_type_info = {
- .free_cb = zjs_spi_callback_free
+ .free_cb = zjs_spi_callback_free
};
static ZJS_DECL_FUNC(zjs_spi_transceive)
@@ -329,7 +329,7 @@ static void zjs_spi_cleanup(void *native)
}
static const jerry_object_native_info_t spi_module_type_info = {
- .free_cb = zjs_spi_cleanup
+ .free_cb = zjs_spi_cleanup
};
static jerry_value_t zjs_spi_init()
diff --git a/src/zjs_timers.c b/src/zjs_timers.c
index 9ef581e..4a65a0e 100644
--- a/src/zjs_timers.c
+++ b/src/zjs_timers.c
@@ -25,7 +25,7 @@ typedef struct zjs_timer {
zjs_callback_id callback_id;
bool repeat;
#ifdef ZJS_LINUX_BUILD
- //FIXME - reverted patch #1542 to old timer implementation
+ // FIXME - reverted patch #1542 to old timer implementation
u32_t interval;
bool completed;
#endif
@@ -35,7 +35,7 @@ typedef struct zjs_timer {
static zjs_timer_t *zjs_timers = NULL;
static const jerry_object_native_info_t timer_type_info = {
- .free_cb = free_handle_nop
+ .free_cb = free_handle_nop
};
#ifdef ZJS_LINUX_BUILD
@@ -64,7 +64,8 @@ static void timer_callback(zjs_port_timer_t *handle)
{
zjs_timer_t *timer = (zjs_timer_t *)handle->user_data;
- zjs_signal_callback(timer->callback_id, timer->argv, sizeof(jerry_value_t) * timer->argc);
+ zjs_signal_callback(timer->callback_id, timer->argv,
+ sizeof(jerry_value_t) * timer->argc);
if (!timer->repeat) {
zjs_port_timer_stop(handle);
@@ -160,7 +161,7 @@ static bool delete_timer(zjs_timer_t *tm)
}
// remove callbacks except for expired once timers
#ifdef ZJS_LINUX_BUILD
- //FIXME - reverted patch #1542 to old timer implementation
+ // FIXME - reverted patch #1542 to old timer implementation
if (tm->repeat || !tm->completed) {
#else
if (tm->repeat) {
@@ -229,7 +230,7 @@ static ZJS_DECL_FUNC(native_clear_interval_handler)
}
#ifdef ZJS_LINUX_BUILD
-//FIXME - reverted patch #1542 to old timer implementation
+// FIXME - reverted patch #1542 to old timer implementation
s32_t zjs_timers_process_events()
{
s32_t wait = ZJS_TICKS_FOREVER;
diff --git a/src/zjs_uart.c b/src/zjs_uart.c
index fdd0320..c70e82b 100644
--- a/src/zjs_uart.c
+++ b/src/zjs_uart.c
@@ -1,4 +1,4 @@
-// Copyright (c) 2016-2017, Intel Corporation.
+// Copyright (c) 2016-2018, Intel Corporation.
#ifdef BUILD_MODULE_UART
@@ -310,7 +310,7 @@ static void zjs_uart_cleanup(void *native)
}
static const jerry_object_native_info_t uart_module_type_info = {
- .free_cb = zjs_uart_cleanup
+ .free_cb = zjs_uart_cleanup
};
static jerry_value_t zjs_uart_init()
diff --git a/src/zjs_util.c b/src/zjs_util.c
index ecf115b..7058ab4 100644
--- a/src/zjs_util.c
+++ b/src/zjs_util.c
@@ -1,4 +1,4 @@
-// Copyright (c) 2016-2017, Intel Corporation.
+// Copyright (c) 2016-2018, Intel Corporation.
// C includes
#include <string.h>
@@ -310,7 +310,6 @@ jerry_value_t zjs_push_array(jerry_value_t array, jerry_value_t val)
}
}
-
void zjs_copy_jstring(jerry_value_t jstr, char *buffer, jerry_size_t *maxlen)
{
jerry_size_t size = jerry_get_string_size(jstr);
@@ -351,7 +350,7 @@ char *zjs_alloc_from_string(const char *str, size_t *maxlen)
{
// if no max or string small enough, copy the whole string
if (!maxlen || !*maxlen || strnlen(str, *maxlen) < *maxlen) {
- return (char*)strdup(str);
+ return (char *)strdup(str);
}
// otherwise, limit the size of the string
@@ -784,7 +783,7 @@ void free_handle_nop(void *h)
bool zjs_str_matches(char *str, char *array[])
{
// requires: the final element of array must be NULL
- for (int i=0; array[i]; ++i) {
+ for (int i = 0; array[i]; ++i) {
if (strequal(str, array[i])) {
return true;
}
diff --git a/src/zjs_util.h b/src/zjs_util.h
index 13a1de2..b4d1908 100644
--- a/src/zjs_util.h
+++ b/src/zjs_util.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2016-2017, Intel Corporation.
+// Copyright (c) 2016-2018, Intel Corporation.
#ifndef __zjs_util_h__
#define __zjs_util_h__
@@ -9,8 +9,8 @@
#include <stdlib.h>
// JerryScript includes
-#include "jerryscript.h"
#include "jerryscript-ext/module.h"
+#include "jerryscript.h"
// ZJS includes
#include "zjs_common.h"
@@ -71,37 +71,38 @@ void zjs_pop_mem_stat(void *ptr);
#else
#include <zephyr.h>
#ifdef ZJS_TRACE_MALLOC
-#define zjs_malloc(sz) \
- ({ \
- void *zjs_ptr = zjs_malloc_with_retry(sz); \
- ZJS_PRINT("%s:%d: allocating %u bytes (%p)\n", __func__, __LINE__, \
- (u32_t)(sz), zjs_ptr); \
- zjs_push_mem_stat(zjs_ptr, __FILE__, __func__, __LINE__); \
- zjs_ptr; \
+#define zjs_malloc(sz) \
+ ({ \
+ void *zjs_ptr = zjs_malloc_with_retry(sz); \
+ ZJS_PRINT("%s:%d: allocating %u bytes (%p)\n", __func__, __LINE__, \
+ (u32_t)(sz), zjs_ptr); \
+ zjs_push_mem_stat(zjs_ptr, __FILE__, __func__, __LINE__); \
+ zjs_ptr; \
})
-#define zjs_free(ptr) \
- (ZJS_PRINT("%s:%d: freeing %p\n", __func__, __LINE__, ptr), zjs_pop_mem_stat(ptr), free(ptr))
+#define zjs_free(ptr) \
+ (ZJS_PRINT("%s:%d: freeing %p\n", __func__, __LINE__, ptr), \
+ zjs_pop_mem_stat(ptr), free(ptr))
#else
-#define zjs_malloc(sz) \
- ({ \
- void *zjs_ptr = zjs_malloc_with_retry(sz); \
- if (!zjs_ptr) { \
- ERR_PRINT("malloc(%u) failed\n", (u32_t)(sz)); \
- } \
- zjs_ptr; \
+#define zjs_malloc(sz) \
+ ({ \
+ void *zjs_ptr = zjs_malloc_with_retry(sz); \
+ if (!zjs_ptr) { \
+ ERR_PRINT("malloc(%u) failed\n", (u32_t)(sz)); \
+ } \
+ zjs_ptr; \
})
#define zjs_free(ptr) free(ptr)
#endif // ZJS_TRACE_MALLOC
#endif // ZJS_LINUX_BUILD
#ifdef DEBUG_BUILD
-#define zjs_create_object() \
- ({ \
- jerry_value_t jval = jerry_create_object(); \
- DBG_PRINT("trace: T:%p: create object: %p\n", \
- (void *)(uintptr_t)zjs_port_get_thread_id(), \
- (void *)(uintptr_t)jval); \
- jval; \
+#define zjs_create_object() \
+ ({ \
+ jerry_value_t jval = jerry_create_object(); \
+ DBG_PRINT("trace: T:%p: create object: %p\n", \
+ (void *)(uintptr_t)zjs_port_get_thread_id(), \
+ (void *)(uintptr_t)jval); \
+ jval; \
})
#else
#define zjs_create_object() jerry_create_object()
@@ -368,7 +369,7 @@ int zjs_validate_args(const char *expectations[], const jerry_length_t argc,
*
* NOTE: Expects argc and argv to exist as in a JerryScript native function
*/
-#define ZJS_CHECK_ARGS(...) \
+#define ZJS_CHECK_ARGS(...) \
(zjs_validate_args((const char *[]){ __VA_ARGS__, NULL }, argc, argv) \
<= ZJS_INVALID_ARG) ? 1 : 0
@@ -664,11 +665,11 @@ void zjs_loop_init(void);
* @param str A label string that will be displayed to identify this call
* @param obj The JerryScript object in question
*/
-#define CHECK_REF_COUNT(str, obj) \
- { \
- uint16_t *ptr = (uint16_t *)(uintptr_t)(obj - 3); \
- ZJS_PRINT("%s: %p %d\n", str, (void *)(uintptr_t)obj, \
- (uint32_t)(*ptr) >> 6); \
+#define CHECK_REF_COUNT(str, obj) \
+ { \
+ uint16_t *ptr = (uint16_t *)(uintptr_t)(obj - 3); \
+ ZJS_PRINT("%s: %p %d\n", str, (void *)(uintptr_t)obj, \
+ (uint32_t)(*ptr) >> 6); \
}
#else
#define CHECK_REF_COUNT(str, obj)
diff --git a/src/zjs_web_sockets.c b/src/zjs_web_sockets.c
index ab695e0..6b283a1 100644
--- a/src/zjs_web_sockets.c
+++ b/src/zjs_web_sockets.c
@@ -116,7 +116,9 @@ static char magic[] = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
// get the socket handle or return a JS error
#define GET_WS_HANDLE_JS(obj, var) \
ws_connection_t *var = (ws_connection_t *)zjs_event_get_user_handle(obj); \
- if (!var) { return zjs_error("no websocket handle"); }
+ if (!var) { \
+ return zjs_error("no websocket handle"); \
+ }
static inline ws_connection_t *find_connection(server_handle_t *server_h,
struct net_context *context)
@@ -526,9 +528,9 @@ static void process_packet(ws_connection_t *con, u8_t *data, u32_t len)
}
if (con->server_h->max_payload &&
- (packet->payload_len > con->server_h->max_payload)) {
+ (packet->payload_len > con->server_h->max_payload)) {
emit_error(con->server, "payload too large: %d > %d",
- packet->payload_len, con->server_h->max_payload);
+ packet->payload_len, con->server_h->max_payload);
zjs_free(packet->payload);
zjs_free(packet);
return;
@@ -884,8 +886,9 @@ static void post_accept_handler(void *handle, jerry_value_t ret_val)
emit_error(con->server, "out of memory");
return;
}
- snprintf(send_data, sdata_size, "%s%s\r\nSec-WebSocket-Protocol: %s\r\n\r\n",
- accept_header, con->accept_key, proto);
+ snprintf(send_data, sdata_size,
+ "%s%s\r\nSec-WebSocket-Protocol: %s\r\n\r\n", accept_header,
+ con->accept_key, proto);
DBG_PRINT("Sending accept packet\n");
tcp_send(con->tcp_sock, send_data, strlen(send_data));
@@ -1025,7 +1028,7 @@ static ZJS_DECL_FUNC(ws_server)
if (zjs_is_ip(host) == 4) {
CHECK(net_context_get(AF_INET, SOCK_STREAM, IPPROTO_TCP,
- &handle->server_ctx));
+ &handle->server_ctx));
struct sockaddr_in *my_addr = (struct sockaddr_in *)&addr;
@@ -1035,7 +1038,7 @@ static ZJS_DECL_FUNC(ws_server)
my_addr->sin_port = htons((int)port);
} else {
CHECK(net_context_get(AF_INET6, SOCK_STREAM, IPPROTO_TCP,
- &handle->server_ctx));
+ &handle->server_ctx));
struct sockaddr_in6 *my_addr6 = (struct sockaddr_in6 *)&addr;
@@ -1071,7 +1074,7 @@ static void zjs_ws_cleanup(void *native)
}
static const jerry_object_native_info_t ws_module_type_info = {
- .free_cb = zjs_ws_cleanup
+ .free_cb = zjs_ws_cleanup
};
static jerry_value_t zjs_ws_init()
diff --git a/src/zjs_webusb.c b/src/zjs_webusb.c
index 6c3989d..8687dd6 100644
--- a/src/zjs_webusb.c
+++ b/src/zjs_webusb.c
@@ -1,4 +1,4 @@
-// Copyright (c) 2017, Intel Corporation.
+// Copyright (c) 2017-2018, Intel Corporation.
// C includes
#include <string.h>
@@ -209,12 +209,10 @@ static ZJS_DECL_FUNC(zjs_webusb_set_url)
DBG_PRINT("Found http URL for WebUSB: Chrome only works with https!\n");
scheme = 0;
prefix_len = 7;
- }
- else if (!strncmp(url, "https://", 8)) {
+ } else if (!strncmp(url, "https://", 8)) {
scheme = 1;
prefix_len = 8;
- }
- else {
+ } else {
DBG_PRINT("Found URL for WebUSB with unknown scheme\n");
}
@@ -307,8 +305,7 @@ static bool prepare_read(void *unused, jerry_value_t argv[], u32_t *argc,
if (read < write) {
len = write - read;
- }
- else {
+ } else {
len = write + RINGMAX - read;
}
@@ -352,14 +349,12 @@ static void fill_uart_from_tx(struct device *dev)
if (read == write) {
// empty
uart_irq_tx_disable(dev);
- }
- else {
+ } else {
int max = 0;
bool cont = false;
if (read < write) {
max = write - read;
- }
- else {
+ } else {
max = RINGMAX - read;
cont = true;
}
@@ -387,22 +382,19 @@ static void uart_interrupt_handler(struct device *dev)
int read = rx_ring->read;
int write = rx_ring->write;
bool wrote = false;
- if (write + 1 == read || (write == RINGMAX -1 && read == 0)) {
+ if (write + 1 == read || (write == RINGMAX - 1 && read == 0)) {
// full
ERR_PRINT("receive overflow\n");
- }
- else {
+ } else {
int max = 0;
bool cont = false;
if (write < read) {
max = read - 1 - write;
- }
- else {
+ } else {
max = RINGMAX - write;
if (read == 0) {
--max;
- }
- else {
+ } else {
cont = true;
}
}
@@ -518,8 +510,7 @@ static void check_uart(struct k_timer *timer)
ERR_PRINT("failed to get baudrate\n");
k_timer_stop(timer);
}
- }
- else {
+ } else {
DBG_PRINT("baudrate: %d\n", result);
// apparently we don't actually need to use the baudrate, just need
// to make sure one has been set?