From 4327ebd34ecb1d4afd16d7c11b0c346c1d5a55d4 Mon Sep 17 00:00:00 2001 From: Gordon Williams Date: Fri, 6 Oct 2023 10:47:58 +0100 Subject: [PATCH] Tidying up error messages (no trailing '.' or '\n'), making almost-similar error messages the same Used the following to try and find issues: find . -name "*.c" | xargs -I{} grep -h jsExceptionHere {} | sed -e "s/^[^\"]*\"/\"/" | sort | uniq -c --- ChangeLog | 1 + libs/bluetooth/jswrap_bluetooth.c | 4 +- libs/filesystem/jswrap_file.c | 18 +-- libs/graphics/font/fontconverter.js | 2 +- libs/graphics/graphics.c | 2 +- libs/graphics/jswrap_graphics.c | 4 +- libs/graphics/lcd_sdl.c | 4 +- libs/neopixel/jswrap_neopixel.c | 16 +-- libs/network/cc3000/network_cc3000.c | 2 +- libs/network/esp32/jswrap_esp32_network.c | 106 +++++++++--------- libs/network/esp8266/jswrap_esp8266_network.c | 92 +++++++-------- libs/network/network.c | 24 ++-- libs/network/socketserver.c | 10 +- libs/network/wiznet/jswrap_wiznet.c | 10 +- src/jsjit.c | 4 +- src/jsparse.c | 12 +- src/jspin.c | 4 +- src/jsserial.c | 2 +- src/jsvar.c | 6 +- src/jswrap_arraybuffer.c | 8 +- src/jswrap_functions.c | 8 +- src/jswrap_interactive.c | 4 +- src/jswrap_io.c | 10 +- src/jswrap_modules.c | 10 +- src/jswrap_object.c | 16 +-- src/jswrap_pipe.c | 8 +- src/jswrap_promise.c | 2 +- src/jswrap_serial.c | 4 +- targets/esp32/BLE/esp32_gatts_func.c | 34 +++--- targets/esp32/bluetooth.c | 36 +++--- targets/esp32/jshardwareAnalog.c | 14 +-- targets/esp32/jshardwareI2c.c | 28 ++--- targets/esp32/jshardwareSpi.c | 16 +-- targets/esp32/jswrap_esp32.c | 12 +- targets/esp8266/jshardware.c | 70 ++++++------ targets/esp8266/jswrap_esp8266.c | 6 +- targets/linux/jshardware.c | 30 ++--- targets/nrf5x/bluetooth.c | 4 +- targets/nrf5x/jshardware.c | 20 ++-- targets/stm32/jshardware.c | 16 +-- targets/stm32/stm32_ws2812b_driver.c | 10 +- targets/stm32_ll/jshardware.c | 12 +- 42 files changed, 351 insertions(+), 350 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8bcacde3db..91098040c5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -9,6 +9,7 @@ nRF52: bootloader asks for connection interval 7.5->30ms now, not just 15ms. Should improve DFU on iOS 16 which doesn't honour 15ms request Fix unicode in object keys when UTF8 support enabled, eg. {'\u00e4':1} Bangle.js: Change order of items in the Recovery Menu (hold BTN at boot) to put more common options first + Tidying up error messages (no trailing '.' or '\n'), making almost-similar error messages the same 2v19 : Fix Object.values/entries for numeric keys after 2v18 regression (fix #2375) nRF52: for SD>5 use static buffers for advertising and scan response data (#2367) diff --git a/libs/bluetooth/jswrap_bluetooth.c b/libs/bluetooth/jswrap_bluetooth.c index 7958758141..3dbf207250 100644 --- a/libs/bluetooth/jswrap_bluetooth.c +++ b/libs/bluetooth/jswrap_bluetooth.c @@ -695,7 +695,7 @@ Booting your device while holding all buttons down together should also have the void jswrap_ble_eraseBonds() { #if PEER_MANAGER_ENABLED if (jsble_has_connection()) { - jsExceptionHere(JSET_ERROR, "BLE Connected, can't erase bonds.\n"); + jsExceptionHere(JSET_ERROR, "BLE Connected, can't erase bonds."); } else { jsble_central_eraseBonds(); } @@ -2064,7 +2064,7 @@ void jswrap_ble_setScan(JsVar *callback, JsVar *options) { return; } } else if (options) - jsExceptionHere(JSET_TYPEERROR, "Expecting Object got %t\n", options); + jsExceptionHere(JSET_TYPEERROR, "Expecting Object got %t", options); // set the callback event variable if (!jsvIsFunction(callback)) callback=0; if (callback) { diff --git a/libs/filesystem/jswrap_file.c b/libs/filesystem/jswrap_file.c index 1435263752..ab4b9f5d0f 100755 --- a/libs/filesystem/jswrap_file.c +++ b/libs/filesystem/jswrap_file.c @@ -41,7 +41,7 @@ bool isSdSPISetup(); // 'path' must be of JS_DIR_BUF_SIZE bool jsfsGetPathString(char *pathStr, JsVar *path) { if (jsvGetString(path, pathStr, JS_DIR_BUF_SIZE)==JS_DIR_BUF_SIZE) { - jsExceptionHere(JSET_ERROR, "File path too long\n"); + jsExceptionHere(JSET_ERROR, "File path too long"); return false; } return true; @@ -71,10 +71,10 @@ void jsfsReportError(const char *msg, FRESULT res) { } bool jsfsInit() { - + #ifndef LINUX if (!fat_initialised) { -#ifndef USE_FLASHFS +#ifndef USE_FLASHFS #ifdef SD_CARD_ANYWHERE if (!isSdSPISetup()) { #ifdef SD_SPI @@ -95,7 +95,7 @@ bool jsfsInit() { #endif // SD_SPI } #endif // SD_CARD_ANYWHER -#endif // USE_FLASHFS +#endif // USE_FLASHFS FRESULT res; if ((res = f_mount(&jsfsFAT, "", 1)) != FR_OK) { @@ -147,7 +147,7 @@ initialised, and some cards will not work reliably without one. void jswrap_E_connectSDCard(JsVar *spi, Pin csPin) { #ifdef SD_CARD_ANYWHERE if (!jsvIsObject(spi)) { - jsExceptionHere(JSET_ERROR, "First argument is a %t, not an SPI object\n", spi); + jsExceptionHere(JSET_ERROR, "First argument is a %t, not an SPI object", spi); return; } if (!jshIsPinValid(csPin)) { @@ -557,9 +557,9 @@ Seek to a certain position in the file */ void jswrap_file_skip_or_seek(JsVar* parent, int nBytes, bool is_skip) { if (nBytes<0) { - if ( is_skip ) + if ( is_skip ) jsWarn("Bytes to skip must be >=0"); - else + else jsWarn("Position to seek to must be >=0"); return; } @@ -655,7 +655,7 @@ int jswrap_E_flashFatFS(JsVar* options) { else if (!jsvIsUndefined(options)) { jsExceptionHere(JSET_TYPEERROR, "'options' must be an object, or undefined"); } - + uint8_t init=flashFatFsInit(addr, sectors); if (init) { if ( format ) { @@ -666,7 +666,7 @@ int jswrap_E_flashFatFS(JsVar* options) { jsExceptionHere(JSET_INTERNALERROR, "Flash Formatting error:",res); return false; } - } + } } jsfsInit(); return true; diff --git a/libs/graphics/font/fontconverter.js b/libs/graphics/font/fontconverter.js index bc1aeb87a1..93e863c474 100755 --- a/libs/graphics/font/fontconverter.js +++ b/libs/graphics/font/fontconverter.js @@ -9,7 +9,7 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/. ---------------------------------------------------------------------------------------- - Bitmap font creator for Graphics custom fonts + Bitmap font creator for Espruino Graphics custom fonts Takes input as a PNG font map, PBFF, or bitfontmaker2 JSON diff --git a/libs/graphics/graphics.c b/libs/graphics/graphics.c index 62be9a09a7..190957d254 100644 --- a/libs/graphics/graphics.c +++ b/libs/graphics/graphics.c @@ -197,7 +197,7 @@ bool graphicsSetCallbacks(JsGraphics *gfx) { lcd_spi_unbuf_setCallbacks(gfx); #endif } else { - jsExceptionHere(JSET_INTERNALERROR, "Unknown graphics type\n"); + jsExceptionHere(JSET_INTERNALERROR, "Unknown graphics type"); assert(0); return false; } diff --git a/libs/graphics/jswrap_graphics.c b/libs/graphics/jswrap_graphics.c index c5c15b0818..ec2b6e9401 100644 --- a/libs/graphics/jswrap_graphics.c +++ b/libs/graphics/jswrap_graphics.c @@ -641,11 +641,11 @@ JsVar *jswrap_graphics_createArrayBuffer(int width, int height, int bpp, JsVar * if (gfx.data.bpp==1) gfx.data.flags = (JsGraphicsFlags)(gfx.data.flags | JSGRAPHICSFLAGS_ARRAYBUFFER_VERTICAL_BYTE); else { - jsExceptionHere(JSET_ERROR, "vertical_byte only works for 1bpp ArrayBuffers\n"); + jsExceptionHere(JSET_ERROR, "vertical_byte only works for 1bpp ArrayBuffers"); return 0; } if (gfx.data.height&7) { - jsExceptionHere(JSET_ERROR, "height must be a multiple of 8 when using vertical_byte\n"); + jsExceptionHere(JSET_ERROR, "height must be a multiple of 8 when using vertical_byte"); return 0; } } diff --git a/libs/graphics/lcd_sdl.c b/libs/graphics/lcd_sdl.c index 172c159833..e4c6cd0023 100644 --- a/libs/graphics/lcd_sdl.c +++ b/libs/graphics/lcd_sdl.c @@ -76,12 +76,12 @@ void lcdSetPixel_SDL(JsGraphics *gfx, int x, int y, unsigned int col) { void lcdInit_SDL(JsGraphics *gfx) { if (SDL_Init(SDL_INIT_VIDEO) < 0 ) { - jsExceptionHere(JSET_ERROR, "SDL_Init failed\n"); + jsExceptionHere(JSET_ERROR, "SDL_Init failed"); exit(1); } if (!(screen = SDL_SetVideoMode(gfx->data.width, gfx->data.height, 32, SDL_SWSURFACE))) { - jsExceptionHere(JSET_ERROR, "SDL_SetVideoMode failed\n"); + jsExceptionHere(JSET_ERROR, "SDL_SetVideoMode failed"); SDL_Quit(); exit(1); } diff --git a/libs/neopixel/jswrap_neopixel.c b/libs/neopixel/jswrap_neopixel.c index f45d2f575f..67b4d6337b 100644 --- a/libs/neopixel/jswrap_neopixel.c +++ b/libs/neopixel/jswrap_neopixel.c @@ -96,8 +96,8 @@ multiple of 3 bytes long. Just round the size up - it won't cause any problems. * On some platforms like STM32, pins capable of hardware SPI MOSI are required. * On STM32, `neopixel.write` chooses a hardware SPI device to output the signal on -and uses that. However in order to avoid spikes in the output, if that hardware device is *already -initialised* it will not be re-initialised. This means that if the SPI device was already in use, +and uses that. However in order to avoid spikes in the output, if that hardware device is *already +initialised* it will not be re-initialised. This means that if the SPI device was already in use, you may have to use `SPIx.setup({baud:3200000, mosi:the_pin})` to force it to be re-setup on the pin. * Espruino devices tend to have 3.3v IO, while WS2812/etc run off of 5v. Many @@ -116,11 +116,11 @@ void jswrap_neopixel_write(Pin pin, JsVar *data) { return; } if (rgbSize == 0) { - jsExceptionHere(JSET_ERROR, "Data must be a non empty array."); + jsExceptionHere(JSET_ERROR, "Data must be a non empty array"); return; } if (rgbSize % 3 != 0) { - jsExceptionHere(JSET_ERROR, "Data length must be a multiple of 3 (RGB)."); + jsExceptionHere(JSET_ERROR, "Data length must be a multiple of 3 (RGB)"); return; } @@ -145,7 +145,7 @@ extern Pin jshNeoPixelPin; ///< The currently setup Neopixel pin (set by jswrap_ // this one could potentially work on other platforms as well... bool neopixelWrite(Pin pin, unsigned char *rgbData, size_t rgbSize) { if (!jshIsPinValid(pin)) { - jsExceptionHere(JSET_ERROR, "Pin is not valid."); + jsExceptionHere(JSET_ERROR, "Pin is not valid"); return false; } JshPinFunction spiDevice = 0; @@ -158,7 +158,7 @@ bool neopixelWrite(Pin pin, unsigned char *rgbData, size_t rgbSize) { } IOEventFlags device = jshGetFromDevicePinFunction(spiDevice); if (!spiDevice || !device) { - jsExceptionHere(JSET_ERROR, "No suitable SPI device found for this pin\n"); + jsExceptionHere(JSET_ERROR, "No suitable SPI device found for this pin"); return false; } JshSPIInfo inf; @@ -187,7 +187,7 @@ bool neopixelWrite(Pin pin, unsigned char *rgbData, size_t rgbSize) { bool neopixelWrite(Pin pin, unsigned char *rgbData, size_t rgbSize) { #ifdef NRF52_SERIES if (!jshIsPinValid(pin)) { - jsExceptionHere(JSET_ERROR, "Pin is not valid."); + jsExceptionHere(JSET_ERROR, "Pin is not valid"); return false; } return !i2s_ws2812b_drive_xfer((rgb_led_t *)rgbData, rgbSize/3, pinInfo[pin].pin); @@ -208,7 +208,7 @@ static inline uint32_t _getCycleCount(void) { bool neopixelWrite(Pin pin, unsigned char *rgbData, size_t rgbSize) { if (!jshIsPinValid(pin)) { - jsExceptionHere(JSET_ERROR, "Pin is not valid."); + jsExceptionHere(JSET_ERROR, "Pin is not valid"); return false; } if (!jshGetPinStateIsManual(pin)) diff --git a/libs/network/cc3000/network_cc3000.c b/libs/network/cc3000/network_cc3000.c index 037b27d4f1..0a0b2d5ada 100644 --- a/libs/network/cc3000/network_cc3000.c +++ b/libs/network/cc3000/network_cc3000.c @@ -67,7 +67,7 @@ bool net_cc3000_checkError(JsNetwork *net) { if (wlan) { jswrap_wlan_reconnect(wlan); jsvUnLock(wlan); - } else jsExceptionHere(JSET_INTERNALERROR, "No CC3000 object!\n"); + } else jsExceptionHere(JSET_INTERNALERROR, "No CC3000 object!"); // jswrap_wlan_reconnect could fail, which would mean we have to do this all over again } return hadErrors; diff --git a/libs/network/esp32/jswrap_esp32_network.c b/libs/network/esp32/jswrap_esp32_network.c index ac771c9d57..7171eaafd2 100644 --- a/libs/network/esp32/jswrap_esp32_network.c +++ b/libs/network/esp32/jswrap_esp32_network.c @@ -145,8 +145,8 @@ static char *cipherTypeToString(wifi_cipher_type_t cipherType) { */ /** - * check esp function -*/ + * check esp function +*/ /** * Convert an wifi_second_chan_t data type to a string value. @@ -259,7 +259,7 @@ static char *wifiEventToString(uint32_t event){ case SYSTEM_EVENT_STA_GOT_IP:return "STA_GOT_IP"; case SYSTEM_EVENT_AP_STACONNECTED:return "AP_STACONNECTED"; case SYSTEM_EVENT_AP_STADISCONNECTED: return "AP_STADISCONNECTED"; - case SYSTEM_EVENT_AP_PROBEREQRECVED:return "AP_PROBEREQRECVED"; + case SYSTEM_EVENT_AP_PROBEREQRECVED:return "AP_PROBEREQRECVED"; case SYSTEM_EVENT_WIFI_READY: return "WIFI_READY"; case SYSTEM_EVENT_SCAN_DONE: return "SCAN_DONE"; case SYSTEM_EVENT_STA_START: return "STA_START"; @@ -278,13 +278,13 @@ static char *wifiEventToString(uint32_t event){ case SYSTEM_EVENT_ETH_DISCONNECTED: return "ETH_DISCONNECTED"; case SYSTEM_EVENT_ETH_GOT_IP: return "ETH_GOT_IP"; case SYSTEM_EVENT_MAX: return "MAX"; - default: return "unknown event"; + default: return "unknown event"; } } /** * convert WiFi error to a string value. - */ + */ static char *wifiErrorToString(esp_err_t err){ switch(err){ case 0x3001: return"WiFi driver was not installed by esp_wifi_init"; @@ -549,7 +549,7 @@ static esp_err_t event_handler(void *ctx, system_event_t *event) jsError( "Wifi: event_handler STA_START: esp_wifi_connect: %d(%s)", err,wifiErrorToString(err)); return NULL; } - return ESP_OK; + return ESP_OK; } /** * SYSTEM_EVENT_STA_GOT_IP @@ -653,7 +653,7 @@ void esp32_wifi_init() { ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM)); jsDebug(DBG_INFO, "esp32_wifi_init complete"); - + } // End of esp32_wifi_init @@ -765,7 +765,7 @@ void jswrap_wifi_connect( JsVar *jsOptions, JsVar *jsCallback ) { - + jsDebug(DBG_INFO, "jswrap_wifi_connect: entry"); // Check that the ssid value isn't obviously in error. @@ -816,7 +816,7 @@ jsDebug(DBG_INFO, "jswrap_wifi_connect: entry"); jsvUnLock(jsPassword); } // End of we had options jsDebug(DBG_INFO, "jswrap_wifi_connect: SSID, password, Callback done"); - + // At this point, we have the ssid in "ssid" and the password in "password". // Perform an esp_wifi_set_mode wifi_mode_t mode; @@ -846,7 +846,7 @@ jsDebug(DBG_INFO, "jswrap_wifi_connect: entry"); return; } jsDebug(DBG_INFO, "jswrap_wifi_connect: esi_wifi_set_mode done"); - + // Perform a an esp_wifi_set_config wifi_config_t staConfig; @@ -856,8 +856,8 @@ jsDebug(DBG_INFO, "jswrap_wifi_connect: entry"); staConfig.sta.bssid_set = false; esp_wifi_set_auto_connect(true); jsDebug(DBG_INFO, "jswrap_wifi_connect: esp_wifi_set_autoconnect done"); - - err = esp_wifi_set_config(ESP_IF_WIFI_STA, &staConfig); + + err = esp_wifi_set_config(ESP_IF_WIFI_STA, &staConfig); if (err != ESP_OK) { jsError( "jswrap_wifi_connect: esp_wifi_set_config: %d(%s)", err,wifiErrorToString(err)); return; @@ -874,7 +874,7 @@ jsDebug(DBG_INFO, "jswrap_wifi_connect: entry"); // Save the callback for later execution. g_jsGotIpCallback = jsvLockAgainSafe(jsCallback); - + err = esp_wifi_connect(); } @@ -882,7 +882,7 @@ jsDebug(DBG_INFO, "jswrap_wifi_connect: entry"); void jswrap_wifi_scan(JsVar *jsCallback) { // If we have a saved scan callback function we must be scanning already if (g_jsScanCallback != NULL) { - jsExceptionHere(JSET_ERROR, "A scan is already in progress."); + jsExceptionHere(JSET_ERROR, "A scan is already in progress"); return; } @@ -961,7 +961,7 @@ void jswrap_wifi_startAP( // Validate that the SSID value is provided and is a string. if (!jsvIsString(jsSsid)) { - jsExceptionHere(JSET_ERROR, "No SSID."); + jsExceptionHere(JSET_ERROR, "No SSID"); return; } @@ -1026,7 +1026,7 @@ void jswrap_wifi_startAP( apConfig.authmode = WIFI_AUTH_WPA_WPA2_PSK; } else { jsvUnLock(jsAuth); - jsExceptionHere(JSET_ERROR, "Unknown authMode value."); + jsExceptionHere(JSET_ERROR, "Unknown authMode value"); return; } } else { @@ -1042,13 +1042,13 @@ void jswrap_wifi_startAP( // Make sure password and authMode match if (apConfig.authmode != WIFI_AUTH_OPEN && strlen(apConfig.password) == 0) { - jsExceptionHere(JSET_ERROR, "Password not set but authMode not open."); + jsExceptionHere(JSET_ERROR, "Password not set but authMode not open"); return; } // Make sure that if authmode is explicitly open then there is NO password supplied. if (apConfig.authmode == WIFI_AUTH_OPEN && strlen(apConfig.password) > 0) { - jsExceptionHere(JSET_ERROR, "Auth mode set to open but password supplied."); + jsExceptionHere(JSET_ERROR, "Auth mode set to open but password supplied"); return; } } // End we have an options structure @@ -1061,7 +1061,7 @@ void jswrap_wifi_startAP( wifi_mode_t mode; err = esp_wifi_get_mode(&mode); - + err = esp_wifi_set_mode( mode | WIFI_MODE_AP); if (err != ESP_OK) { jsError( "jswrap_wifi_startAP: esp_wifi_set_mode: %d(%s)", err,wifiErrorToString(err)); @@ -1192,7 +1192,7 @@ void jswrap_wifi_setConfig(JsVar *jsSettings) { esp_wifi_set_protocol(WIFI_IF_AP,WIFI_PROTOCOL_11B| WIFI_PROTOCOL_11G|WIFI_PROTOCOL_11N); } else { jsvUnLock(jsPhy); - jsExceptionHere(JSET_ERROR, "Unknown phy mode."); + jsExceptionHere(JSET_ERROR, "Unknown phy mode"); return; } } @@ -1212,7 +1212,7 @@ void jswrap_wifi_setConfig(JsVar *jsSettings) { esp_wifi_set_ps(WIFI_PS_MAX_MODEM); } else { jsvUnLock(jsPowerSave); - jsExceptionHere(JSET_ERROR, "Unknown powersave mode."); + jsExceptionHere(JSET_ERROR, "Unknown powersave mode"); return; } } @@ -1301,7 +1301,7 @@ JsVar *jswrap_wifi_getAPDetails(JsVar *jsCallback) { } // End of jswrap_wifi_getAPDetails void jswrap_wifi_save(JsVar *what) { - jsDebug(DBG_INFO, "Wifi.save"); + jsDebug(DBG_INFO, "Wifi.save"); JsVar *o = jsvNewObject(); if (!o) return; @@ -1315,10 +1315,10 @@ void jswrap_wifi_save(JsVar *what) { // station stuff wifi_sta_config_t sta_config; - esp_wifi_get_config(WIFI_IF_STA, (wifi_config_t *)&sta_config); + esp_wifi_get_config(WIFI_IF_STA, (wifi_config_t *)&sta_config); jsvObjectSetChildAndUnLock(o, "ssid", jsvNewFromString((char *)sta_config.ssid)); jsvObjectSetChildAndUnLock(o, "password", jsvNewFromString((char *)sta_config.password)); - + wifi_mode_t wifi_mode; esp_wifi_get_mode(&wifi_mode); jsvObjectSetChildAndUnLock(o, "mode", jsvNewFromInteger(wifi_mode)); @@ -1338,13 +1338,13 @@ void jswrap_wifi_save(JsVar *what) { jsvObjectSetChildAndUnLock(o, "channelAP", jsvNewFromInteger(ap_config.channel)); const char * hostname; - esp_err_t err = tcpip_adapter_get_hostname(TCPIP_ADAPTER_IF_STA, &hostname); + esp_err_t err = tcpip_adapter_get_hostname(TCPIP_ADAPTER_IF_STA, &hostname); if (hostname) jsvObjectSetChildAndUnLock(o, "hostname", jsvNewFromString((char *) hostname)); // save object JsVar *name = jsvNewFromString(WIFI_CONFIG_STORAGE_NAME); jswrap_storage_erase(name); - jswrap_storage_write(name,o,0,0); + jswrap_storage_write(name,o,0,0); jsvUnLock2(name,o); jsDebug(DBG_INFO, "Wifi.save: write completed"); @@ -1352,31 +1352,31 @@ void jswrap_wifi_save(JsVar *what) { void jswrap_wifi_restore(void) { jsDebug(DBG_INFO, "jswrap_wifi_restore"); - + JsVar *name = jsvNewFromString(WIFI_CONFIG_STORAGE_NAME); JsVar *o = jswrap_storage_readJSON(name, true); - if (!o) { // no data + if (!o) { // no data jsDebug(DBG_INFO, "jswrap_wifi_restore: No data - Starting default AP"); esp_wifi_start(); jsvUnLock2(name,o); - return; + return; } - + wifi_mode_t savedMode; JsVar *v = jsvObjectGetChildIfExists(o,"mode"); savedMode=jsvGetInteger(v); esp_wifi_set_mode(savedMode); jsvUnLock(v); - + //v = jsvObjectGetChildIfExists(o,"phyMode"); //wifi_set_phy_mode(jsvGetInteger(v)); - //jsvUnLock(v); + //jsvUnLock(v); //v = jsvObjectGetChildIfExists(o,"sleepType"); //esp_wifi_get_ps(jsvGetInteger(v)); //jsvUnLock(v); - + wifi_ap_config_t apConfig; bzero(&apConfig, sizeof(apConfig)); @@ -1387,7 +1387,7 @@ void jswrap_wifi_restore(void) { v = jsvObjectGetChildIfExists(o,"authmodeAP"); ap_config.authmode =jsvGetInteger(v); - jsvUnLock(v); + jsvUnLock(v); v = jsvObjectGetChildIfExists(o,"hiddenAP"); ap_config.ssid_hidden = jsvGetInteger(v); @@ -1401,7 +1401,7 @@ void jswrap_wifi_restore(void) { v = jsvObjectGetChildIfExists(o,"passwordAP"); jsvGetString(v, (char *)ap_config.password, sizeof(ap_config.password)); - jsvUnLock(v); + jsvUnLock(v); v = jsvObjectGetChildIfExists(o,"channelAP"); ap_config.channel = jsvGetInteger(v); @@ -1411,25 +1411,25 @@ void jswrap_wifi_restore(void) { ap_config.beacon_interval = 100; err = esp_wifi_set_config(WIFI_IF_AP, (wifi_config_t *)&apConfig); jsWarn("jswrap_wifi_restore: AP=%s", ap_config.ssid); - } - - if (savedMode & WIFI_MODE_STA) { + } + + if (savedMode & WIFI_MODE_STA) { wifi_sta_config_t sta_config; bzero(&sta_config, sizeof(sta_config)); v = jsvObjectGetChildIfExists(o,"ssid"); - jsvGetString(v, (char *)sta_config.ssid, sizeof(sta_config.ssid)); - jsvUnLock(v); + jsvGetString(v, (char *)sta_config.ssid, sizeof(sta_config.ssid)); + jsvUnLock(v); v = jsvObjectGetChildIfExists(o,"password"); jsvGetString(v, (char *)sta_config.password, sizeof(sta_config.password)); - jsvUnLock(v); + jsvUnLock(v); - err = esp_wifi_set_config(ESP_IF_WIFI_STA, &sta_config); + err = esp_wifi_set_config(ESP_IF_WIFI_STA, &sta_config); jsWarn("Wifi.restore: STA=%s", sta_config.ssid); - } + } err = esp_wifi_start(); if (err != ESP_OK) { jsError( "jswrap_wifi_restore: esp_wifi_start: %d(%s)", err - ESP_ERR_WIFI_BASE,wifiErrorToString(err)); @@ -1443,14 +1443,14 @@ void jswrap_wifi_restore(void) { jsWarn("Wifi.restore: hostname=%s", hostname); tcpip_adapter_set_hostname(TCPIP_ADAPTER_IF_STA,hostname); } - jsvUnLock(v); + jsvUnLock(v); } if ( ( savedMode == WIFI_MODE_STA ) || ( savedMode == WIFI_MODE_APSTA ) ) { err = esp_wifi_connect(); if (err != ESP_OK) { jsError( "jswrap_wifi_restore: esp_wifi_connect: %d(%s)", err - ESP_ERR_WIFI_BASE,wifiErrorToString(err)); return; - } + } } else { jsDebug(DBG_INFO, "Wifi: Both STA AND APSTA are off"); } @@ -1532,7 +1532,7 @@ void jswrap_wifi_setHostname( // now update mDNS startMDNS(hostname); - + if (jsvIsFunction(jsCallback)) jsiQueueEvents(0, jsCallback, 0, 0); } @@ -1540,7 +1540,7 @@ void jswrap_wifi_setHostname( static uint8_t seq_no; esp_err_t pingResults(ping_target_id_t msgType, esp_ping_found * pingResp){ - //printf("AvgTime:%.1fmS Sent:%d Rec:%d Err:%d min(mS):%d max(mS):%d ", + //printf("AvgTime:%.1fmS Sent:%d Rec:%d Err:%d min(mS):%d max(mS):%d ", //(float)pf->total_time/pf->recv_count, pf->send_count, pf->recv_count, pf->err_count, pf->min_time, pf->max_time ); //printf("Resp(mS):%d Timeouts:%d Total Time:%d\n",pf->resp_time, pf->timeout_count, pf->total_time); if (g_jsPingCallback != NULL) { @@ -1575,7 +1575,7 @@ void jswrap_wifi_ping( ipString[len] = '\0'; ip.addr = networkParseIPAddress(ipString); if (ip.addr == 0) { - jsExceptionHere(JSET_ERROR, "Not a valid IP address."); + jsExceptionHere(JSET_ERROR, "Not a valid IP address"); return; } } else @@ -1587,7 +1587,7 @@ void jswrap_wifi_ping( // know how to get the IP address of the partner to ping so throw an // exception. { - jsExceptionHere(JSET_ERROR, "IP address must be string or integer."); + jsExceptionHere(JSET_ERROR, "IP address must be string or integer"); return; } @@ -1597,7 +1597,7 @@ void jswrap_wifi_ping( } g_jsPingCallback = NULL; } else if (!jsvIsFunction(pingCallback)) { - jsExceptionHere(JSET_ERROR, "Callback is not a function."); + jsExceptionHere(JSET_ERROR, "Callback is not a function"); return; } else { if (g_jsPingCallback != NULL) { @@ -1611,7 +1611,7 @@ void jswrap_wifi_ping( uint32_t ping_count = 5; //how many pings per report uint32_t ping_timeout = 1000; //mS till we consider it timed out - uint32_t ping_delay = 500; //mS between pings + uint32_t ping_delay = 500; //mS between pings esp_ping_set_target(PING_TARGET_IP_ADDRESS_COUNT, &ping_count, sizeof(uint32_t)); esp_ping_set_target(PING_TARGET_RCV_TIMEO, &ping_timeout, sizeof(uint32_t)); esp_ping_set_target(PING_TARGET_DELAY_TIME, &ping_delay, sizeof(uint32_t)); @@ -1633,10 +1633,10 @@ void jswrap_wifi_setSNTP(JsVar *jsServer, JsVar *jsZone) { } char zone[64]; jsvGetString(jsZone, zone, 64); - + char server[64]; jsvGetString(jsServer, server, 64); - + setenv("TZ", zone, 1); tzset(); sntp_setoperatingmode(SNTP_OPMODE_POLL); diff --git a/libs/network/esp8266/jswrap_esp8266_network.c b/libs/network/esp8266/jswrap_esp8266_network.c index 302adeb95f..0ad929e428 100644 --- a/libs/network/esp8266/jswrap_esp8266_network.c +++ b/libs/network/esp8266/jswrap_esp8266_network.c @@ -115,7 +115,7 @@ static bool g_skipDisconnect; // Global data structure for ping request static struct ping_option pingOpt; -// Global data structure for setIP and setAPIP +// Global data structure for setIP and setAPIP static struct ip_info info; // Configuration save to flash @@ -364,16 +364,16 @@ void jswrap_wifi_connect( bool isMAC = networkParseMACAddress((unsigned char*) stationConfig.bssid, (char *) macAddrString); if ( isMAC ) { stationConfig.bssid_set = 1; - DBGV("stationConfig.bssid_set = 1, %d %d %d %d %d %d\n", + DBGV("stationConfig.bssid_set = 1, %d %d %d %d %d %d\n", stationConfig.bssid[0], stationConfig.bssid[1], stationConfig.bssid[2], stationConfig.bssid[3], stationConfig.bssid[4], stationConfig.bssid[5] ); - } else { + } else { jsExceptionHere(JSET_ERROR, "Expecting bssid as \"aa:bb:cc:dd:cc:ff\""); jsvUnLock(jsBssid); return; } - } + } jsvUnLock(jsBssid); //Handle channel @@ -385,8 +385,8 @@ void jswrap_wifi_connect( wifi_set_channel(channel); } else { jsExceptionHere(JSET_ERROR, "Expecting options.channel to be a integer between 0 and 14, but got %t", jsChannel); - jsvUnLock(jsChannel); - return; + jsvUnLock(jsChannel); + return; } } jsvUnLock(jsChannel); @@ -489,7 +489,7 @@ void jswrap_wifi_scan(JsVar *jsCallback) { // If we have a saved scan callback function we must be scanning already if (g_jsScanCallback != NULL) { - jsExceptionHere(JSET_ERROR, "A scan is already in progress."); + jsExceptionHere(JSET_ERROR, "A scan is already in progress"); return; } @@ -531,7 +531,7 @@ void jswrap_wifi_startAP( // Validate that the SSID is provided and is a string. if (!jsvIsString(jsSsid)) { - jsExceptionHere(JSET_ERROR, "No SSID."); + jsExceptionHere(JSET_ERROR, "No SSID"); return; } @@ -554,7 +554,7 @@ void jswrap_wifi_startAP( // Handle any options that may have been supplied. if (jsvIsObject(jsOptions)) { // Handle hidden - JsVar *jsHidden = jsvObjectGetChildIfExists(jsOptions, "hidden"); + JsVar *jsHidden = jsvObjectGetChildIfExists(jsOptions, "hidden"); if (jsvIsInt(jsHidden)) { int hidden = jsvGetInteger(jsHidden); if (hidden >= 0 && hidden <= 1) softApConfig.ssid_hidden = hidden; @@ -599,7 +599,7 @@ void jswrap_wifi_startAP( softApConfig.authmode = AUTH_WPA_WPA2_PSK; } else { jsvUnLock(jsAuth); - jsExceptionHere(JSET_ERROR, "Unknown authMode value."); + jsExceptionHere(JSET_ERROR, "Unknown authMode value"); return; } } else { @@ -610,11 +610,11 @@ void jswrap_wifi_startAP( // Make sure password and authmode match if (softApConfig.authmode != AUTH_OPEN && softApConfig.password[0] == 0) { - jsExceptionHere(JSET_ERROR, "Password not set but authMode not open."); + jsExceptionHere(JSET_ERROR, "Password not set but authMode not open"); return; } if (softApConfig.authmode == AUTH_OPEN && softApConfig.password[0] != 0) { - jsExceptionHere(JSET_ERROR, "Auth mode set to open but password supplied."); + jsExceptionHere(JSET_ERROR, "Auth mode set to open but password supplied"); return; } } @@ -714,7 +714,7 @@ void jswrap_wifi_setConfig(JsVar *jsSettings) { wifi_set_phy_mode(PHY_MODE_11N); } else { jsvUnLock(jsPhy); - jsExceptionHere(JSET_ERROR, "Unknown phy mode."); + jsExceptionHere(JSET_ERROR, "Unknown phy mode"); return; } } @@ -729,7 +729,7 @@ void jswrap_wifi_setConfig(JsVar *jsSettings) { wifi_set_sleep_type(MODEM_SLEEP_T); } else { jsvUnLock(jsPowerSave); - jsExceptionHere(JSET_ERROR, "Unknown powersave mode."); + jsExceptionHere(JSET_ERROR, "Unknown powersave mode"); return; } } @@ -856,7 +856,7 @@ JsVar *jswrap_wifi_getAPDetails(JsVar *jsCallback) { } void jswrap_wifi_save(JsVar *what) { - DBGV("> Wifi.save\n"); + DBGV("> Wifi.save\n"); JsVar *o = jsvNewObject(); if (!o) return; @@ -888,14 +888,14 @@ void jswrap_wifi_save(JsVar *what) { jsvObjectSetChildAndUnLock(o, "authmodeAP", jsvNewFromInteger(ap_config.authmode)); jsvObjectSetChildAndUnLock(o, "hiddenAP", jsvNewFromInteger(ap_config.ssid_hidden)); jsvObjectSetChildAndUnLock(o, "channelAP", jsvNewFromInteger(ap_config.channel)); - + savedMode = wifi_get_opmode(); // save object JsVar *name = jsvNewFromString(WIFI_CONFIG_STORAGE_NAME); //JsVar *arr = jsvNewArray(&o,1); jswrap_storage_erase(name); - jswrap_storage_write(name,o,0,0); + jswrap_storage_write(name,o,0,0); //jsvUnLock3(arr,name,o); jsvUnLock2(name,o); @@ -906,25 +906,25 @@ void jswrap_wifi_restore(void) { DBG("Wifi.restore\n"); JsVar *name = jsvNewFromString(WIFI_CONFIG_STORAGE_NAME); JsVar *o = jswrap_storage_readJSON(name, true); - if (!o) { // no data + if (!o) { // no data jsvUnLock2(name,o); - return; + return; } JsVar *v; v = jsvObjectGetChildIfExists(o,"mode"); savedMode = jsvGetInteger(v); - jsvUnLock(v); + jsvUnLock(v); wifi_set_opmode_current(savedMode); v = jsvObjectGetChildIfExists(o,"phyMode"); wifi_set_phy_mode(jsvGetInteger(v)); - jsvUnLock(v); + jsvUnLock(v); v = jsvObjectGetChildIfExists(o,"sleepType"); wifi_set_sleep_type(jsvGetInteger(v)); jsvUnLock(v); - + if (savedMode & SOFTAP_MODE) { struct softap_config ap_config; @@ -932,7 +932,7 @@ void jswrap_wifi_restore(void) { v = jsvObjectGetChildIfExists(o,"authmodeAP"); ap_config.authmode =jsvGetInteger(v); - jsvUnLock(v); + jsvUnLock(v); v = jsvObjectGetChildIfExists(o,"hiddenAP"); ap_config.ssid_hidden = jsvGetInteger(v); @@ -946,7 +946,7 @@ void jswrap_wifi_restore(void) { v = jsvObjectGetChildIfExists(o,"passwordAP"); jsvGetString(v, (char *)ap_config.password, sizeof(ap_config.password)); - jsvUnLock(v); + jsvUnLock(v); v = jsvObjectGetChildIfExists(o,"channelAP"); ap_config.channel = jsvGetInteger(v); @@ -961,25 +961,25 @@ void jswrap_wifi_restore(void) { if (savedMode & STATION_MODE) { v = jsvObjectGetChildIfExists(o,"hostname"); - + if (v) { char hostname[64]; jsvGetString(v, hostname, sizeof(hostname)); DBG("Wifi.restore: hostname=%s\n", hostname); wifi_station_set_hostname(hostname); } - jsvUnLock(v); + jsvUnLock(v); struct station_config sta_config; os_memset(&sta_config, 0, sizeof(sta_config)); v = jsvObjectGetChildIfExists(o,"ssid"); - jsvGetString(v, (char *)sta_config.ssid, sizeof(sta_config.ssid)); - jsvUnLock(v); + jsvGetString(v, (char *)sta_config.ssid, sizeof(sta_config.ssid)); + jsvUnLock(v); v = jsvObjectGetChildIfExists(o,"password"); jsvGetString(v, (char *)sta_config.password, sizeof(sta_config.password)); - jsvUnLock(v); + jsvUnLock(v); wifi_station_set_config_current(&sta_config); DBG("Wifi.restore: STA=%s\n", sta_config.ssid); @@ -1303,7 +1303,7 @@ void jswrap_wifi_ping( ipString[len] = '\0'; pingOpt.ip = networkParseIPAddress(ipString); if (pingOpt.ip == 0) { - jsExceptionHere(JSET_ERROR, "Not a valid IP address."); + jsExceptionHere(JSET_ERROR, "Not a valid IP address"); return; } } else @@ -1315,7 +1315,7 @@ void jswrap_wifi_ping( // know how to get the IP address of the partner to ping so throw an // exception. { - jsExceptionHere(JSET_ERROR, "IP address must be string or integer."); + jsExceptionHere(JSET_ERROR, "IP address must be string or integer"); return; } @@ -1325,7 +1325,7 @@ void jswrap_wifi_ping( } g_jsPingCallback = NULL; } else if (!jsvIsFunction(pingCallback)) { - jsExceptionHere(JSET_ERROR, "Callback is not a function."); + jsExceptionHere(JSET_ERROR, "Callback is not a function"); return; } else { if (g_jsPingCallback != NULL) { @@ -1378,13 +1378,13 @@ static void pingRecvCB(void *pingOpt, void *pingResponse) { // worker for jswrap_wifi_setIP and jswrap_wifi_setAPIP static void setIP(JsVar *jsSettings, JsVar *jsCallback, int interface) { DBGV("> setIP\n"); - + char ipTmp[20]; int len = 0; bool rc = false; memset(&info, 0, sizeof(info)); -// first check parameter +// first check parameter if (!jsvIsObject(jsSettings)) { EXPECT_OPT_EXCEPTION(jsSettings); return; @@ -1395,13 +1395,13 @@ static void setIP(JsVar *jsSettings, JsVar *jsCallback, int interface) { if (jsIP != NULL && !jsvIsString(jsIP)) { EXPECT_OPT_EXCEPTION(jsIP); jsvUnLock(jsIP); - return; + return; } jsvGetString(jsIP, ipTmp, sizeof(ipTmp)-1); //DBG(">> ip: %s\n",ipTmp); - info.ip.addr = networkParseIPAddress(ipTmp); + info.ip.addr = networkParseIPAddress(ipTmp); if ( info.ip.addr == 0) { - jsExceptionHere(JSET_ERROR, "Not a valid IP address."); + jsExceptionHere(JSET_ERROR, "Not a valid IP address"); jsvUnLock(jsIP); return; } @@ -1418,7 +1418,7 @@ static void setIP(JsVar *jsSettings, JsVar *jsCallback, int interface) { //DBG(">> gw: %s\n",ipTmp); info.gw.addr = networkParseIPAddress(ipTmp); if (info.gw.addr == 0) { - jsExceptionHere(JSET_ERROR, "Not a valid Gateway address."); + jsExceptionHere(JSET_ERROR, "Not a valid Gateway address"); jsvUnLock(jsGW); return; } @@ -1430,13 +1430,13 @@ static void setIP(JsVar *jsSettings, JsVar *jsCallback, int interface) { EXPECT_OPT_EXCEPTION(jsNM); jsvUnLock(jsNM); return; - } + } jsvGetString(jsNM, ipTmp, sizeof(ipTmp)-1); //DBG(">> netmask: %s\n",ipTmp); - info.netmask.addr = networkParseIPAddress(ipTmp); + info.netmask.addr = networkParseIPAddress(ipTmp); if (info.netmask.addr == 0) { - jsExceptionHere(JSET_ERROR, "Not a valid Netmask."); - jsvUnLock(jsNM); + jsExceptionHere(JSET_ERROR, "Not a valid Netmask"); + jsvUnLock(jsNM); return; } jsvUnLock(jsNM); @@ -1459,11 +1459,11 @@ static void setIP(JsVar *jsSettings, JsVar *jsCallback, int interface) { if (jsvIsFunction(jsCallback)) { JsVar *params[1]; params[0] = rc ? jsvNewWithFlags(JSV_NULL) : jsvNewFromString("Failure"); - jsiQueueEvents(NULL, jsCallback, params, 1); + jsiQueueEvents(NULL, jsCallback, params, 1); jsvUnLock(params[0]); } else { - jsExceptionHere(JSET_ERROR, "Callback is not a function."); + jsExceptionHere(JSET_ERROR, "Callback is not a function"); } DBGV("< setIP\n"); return ; @@ -1644,7 +1644,7 @@ static void wifiEventHandler(System_Event_t *evt) { // need two more cases if ((wifiConnectStatus == STATION_WRONG_PASSWORD || wifiConnectStatus == STATION_NO_AP_FOUND || - wifiConnectStatus == STATION_CONNECT_FAIL ) + wifiConnectStatus == STATION_CONNECT_FAIL ) && jsvIsFunction(g_jsGotIpCallback)) { sendWifiCompletionCB(&g_jsGotIpCallback, wifiConn[wifiConnectStatus]); } @@ -1655,7 +1655,7 @@ static void wifiEventHandler(System_Event_t *evt) { sendWifiCompletionCB(&g_jsGotIpCallback, reason); } - + // if we're in the process of disconnecting we want to turn STA mode off now // at that point we may need to make a callback too if (g_disconnecting) { diff --git a/libs/network/network.c b/libs/network/network.c index 7b8f812647..93240a115f 100644 --- a/libs/network/network.c +++ b/libs/network/network.c @@ -397,7 +397,7 @@ JsVar *load_cert_file(JsVar *cert) { if (started && pPtr[i] != '\n' && pPtr[i] != '\r') { pPtr[j++] = pPtr[i]; } - } + } JsVar *parsed = jsvNewFromString((const char *)pPtr); /* convert to binary */ @@ -452,7 +452,7 @@ bool ssl_load_key(SSLSocketData *sd, JsVar *options) { jsvUnLock(keyVar); if (ret != 0) { JsVar *e = jswrap_crypto_error_to_jsvar(ret); - jsExceptionHere(JSET_INTERNALERROR, "HTTPS init failed! mbedtls_pk_parse_key: %v\n", e); + jsExceptionHere(JSET_INTERNALERROR, "HTTPS init failed! mbedtls_pk_parse_key: %v", e); jsvUnLock(e); return false; } @@ -477,7 +477,7 @@ bool ssl_load_owncert(SSLSocketData *sd, JsVar *options) { jsvUnLock(certVar); if (ret != 0) { JsVar *e = jswrap_crypto_error_to_jsvar(ret); - jsExceptionHere(JSET_INTERNALERROR, "HTTPS init failed! mbedtls_x509_crt_parse of 'cert': %v\n", e); + jsExceptionHere(JSET_INTERNALERROR, "HTTPS init failed! mbedtls_x509_crt_parse of 'cert': %v", e); jsvUnLock(e); return false; } @@ -501,7 +501,7 @@ bool ssl_load_cacert(SSLSocketData *sd, JsVar *options) { jsvUnLock(caVar); if (ret != 0) { JsVar *e = jswrap_crypto_error_to_jsvar(ret); - jsExceptionHere(JSET_INTERNALERROR, "HTTPS init failed! mbedtls_x509_crt_parse of 'ca': %v\n", e); + jsExceptionHere(JSET_INTERNALERROR, "HTTPS init failed! mbedtls_x509_crt_parse of 'ca': %v", e); jsvUnLock(e); return false; } @@ -530,7 +530,7 @@ bool ssl_newSocketData(int sckt, JsVar *options) { } JsVar *sslData = jsvNewFlatStringOfLength(sizeof(SSLSocketData)); if (!sslData) { - jsExceptionHere(JSET_INTERNALERROR, "Not enough memory to allocate SSL socket\n"); + jsExceptionHere(JSET_INTERNALERROR, "Not enough memory to allocate SSL socket"); jsvUnLock(sslDataVar); return false; } @@ -559,7 +559,7 @@ bool ssl_newSocketData(int sckt, JsVar *options) { (const unsigned char *) pers, strlen(pers))) != 0 ) { JsVar *e = jswrap_crypto_error_to_jsvar(ret); - jsExceptionHere(JSET_INTERNALERROR, "HTTPS init failed! mbedtls_ctr_drbg_seed: %v\n", e ); + jsExceptionHere(JSET_INTERNALERROR, "HTTPS init failed! mbedtls_ctr_drbg_seed: %v", e ); jsvUnLock(e); ssl_freeSocketData(sckt); return false; @@ -579,7 +579,7 @@ bool ssl_newSocketData(int sckt, JsVar *options) { MBEDTLS_SSL_TRANSPORT_STREAM, MBEDTLS_SSL_PRESET_DEFAULT )) != 0 ) { JsVar *e = jswrap_crypto_error_to_jsvar(ret); - jsExceptionHere(JSET_INTERNALERROR, "HTTPS init failed! mbedtls_ssl_config_defaults returned: %v\n", e ); + jsExceptionHere(JSET_INTERNALERROR, "HTTPS init failed! mbedtls_ssl_config_defaults returned: %v", e ); jsvUnLock(e); ssl_freeSocketData(sckt); return false; @@ -589,7 +589,7 @@ bool ssl_newSocketData(int sckt, JsVar *options) { // this would get set if options.key was set if (( ret = mbedtls_ssl_conf_own_cert(&sd->conf, &sd->owncert, &sd->pkey)) != 0 ) { JsVar *e = jswrap_crypto_error_to_jsvar(ret); - jsExceptionHere(JSET_INTERNALERROR, "HTTPS init failed! mbedtls_ssl_conf_own_cert: %v\n", e ); + jsExceptionHere(JSET_INTERNALERROR, "HTTPS init failed! mbedtls_ssl_conf_own_cert: %v", e ); jsvUnLock(e); ssl_freeSocketData(sckt); return false; @@ -603,7 +603,7 @@ bool ssl_newSocketData(int sckt, JsVar *options) { if (( ret = mbedtls_ssl_setup( &sd->ssl, &sd->conf )) != 0) { JsVar *e = jswrap_crypto_error_to_jsvar(ret); - jsExceptionHere(JSET_INTERNALERROR, "Failed! mbedtls_ssl_setup: %v\n", e ); + jsExceptionHere(JSET_INTERNALERROR, "Failed! mbedtls_ssl_setup: %v", e ); jsvUnLock(e); ssl_freeSocketData(sckt); return false; @@ -611,7 +611,7 @@ bool ssl_newSocketData(int sckt, JsVar *options) { if (( ret = mbedtls_ssl_set_hostname( &sd->ssl, "mbed TLS Server 1" )) != 0) { JsVar *e = jswrap_crypto_error_to_jsvar(ret); - jsExceptionHere(JSET_INTERNALERROR, "HTTPS init failed! mbedtls_ssl_set_hostname: %v\n", e ); + jsExceptionHere(JSET_INTERNALERROR, "HTTPS init failed! mbedtls_ssl_set_hostname: %v", e ); jsvUnLock(e); ssl_freeSocketData(sckt); return false; @@ -644,7 +644,7 @@ SSLSocketData *ssl_getSocketData(int sckt) { if ( ( ret = mbedtls_ssl_handshake( &sd->ssl ) ) != 0 ) { if( ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE ) { JsVar *e = jswrap_crypto_error_to_jsvar(ret); - jsExceptionHere(JSET_INTERNALERROR, "Failed! mbedtls_ssl_handshake returned %v\n", e ); + jsExceptionHere(JSET_INTERNALERROR, "Failed! mbedtls_ssl_handshake returned %v", e ); jsvUnLock(e); return 0; // this signals an error } @@ -658,7 +658,7 @@ SSLSocketData *ssl_getSocketData(int sckt) { if( ( flags = mbedtls_ssl_get_verify_result( &sd->ssl ) ) != 0 ) { char vrfy_buf[512]; mbedtls_x509_crt_verify_info( vrfy_buf, sizeof( vrfy_buf ), " ! ", flags ); - jsExceptionHere(JSET_INTERNALERROR, "Failed! %s\n", vrfy_buf ); + jsExceptionHere(JSET_INTERNALERROR, "Failed! %s", vrfy_buf ); return 0; } sd->connecting = false; diff --git a/libs/network/socketserver.c b/libs/network/socketserver.c index 7b6689b7de..0f95cd7bbc 100644 --- a/libs/network/socketserver.c +++ b/libs/network/socketserver.c @@ -868,7 +868,7 @@ void serverListen(JsNetwork *net, JsVar *server, unsigned short port, SocketType int sckt = netCreateSocket(net, socketType, 0/*server*/, port, options); if (sckt<0) { - jsExceptionHere(JSET_INTERNALERROR, "Unable to create socket\n"); + jsExceptionHere(JSET_INTERNALERROR, "Unable to create socket"); jsvObjectSetChildAndUnLock(server, HTTP_NAME_CLOSENOW, jsvNewFromBool(true)); } else { jsvObjectSetChildAndUnLock(server, HTTP_NAME_SOCKET, jsvNewFromInteger(sckt+1)); @@ -935,7 +935,7 @@ JsVar *clientRequestNew(SocketType socketType, JsVar *options, JsVar *callback) void clientRequestWrite(JsNetwork *net, JsVar *httpClientReqVar, JsVar *data, JsVar *host, unsigned short portNumber) { if (!_socketConnectionOpen(httpClientReqVar)) { - jsExceptionHere(JSET_ERROR, "This socket is closed."); + jsExceptionHere(JSET_ERROR, "This socket is closed"); return; } SocketType socketType = socketGetType(httpClientReqVar); @@ -1043,7 +1043,7 @@ void clientRequestConnect(JsNetwork *net, JsVar *httpClientReqVar) { if(!host_addr) { - jsExceptionHere(JSET_INTERNALERROR, "Unable to locate host\n"); + jsExceptionHere(JSET_INTERNALERROR, "Unable to locate host"); // As this is already in the list of connections, an error will be thrown on idle anyway jsvObjectSetChildAndUnLock(httpClientReqVar, HTTP_NAME_CLOSENOW, jsvNewFromBool(true)); jsvUnLock(options); @@ -1062,7 +1062,7 @@ void clientRequestConnect(JsNetwork *net, JsVar *httpClientReqVar) { int sckt = netCreateSocket(net, socketType, host_addr, port, options); if (sckt<0) { - jsExceptionHere(JSET_INTERNALERROR, "Unable to create socket\n"); + jsExceptionHere(JSET_INTERNALERROR, "Unable to create socket"); // As this is already in the list of connections, an error will be thrown on idle anyway jsvObjectSetChildAndUnLock(httpClientReqVar, HTTP_NAME_CLOSENOW, jsvNewFromBool(true)); } else { @@ -1148,7 +1148,7 @@ void serverResponseWriteHead(JsVar *httpServerResponseVar, int statusCode, JsVar void serverResponseWrite(JsVar *httpServerResponseVar, JsVar *data) { if (!_socketConnectionOpen(httpServerResponseVar)) { - jsExceptionHere(JSET_ERROR, "This socket is closed."); + jsExceptionHere(JSET_ERROR, "This socket is closed"); return; } // Append data to sendData diff --git a/libs/network/wiznet/jswrap_wiznet.c b/libs/network/wiznet/jswrap_wiznet.c index 12a1c595c7..b550852104 100644 --- a/libs/network/wiznet/jswrap_wiznet.c +++ b/libs/network/wiznet/jswrap_wiznet.c @@ -108,7 +108,7 @@ JsVar *jswrap_wiznet_connect(JsVar *spi, Pin cs) { jshSPISetup(ETH_SPI, &inf); spiDevice = ETH_SPI; #else - jsExceptionHere(JSET_ERROR, "No default SPI on this platform - you must specify one."); + jsExceptionHere(JSET_ERROR, "No default SPI on this platform - you must specify one"); return 0; #endif } @@ -418,16 +418,16 @@ JsVar * jswrap_ethernet_getStatus( JsVar *wlanObj, JsVar *callback) { jsvObjectSetChildAndUnLock(jsStatus, "state", jsvNewFromString(state[networkState])); - ctlwizchip(CW_GET_ID,(void*)tmpstr); + ctlwizchip(CW_GET_ID,(void*)tmpstr); jsvObjectSetChildAndUnLock(jsStatus, "id",jsvNewFromString(tmpstr)); ctlwizchip(CW_GET_PHYLINK, (void*)&tmp); jsvObjectSetChildAndUnLock(jsStatus, "phylink", jsvNewFromString(phylink[tmp])); - + ctlwizchip(CW_GET_PHYPOWMODE,(void*)&tmp); jsvObjectSetChildAndUnLock(jsStatus, "phypowmode", jsvNewFromString(phypowm[tmp])); -#if _WIZCHIP_ == 5500 +#if _WIZCHIP_ == 5500 wiz_PhyConf tmpPhycConf; ctlwizchip(CW_GET_PHYCONF,(void*)&tmpPhycConf); jsvObjectSetChildAndUnLock(jsStatus, "by", jsvNewFromInteger(tmpPhycConf.by)); @@ -445,6 +445,6 @@ JsVar * jswrap_ethernet_getStatus( JsVar *wlanObj, JsVar *callback) { params[1] = jsStatus; jsiQueueEvents(NULL, callback, params, 2); jsvUnLock(params[0]); - } + } return jsStatus; } diff --git a/src/jsjit.c b/src/jsjit.c index 7241151318..765c2ddfac 100644 --- a/src/jsjit.c +++ b/src/jsjit.c @@ -377,7 +377,7 @@ void jsjFactor() { JSP_ASSERT_MATCH(LEX_R_NULL); if (jit.phase == JSJP_EMIT) { jsjcLiteral32(0, JSV_NULL); - jsjcCall(jsvNewWithFlags); + jsjcCall(jsvNewWithFlagsX); jsjcPush(0, JSJVT_JSVAR_NO_NAME); // a value, not a NAME } } else if (lex->tk==LEX_R_UNDEFINED) { @@ -718,7 +718,7 @@ void __jsjBinaryExpression(unsigned int lastPrecedence) { } a = jsvNewFromBool(found); } else { // not built-in, just assume we can't do it - jsExceptionHere(JSET_ERROR, "Cannot use 'in' operator to search a %t", bv); + jsExceptionHere(JSET_ERROR, "Can't use 'in' operator to search a %t", bv); jsvUnLock(a); a = 0; } diff --git a/src/jsparse.c b/src/jsparse.c index d2c0964157..1e88088d2a 100644 --- a/src/jsparse.c +++ b/src/jsparse.c @@ -1121,7 +1121,7 @@ NO_INLINE JsVar *jspeFactorMember(JsVar *a, JsVar **parentResult) { jsvUnLock(nameVar); } else { // could have been a string... - jsExceptionHere(JSET_ERROR, "Cannot read property '%s' of %s", name, jsvIsUndefined(aVar) ? "undefined" : "null"); + jsExceptionHere(JSET_ERROR, "Can't read property '%s' of %s", name, jsvIsUndefined(aVar) ? "undefined" : "null"); } } jsvUnLock(parent); @@ -1836,7 +1836,7 @@ NO_INLINE JsVar *jspeFactor() { } else if (lex->tk==LEX_REGEX) { JsVar *a = 0; #ifdef ESPR_NO_REGEX - jsExceptionHere(JSET_SYNTAXERROR, "RegEx are not supported in this version of Espruino\n"); + jsExceptionHere(JSET_SYNTAXERROR, "RegEx are not supported in this version of Espruino"); #else if (JSP_SHOULD_EXECUTE) { JsVar *regex = jslGetTokenValueAsVar(); @@ -1892,7 +1892,7 @@ NO_INLINE JsVar *jspeFactor() { return 0; } JSP_MATCH(LEX_EOF); - jsExceptionHere(JSET_SYNTAXERROR, "Unexpected end of Input\n"); + jsExceptionHere(JSET_SYNTAXERROR, "Unexpected end of Input"); return 0; } @@ -2064,7 +2064,7 @@ NO_INLINE JsVar *__jspeBinaryExpression(JsVar *a, unsigned int lastPrecedence) { } a = jsvNewFromBool(found); } else { // not built-in, just assume we can't do it - jsExceptionHere(JSET_ERROR, "Cannot use 'in' operator to search a %t", bv); + jsExceptionHere(JSET_ERROR, "Can't use 'in' operator to search a %t", bv); jsvUnLock(a); a = 0; } @@ -2810,7 +2810,7 @@ NO_INLINE JsVar *jspeStatementFor() { #ifdef JSPARSE_MAX_LOOP_ITERATIONS if (loopCount<=0) { - jsExceptionHere(JSET_ERROR, "FOR Loop exceeded the maximum number of iterations ("STRINGIFY(JSPARSE_MAX_LOOP_ITERATIONS)")"); + jsExceptionHere(JSET_ERROR, "FOR loop exceeded the maximum number of iterations ("STRINGIFY(JSPARSE_MAX_LOOP_ITERATIONS)")"); } #endif } @@ -2892,7 +2892,7 @@ NO_INLINE JsVar *jspeStatementReturn() { jsvUnLock(resultVar); execInfo.execute |= EXEC_RETURN; // Stop anything else in this function executing } else { - jsExceptionHere(JSET_SYNTAXERROR, "RETURN statement, but not in a function.\n"); + jsExceptionHere(JSET_SYNTAXERROR, "RETURN statement, but not in a function."); } } jsvUnLock(result); diff --git a/src/jspin.c b/src/jspin.c index 742d51de5e..3a8cac5700 100644 --- a/src/jspin.c +++ b/src/jspin.c @@ -247,7 +247,7 @@ bool jshPinInput( value = jshPinGetValue(pin); } // Handle pin being invalid. - else jsExceptionHere(JSET_ERROR, "Invalid pin!"); + else jsExceptionHere(JSET_ERROR, "Invalid pin"); return value; } @@ -265,7 +265,7 @@ void jshPinOutput( jshPinSetState(pin, JSHPINSTATE_GPIO_OUT); } // Handle pin being invalid. - else jsExceptionHere(JSET_ERROR, "Invalid pin!"); + else jsExceptionHere(JSET_ERROR, "Invalid pin"); } diff --git a/src/jsserial.c b/src/jsserial.c index 676129150d..58f06d6cff 100644 --- a/src/jsserial.c +++ b/src/jsserial.c @@ -230,7 +230,7 @@ bool jsserialEventCallbackInit(JsVar *parent, JshUSARTInfo *inf) { jsvUnLock(list); jshSetEventCallback(exti, jsserialEventCallback); } else { - jsExceptionHere(JSET_ERROR, "Unable to watch pin %p, no Software Serial RX\n", inf->pinRX); + jsExceptionHere(JSET_ERROR, "Unable to watch pin %p, no Software Serial RX", inf->pinRX); return false; } diff --git a/src/jsvar.c b/src/jsvar.c index c07601f11b..427dbc8525 100644 --- a/src/jsvar.c +++ b/src/jsvar.c @@ -2131,7 +2131,7 @@ JsVarInt jsvGetInteger(const JsVar *v) { if (jsvIsString(v) && jsvIsStringNumericInt(v, true/* allow decimal point*/)) { char buf[32]; if (jsvGetString(v, buf, sizeof(buf))==sizeof(buf)) - jsExceptionHere(JSET_ERROR, "String too big to convert to integer\n"); + jsExceptionHere(JSET_ERROR, "String too big to convert to integer"); else return (JsVarInt)stringToInt(buf); } @@ -2197,7 +2197,7 @@ JsVarFloat jsvGetFloat(const JsVar *v) { if (jsvIsString(v)) { char buf[64]; if (jsvGetString(v, buf, sizeof(buf))==sizeof(buf)) { - jsExceptionHere(JSET_ERROR, "String too big to convert to float\n"); + jsExceptionHere(JSET_ERROR, "String too big to convert to float"); } else { if (buf[0]==0) return 0; // empty string -> 0 if (!strcmp(buf,"Infinity")) return INFINITY; @@ -2223,7 +2223,7 @@ JsVar *jsvAsNumber(JsVar *var) { // handle strings like this, in case they're too big for an int char buf[64]; if (jsvGetString(var, buf, sizeof(buf))==sizeof(buf)) { - jsExceptionHere(JSET_ERROR, "String too big to convert to integer\n"); + jsExceptionHere(JSET_ERROR, "String too big to convert to integer"); return jsvNewFromFloat(NAN); } else return jsvNewFromLongInteger(stringToInt(buf)); diff --git a/src/jswrap_arraybuffer.c b/src/jswrap_arraybuffer.c index 3f21fcd735..918aa0e4f4 100644 --- a/src/jswrap_arraybuffer.c +++ b/src/jswrap_arraybuffer.c @@ -238,11 +238,11 @@ Create an Array Buffer object */ JsVar *jswrap_arraybuffer_constructor(JsVarInt byteLength) { if (byteLength < 0) { - jsExceptionHere(JSET_ERROR, "Invalid length for ArrayBuffer\n"); + jsExceptionHere(JSET_ERROR, "Invalid length for ArrayBuffer"); return 0; } if (byteLength > JSV_ARRAYBUFFER_MAX_LENGTH) { - jsExceptionHere(JSET_ERROR, "ArrayBuffer too long\n"); + jsExceptionHere(JSET_ERROR, "ArrayBuffer too long"); return 0; } // try and use a flat string - which will be faster @@ -531,11 +531,11 @@ JsVar *jswrap_typedarray_constructor(JsVarDataArrayBufferViewType type, JsVar *a copyData = true; // so later on we'll populate this } if (!arrayBuffer) { - jsExceptionHere(JSET_ERROR, "Unsupported first argument of type %t\n", arr); + jsExceptionHere(JSET_ERROR, "Unsupported first argument of type %t", arr); return 0; } if (length==0) { - length = ((JsVarInt)jsvGetArrayBufferLength(arrayBuffer)-byteOffset) / (JsVarInt)JSV_ARRAYBUFFER_GET_SIZE(type); + length = ((JsVarInt)jsvGetArrayBufferLength(arrayBuffer)-byteOffset) / (JsVarInt)JSV_ARRAYBUFFER_GET_SIZE(type); if (length<0) length=0; } JsVar *typedArr = jsvNewWithFlags(JSV_ARRAYBUFFER); diff --git a/src/jswrap_functions.c b/src/jswrap_functions.c index f3c9c8d862..d7d3cdc2f4 100644 --- a/src/jswrap_functions.c +++ b/src/jswrap_functions.c @@ -182,7 +182,7 @@ JsVar *jswrap_parseInt(JsVar *v, JsVar *radixVar) { // probably had to miss some stuff off the end of the string // in jsvGetString if (endOfInteger == &buffer[sizeof(buffer)-1]) { - jsExceptionHere(JSET_ERROR, "String too big to convert to integer\n"); + jsExceptionHere(JSET_ERROR, "String too big to convert to integer"); return jsvNewFromFloat(NAN); } return jsvNewFromLongInteger(i); @@ -210,7 +210,7 @@ JsVarFloat jswrap_parseFloat(JsVar *v) { // probably had to miss some stuff off the end of the string // in jsvGetString if (endOfFloat == &buffer[sizeof(buffer)-1]) { - jsExceptionHere(JSET_ERROR, "String too big to convert to float\n"); + jsExceptionHere(JSET_ERROR, "String too big to convert to float"); return NAN; } return f; @@ -486,7 +486,7 @@ JsVar *jswrap_decodeURIComponent(JsVar *arg) { while (jsvStringIteratorHasChar(&it)) { char ch = jsvStringIteratorGetCharAndNext(&it); if (ch>>7) { - jsExceptionHere(JSET_ERROR, "ASCII only\n"); + jsExceptionHere(JSET_ERROR, "ASCII only"); break; } if (ch!='%') { @@ -496,7 +496,7 @@ JsVar *jswrap_decodeURIComponent(JsVar *arg) { char lo = (char)jsvStringIteratorGetCharAndNext(&it); int v = (char)hexToByte(hi,lo); if (v<0) { - jsExceptionHere(JSET_ERROR, "Invalid URI\n"); + jsExceptionHere(JSET_ERROR, "Invalid URI"); break; } ch = (char)v; diff --git a/src/jswrap_interactive.c b/src/jswrap_interactive.c index 9b0584d66e..b1e544bfff 100644 --- a/src/jswrap_interactive.c +++ b/src/jswrap_interactive.c @@ -556,7 +556,7 @@ void _jswrap_interface_clearTimeoutOrInterval(JsVar *idVarArr, bool isTimeout) { if (!watchPtr) jsvObjectIteratorRemoveAndGotoNext(&it, timerArrayPtr); else - jsvObjectIteratorNext(&it); + jsvObjectIteratorNext(&it); jsvUnLock2(watchPtr, timerPtr); } jsvObjectIteratorFree(&it); @@ -564,7 +564,7 @@ void _jswrap_interface_clearTimeoutOrInterval(JsVar *idVarArr, bool isTimeout) { JsVar *idVar = jsvGetArrayItem(idVarArr, 0); if (jsvIsUndefined(idVar)) { const char *name = isTimeout?"Timeout":"Interval"; - jsExceptionHere(JSET_ERROR, "clear%s(undefined) not allowed. Use clear%s() instead.", name, name); + jsExceptionHere(JSET_ERROR, "clear%s(undefined) not allowed. Use clear%s() instead", name, name); } else { JsVar *child = jsvIsBasic(idVar) ? jsvFindChildFromVar(timerArrayPtr, idVar, false) : 0; if (child) { diff --git a/src/jswrap_io.c b/src/jswrap_io.c index b09e38b766..c66edc4c26 100644 --- a/src/jswrap_io.c +++ b/src/jswrap_io.c @@ -248,7 +248,7 @@ anything over a few milliseconds, use setTimeout instead. */ void jswrap_io_digitalPulse(Pin pin, bool value, JsVar *times) { if (!jshIsPinValid(pin)) { - jsExceptionHere(JSET_ERROR, "Invalid pin!"); + jsExceptionHere(JSET_ERROR, "Invalid pin"); return; } // check for currently running timer tasks @@ -337,7 +337,7 @@ void jswrap_io_digitalWrite( JsVar *v = jsvNewFromInteger(value); jsvUnLock(jspeFunctionCall(w,0,pinVar,false,1,&v)); jsvUnLock(v); - } else jsExceptionHere(JSET_ERROR, "Invalid pin!"); + } else jsExceptionHere(JSET_ERROR, "Invalid pin"); jsvUnLock(w); } else { // Handle the case where it is a single pin. @@ -391,7 +391,7 @@ JsVarInt jswrap_io_digitalRead(JsVar *pinVar) { JsVar *r = jspGetNamedField(pinVar, "read", false); if (jsvIsFunction(r)) { v = jsvGetIntegerAndUnLock(jspeFunctionCall(r,0,pinVar,false,0,0)); - } else jsExceptionHere(JSET_ERROR, "Invalid pin!"); + } else jsExceptionHere(JSET_ERROR, "Invalid pin"); jsvUnLock(r); return v; } else { @@ -629,7 +629,7 @@ void jswrap_io_shiftOut(JsVar *pins, JsVar *options, JsVar *data) { jsvObjectIteratorNew(&it, pins); while (jsvObjectIteratorHasValue(&it)) { if (d.cnt>=jswrap_io_shiftOutDataMax) { - jsExceptionHere(JSET_ERROR, "Too many pins! %d Maximum.", jswrap_io_shiftOutDataMax); + jsExceptionHere(JSET_ERROR, "Too many pins! %d Maximum", jswrap_io_shiftOutDataMax); return; } d.pins[d.cnt] = jshGetPinFromVarAndUnLock(jsvObjectIteratorGetValue(&it)); @@ -888,7 +888,7 @@ void jswrap_interface_clearWatch(JsVar *idVarArr) { } else { JsVar *idVar = jsvGetArrayItem(idVarArr, 0); if (jsvIsUndefined(idVar)) { - jsExceptionHere(JSET_ERROR, "clearWatch(undefined) not allowed. Use clearWatch() instead."); + jsExceptionHere(JSET_ERROR, "clearWatch(undefined) not allowed. Use clearWatch() instead"); return; } JsVar *watchArrayPtr = jsvLock(watchArray); diff --git a/src/jswrap_modules.c b/src/jswrap_modules.c index f04149abe3..08db5bf1ea 100644 --- a/src/jswrap_modules.c +++ b/src/jswrap_modules.c @@ -109,7 +109,7 @@ JsVar *jswrap_require(JsVar *moduleName) { if (!moduleExport) { const char *builtInJS = jswGetBuiltInJSLibrary(moduleNameBuf); if (builtInJS) { - JsVar *fileContents = jsvNewNativeString((char*)builtInJS, strlen(builtInJS)); + JsVar *fileContents = jsvNewNativeString((char*)builtInJS, strlen(builtInJS)); if (fileContents) { moduleExport = jspEvaluateModule(fileContents); jsvUnLock(fileContents); @@ -120,7 +120,7 @@ JsVar *jswrap_require(JsVar *moduleName) { // If we have filesystem support, look on the filesystem #ifdef USE_FILESYSTEM if (!moduleExport) { - JsVar *fileContents = 0; + JsVar *fileContents = 0; JsVar *modulePath = jsvNewFromString("node_modules/"); if (modulePath) { // out of memory jsvAppendString(modulePath, moduleNameBuf); @@ -138,8 +138,8 @@ JsVar *jswrap_require(JsVar *moduleName) { jsvUnLock(fileContents); } } -#endif - +#endif + if (moduleExport) { // Found - now save module JsVar *moduleList = jswrap_modules_getModuleList(); @@ -157,7 +157,7 @@ JsVar *jswrap_require(JsVar *moduleName) { } #endif // nope. no module - jsExceptionHere(JSET_ERROR, "Module %s not found", moduleNameBuf); + jsExceptionHere(JSET_ERROR, "Module %q not found", moduleName); } return moduleExport; diff --git a/src/jswrap_object.c b/src/jswrap_object.c index 21b11ff6f7..be9fd77aff 100644 --- a/src/jswrap_object.c +++ b/src/jswrap_object.c @@ -654,11 +654,11 @@ information */ JsVar *jswrap_object_defineProperties(JsVar *parent, JsVar *props) { if (!jsvIsObject(parent)) { - jsExceptionHere(JSET_ERROR, "First argument must be an object, got %t\n", parent); + jsExceptionHere(JSET_ERROR, "First argument must be an object, got %t", parent); return 0; } if (!jsvIsObject(props)) { - jsExceptionHere(JSET_ERROR, "Second argument must be an object, got %t\n", props); + jsExceptionHere(JSET_ERROR, "Second argument must be an object, got %t", props); return 0; } @@ -709,7 +709,7 @@ prototype` but is the 'proper' ES6 way of doing it JsVar *jswrap_object_setPrototypeOf(JsVar *object, JsVar *proto) { JsVar *v = (jsvIsFunction(object)||jsvIsObject(object)) ? jsvFindChildFromString(object, "__proto__", true) : 0; if (!jsvIsName(v)) { - jsExceptionHere(JSET_TYPEERROR, "Can't extend %t\n", v); + jsExceptionHere(JSET_TYPEERROR, "Can't extend %t", v); } else { jsvSetValueOfName(v, proto); } @@ -743,7 +743,7 @@ JsVar *jswrap_object_assign(JsVar *args) { if (jsvIsUndefined(arg) || jsvIsNull(arg)) { // ignore } else if (!jsvIsObject(arg)) { - jsExceptionHere(JSET_TYPEERROR, "Expecting Object, got %t\n", arg); + jsExceptionHere(JSET_TYPEERROR, "Expecting Object, got %t", arg); error = true; } else if (!result) { result = jsvLockAgain(arg); @@ -863,7 +863,7 @@ An alias for `Object.on` #ifndef ESPR_EMBED void jswrap_object_on_X(JsVar *parent, JsVar *event, JsVar *listener, bool addFirst) { if (!jsvHasChildren(parent)) { - jsExceptionHere(JSET_TYPEERROR, "Parent must be an object - not a String, Integer, etc."); + jsExceptionHere(JSET_TYPEERROR, "Parent must be an object - not a String, Integer, etc"); return; } if (!jsvIsString(event)) { @@ -953,7 +953,7 @@ For more information see `Object.on` #ifndef ESPR_EMBED void jswrap_object_emit(JsVar *parent, JsVar *event, JsVar *argArray) { if (!jsvHasChildren(parent)) { - jsExceptionHere(JSET_TYPEERROR, "Parent must be an object - not a String, Integer, etc."); + jsExceptionHere(JSET_TYPEERROR, "Parent must be an object - not a String, Integer, etc"); return; } if (!jsvIsString(event)) { @@ -1014,7 +1014,7 @@ For more information see `Object.on` */ void jswrap_object_removeListener(JsVar *parent, JsVar *event, JsVar *callback) { if (!jsvHasChildren(parent)) { - jsExceptionHere(JSET_TYPEERROR, "Parent must be an object - not a String, Integer, etc."); + jsExceptionHere(JSET_TYPEERROR, "Parent must be an object - not a String, Integer, etc"); return; } if (jsvIsString(event)) { @@ -1067,7 +1067,7 @@ For more information see `Object.on` */ void jswrap_object_removeAllListeners(JsVar *parent, JsVar *event) { if (!jsvHasChildren(parent)) { - jsExceptionHere(JSET_TYPEERROR, "Parent must be an object - not a String, Integer, etc."); + jsExceptionHere(JSET_TYPEERROR, "Parent must be an object - not a String, Integer, etc"); return; } if (jsvIsString(event)) { diff --git a/src/jswrap_pipe.c b/src/jswrap_pipe.c index c6f0b59bc2..915427670f 100644 --- a/src/jswrap_pipe.c +++ b/src/jswrap_pipe.c @@ -125,9 +125,9 @@ static bool handlePipe(JsVar *arr, JsvObjectIterator *it, JsVar* pipe) { } } else { if(!jsvIsFunction(readFunc)) - jsExceptionHere(JSET_ERROR, "Source Stream does not implement the required read(length) method."); + jsExceptionHere(JSET_ERROR, "Source Stream does not implement the required read(length) method"); if(!jsvIsFunction(writeFunc)) - jsExceptionHere(JSET_ERROR, "Destination Stream does not implement the required write(buffer) method."); + jsExceptionHere(JSET_ERROR, "Destination Stream does not implement the required write(buffer) method"); } jsvUnLock2(readFunc, writeFunc); } @@ -302,10 +302,10 @@ void jswrap_pipe(JsVar* source, JsVar* dest, JsVar* options) { // add the pipe to our list jsvArrayPush(arr, pipe); } else { - jsExceptionHere(JSET_ERROR, "Destination object does not implement the required write(buffer, length) method."); + jsExceptionHere(JSET_ERROR, "Destination object does not implement the required write(buffer, length) method"); } } else { - jsExceptionHere(JSET_ERROR, "Source object does not implement the required read(buffer, length) method."); + jsExceptionHere(JSET_ERROR, "Source object does not implement the required read(buffer, length) method"); } jsvUnLock2(readFunc, writeFunc); } diff --git a/src/jswrap_promise.c b/src/jswrap_promise.c index 1c527f5f33..205e4001c1 100644 --- a/src/jswrap_promise.c +++ b/src/jswrap_promise.c @@ -367,7 +367,7 @@ JsVar *jswrap_promise_reject(JsVar *data) { void _jswrap_promise_add(JsVar *parent, JsVar *callback, bool resolve) { if (!jsvIsFunction(callback)) { - jsExceptionHere(JSET_TYPEERROR, "Callback must be a function, got %t", callback); + jsExceptionHere(JSET_TYPEERROR, "Callback is not a function"); return; } diff --git a/src/jswrap_serial.c b/src/jswrap_serial.c index 403cdf1d64..8fc0cda7c8 100644 --- a/src/jswrap_serial.c +++ b/src/jswrap_serial.c @@ -338,9 +338,9 @@ void jswrap_serial_setup(JsVar *parent, JsVar *baud, JsVar *options) { jsserialEventCallbackInit(parent, &inf); } if (inf.pinCK != PIN_UNDEFINED) - jsExceptionHere(JSET_ERROR, "Software Serial CK not implemented yet\n"); + jsExceptionHere(JSET_ERROR, "Software Serial CK not implemented yet"); #else - jsExceptionHere(JSET_ERROR, "No Software Serial in this build\n"); + jsExceptionHere(JSET_ERROR, "No Software Serial in this build"); #endif } } diff --git a/targets/esp32/BLE/esp32_gatts_func.c b/targets/esp32/BLE/esp32_gatts_func.c index 16cdf85824..930144ff23 100644 --- a/targets/esp32/BLE/esp32_gatts_func.c +++ b/targets/esp32/BLE/esp32_gatts_func.c @@ -74,7 +74,7 @@ volatile uint8_t nusBufferLen = 0; void sendNotifBuffer() { - if(uart_gatts_if != ESP_GATT_IF_NONE){ + if(uart_gatts_if != ESP_GATT_IF_NONE){ esp_err_t err = esp_ble_gatts_send_indicate(uart_gatts_if,0,uart_tx_handle,nusBufferLen,nusBuffer,false); // check error? resend if there was one? I think this just blocks if it can't send immediately } @@ -88,11 +88,11 @@ void gatts_sendNUSNotification(int c) { nusBufferLen++; // If our buffer is full, send right away if(nusBufferLen >= BLE_NUS_MAX_DATA_LEN) { - sendNotifBuffer(); + sendNotifBuffer(); } // otherwise, we'll wait until we hit idle next time when gatts_sendNUSNotificationIfNotEmpty will get called } -void gatts_sendNUSNotificationIfNotEmpty() { +void gatts_sendNUSNotificationIfNotEmpty() { if (nusBufferLen) sendNotifBuffer(); } @@ -107,7 +107,7 @@ void emitNRFEvent(char *event,JsVar *args,int argCnt){ jsvUnLock(nrf); jsvUnLock(callback); if(args) jsvUnLockMany(argCnt,args); -} +} int getIndexFromGatts_if(esp_gatt_if_t gatts_if){ for(int i = 0; i < ble_service_cnt;i++){ @@ -244,7 +244,7 @@ static void gatts_disconnect_handler(esp_gatts_cb_event_t event, esp_gatt_if_t g // if we were on bluetooth and we disconnected, clear the input line so we're fresh next time (#2219) if (jsiGetConsoleDevice()==EV_BLUETOOTH) { jsiClearInputLine(false); - if (!jsiIsConsoleDeviceForced()) + if (!jsiIsConsoleDeviceForced()) jsiSetConsoleDevice(jsiGetPreferredConsoleDevice(), 0); } // TODO: Maybe use BLEP_DISCONNECTED handler rather than doing this here? @@ -271,14 +271,14 @@ void gatts_createService(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp gatts_service[param->reg.app_id].service_id.id.inst_id = 0x00; gatts_service[param->reg.app_id].gatts_if = gatts_if; bleuuid_TO_espbtuuid(gatts_service[param->reg.app_id].ble_uuid,&gatts_service[param->reg.app_id].service_id.id); - r = esp_ble_gatts_create_service(gatts_if, &gatts_service[param->reg.app_id].service_id, gatts_service[param->reg.app_id].num_handles); + r = esp_ble_gatts_create_service(gatts_if, &gatts_service[param->reg.app_id].service_id, gatts_service[param->reg.app_id].num_handles); if(r) jsWarn("createService error:%d\n",r); } void gatts_add_char(){ esp_err_t r; for(uint16_t pos=0; pos < ble_char_cnt; pos++){ if(gatts_char[pos].service_pos == ble_service_pos && gatts_char[pos].char_handle == 0){ - ble_char_pos = pos; + ble_char_pos = pos; r = esp_ble_gatts_add_char(gatts_service[ble_service_pos].service_handle,&gatts_char[pos].char_uuid, gatts_char[pos].char_perm,gatts_char[pos].char_property, NULL,gatts_char[pos].char_control); @@ -458,11 +458,11 @@ void gatts_char_init(JsvObjectIterator *ble_char_it){ gatts_char[ble_char_pos].char_uuid.uuid.uuid16 = ble_uuid.uuid; gatts_char[ble_char_pos].char_perm = 0; if (jsvGetBoolAndUnLock(jsvObjectGetChildIfExists(charVar, "broadcast"))) - gatts_char[ble_char_pos].char_property += ESP_GATT_CHAR_PROP_BIT_BROADCAST; + gatts_char[ble_char_pos].char_property += ESP_GATT_CHAR_PROP_BIT_BROADCAST; if (jsvGetBoolAndUnLock(jsvObjectGetChildIfExists(charVar, "notify"))) - gatts_char[ble_char_pos].char_property += ESP_GATT_CHAR_PROP_BIT_NOTIFY; + gatts_char[ble_char_pos].char_property += ESP_GATT_CHAR_PROP_BIT_NOTIFY; if (jsvGetBoolAndUnLock(jsvObjectGetChildIfExists(charVar, "indicate"))) - gatts_char[ble_char_pos].char_property += ESP_GATT_CHAR_PROP_BIT_INDICATE; + gatts_char[ble_char_pos].char_property += ESP_GATT_CHAR_PROP_BIT_INDICATE; if (jsvGetBoolAndUnLock(jsvObjectGetChildIfExists(charVar, "readable"))){ gatts_char[ble_char_pos].char_perm += ESP_GATT_PERM_READ; gatts_char[ble_char_pos].char_property += ESP_GATT_CHAR_PROP_BIT_READ; @@ -501,7 +501,7 @@ void gatts_char_init(JsvObjectIterator *ble_char_it){ if(charValue){ char hiddenName[12]; bleGetHiddenName(hiddenName,BLE_CHAR_VALUE,ble_char_pos); - jsvObjectSetChildAndUnLock(execInfo.hiddenRoot,hiddenName,charValue); + jsvObjectSetChildAndUnLock(execInfo.hiddenRoot,hiddenName,charValue); } jsvUnLock(charVar); } @@ -509,7 +509,7 @@ void gatts_service_struct_init(JsvObjectIterator *ble_service_it){ ble_uuid_t ble_uuid;uint16_t handles; const char *errorStr; if((errorStr = bleVarToUUIDAndUnLock(&gatts_service[ble_service_pos].ble_uuid, jsvObjectIteratorGetKey(ble_service_it)))){ - jsExceptionHere(JSET_ERROR,"invalid Service UUID:%s",errorStr); + jsExceptionHere(JSET_ERROR,"Invalid Service UUID: %s",errorStr); } handles = 1; //for service bleuuid_To_uuid128(gatts_service[ble_service_pos].ble_uuid,&adv_service_uuid128[ble_service_pos * 16]); @@ -558,9 +558,9 @@ void gatts_structs_init(bool enableUART){ } void gatts_getAdvServiceUUID(uint8_t *p_service_uuid, uint16_t service_len){ p_service_uuid = adv_service_uuid128; - service_len = 16 * ble_service_cnt - 16; + service_len = 16 * ble_service_cnt - 16; } - + // Actually allocates gatts_services with enough space void gatts_create_structs(bool enableUART){ ble_service_cnt = 0; ble_char_cnt = 0; ble_descr_cnt = 0; @@ -572,7 +572,7 @@ void gatts_create_structs(bool enableUART){ JsVar *serviceVar = jsvObjectIteratorGetValue(&ble_service_it); JsvObjectIterator ble_char_it; jsvObjectIteratorNew(&ble_char_it,serviceVar); - while(jsvObjectIteratorHasValue(&ble_char_it)){ + while(jsvObjectIteratorHasValue(&ble_char_it)){ JsVar *charVar = jsvObjectIteratorGetValue(&ble_char_it); JsVar *charDescriptionVar = jsvObjectGetChildIfExists(charVar, "description"); if (charDescriptionVar && jsvHasCharacterData(charDescriptionVar)) ble_descr_cnt++; @@ -598,7 +598,7 @@ void gatts_create_structs(bool enableUART){ gatts_char = calloc(sizeof(struct gatts_char_inst),ble_char_cnt); gatts_descr = calloc(sizeof(struct gatts_descr_inst),ble_descr_cnt); } - + void gatts_set_services(JsVar *data){ JsVar *options = jsvObjectGetChildIfExists(execInfo.hiddenRoot, BLE_NAME_SERVICE_OPTIONS); gatts_reset(true); @@ -620,7 +620,7 @@ void gatts_set_services(JsVar *data){ ble_char_pos = 0; ble_descr_pos = 0; gatts_reg_app(); //this starts tons of api calls creating gatts-events. Ends in gatts_reg_app - if (enableUART) + if (enableUART) setBleUart(); jsvUnLock(options); } diff --git a/targets/esp32/bluetooth.c b/targets/esp32/bluetooth.c index 2f563ffbe0..481aa9fb01 100644 --- a/targets/esp32/bluetooth.c +++ b/targets/esp32/bluetooth.c @@ -31,7 +31,7 @@ #include "BLE/esp32_gattc_func.h" #include "BLE/esp32_bluetooth_utils.h" #include "jshardwareESP32.h" - + volatile BLEStatus bleStatus; ble_uuid_t bleUUIDFilter; uint16_t bleAdvertisingInterval; /**< The advertising interval (in units of 0.625 ms). */ @@ -44,20 +44,20 @@ void jsble_init(){ if(ESP32_Get_NVS_Status(ESP_NETWORK_BLE)) { ret = esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT); if(ret) { - jsExceptionHere(JSET_ERROR,"mem release failed:%x\n",ret); + jsExceptionHere(JSET_ERROR,"mem release failed:%x",ret); return; } - + if(initController()) return; if(initBluedroid()) return; if(registerCallbacks()) return; setMtu(); - gap_init_security(); + gap_init_security(); // force advertising with the right info bleStatus |= BLE_IS_ADVERTISING; } else{ - ret = esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT); + ret = esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT); jsWarn("Bluetooth is disabled per ESP32.enableBLE(false)\n"); } } @@ -121,7 +121,7 @@ void jsble_restart_softdevice(JsVar *jsFunction){ } uint32_t jsble_advertising_start() { - if(!ESP32_Get_NVS_Status(ESP_NETWORK_BLE)) + if(!ESP32_Get_NVS_Status(ESP_NETWORK_BLE)) return ESP_ERR_INVALID_STATE; // ESP32.enableBLE(false) esp_err_t status; if (bleStatus & BLE_IS_ADVERTISING) return; @@ -130,7 +130,7 @@ uint32_t jsble_advertising_start() { return status; } void jsble_advertising_stop() { - if(!ESP32_Get_NVS_Status(ESP_NETWORK_BLE)) + if(!ESP32_Get_NVS_Status(ESP_NETWORK_BLE)) return ESP_ERR_INVALID_STATE; // ESP32.enableBLE(false) esp_err_t status; @@ -143,7 +143,7 @@ void jsble_advertising_stop() { } /** Is BLE connected to any device at all? */ bool jsble_has_connection(){ - if(!ESP32_Get_NVS_Status(ESP_NETWORK_BLE)) + if(!ESP32_Get_NVS_Status(ESP_NETWORK_BLE)) return false; // ESP32.enableBLE(false) #if CENTRAL_LINK_COUNT>0 return (m_central_conn_handles[0] != BLE_GATT_HANDLE_INVALID) || @@ -155,7 +155,7 @@ bool jsble_has_connection(){ /** Is BLE connected to a central device at all? */ bool jsble_has_central_connection(){ - if(!ESP32_Get_NVS_Status(ESP_NETWORK_BLE)) + if(!ESP32_Get_NVS_Status(ESP_NETWORK_BLE)) return false; // ESP32.enableBLE(false) #if CENTRAL_LINK_COUNT>0 return (m_central_conn_handles[0] != BLE_GATT_HANDLE_INVALID); @@ -166,8 +166,8 @@ bool jsble_has_central_connection(){ /** Is BLE connected to a server device at all (eg, the simple, 'slave' mode)? */ bool jsble_has_peripheral_connection(){ - if(!ESP32_Get_NVS_Status(ESP_NETWORK_BLE)) - return false; + if(!ESP32_Get_NVS_Status(ESP_NETWORK_BLE)) + return false; return (m_peripheral_conn_handle != BLE_GATT_HANDLE_INVALID); } @@ -187,8 +187,8 @@ bool jsble_check_error_line(uint32_t err_code, int lineNumber) { } /// Scanning for advertising packets uint32_t jsble_set_scanning(bool enabled, JsVar *options){ - if(!ESP32_Get_NVS_Status(ESP_NETWORK_BLE)) - return ESP_ERR_INVALID_STATE; // ESP32.enableBLE(false) + if(!ESP32_Get_NVS_Status(ESP_NETWORK_BLE)) + return ESP_ERR_INVALID_STATE; // ESP32.enableBLE(false) if (enabled) { if (bleStatus & BLE_IS_SCANNING) return 0; @@ -218,16 +218,16 @@ uint32_t jsble_set_rssi_scan(bool enabled){ * only do this *once* - so to change it we must reset the softdevice and * then call this again */ void jsble_set_services(JsVar *data){ - if(!ESP32_Get_NVS_Status(ESP_NETWORK_BLE)) - return; // ESP32.enableBLE(false) + if(!ESP32_Get_NVS_Status(ESP_NETWORK_BLE)) + return; // ESP32.enableBLE(false) gatts_set_services(data); } /// Disconnect from the given connection uint32_t jsble_disconnect(uint16_t conn_handle){ - if(!ESP32_Get_NVS_Status(ESP_NETWORK_BLE)) - return ESP_ERR_INVALID_STATE; // ESP32.enableBLE(false) + if(!ESP32_Get_NVS_Status(ESP_NETWORK_BLE)) + return ESP_ERR_INVALID_STATE; // ESP32.enableBLE(false) return gattc_disconnect(conn_handle); } @@ -241,7 +241,7 @@ void jsble_send_hid_input_report(uint8_t *data, int length){ /// Connect to the given peer address. When done call bleCompleteTask void jsble_central_connect(ble_gap_addr_t peer_addr, JsVar *options){ - if(!ESP32_Get_NVS_Status(ESP_NETWORK_BLE)) + if(!ESP32_Get_NVS_Status(ESP_NETWORK_BLE)) return; // ESP32.enableBLE(false) // Ignore options for now gattc_connect(peer_addr, options); diff --git a/targets/esp32/jshardwareAnalog.c b/targets/esp32/jshardwareAnalog.c index ca65bf3e78..7f56acf965 100644 --- a/targets/esp32/jshardwareAnalog.c +++ b/targets/esp32/jshardwareAnalog.c @@ -2,7 +2,7 @@ * This file is designed to support Analog functions in Espruino, * a JavaScript interpreter for Microcontrollers designed by Gordon Williams * - * Copyright (C) 2016 by Juergen Marsch + * Copyright (C) 2016 by Juergen Marsch * * This Source Code Form is subject to the terms of the Mozilla Publici * License, v. 2.0. If a copy of the MPL was not distributed with this @@ -86,13 +86,13 @@ void initADC(int ADCgroup){ for(int i = 0; i < adc_channel_max; i++){ adc_channel[i] = ADC_ATTEN_11db; } break; case 2: - jsExceptionHere(JSET_ERROR, "not implemented\n"); + jsExceptionHere(JSET_ERROR, "Not implemented"); break; case 3: - jsExceptionHere(JSET_ERROR, "not implemented\n"); + jsExceptionHere(JSET_ERROR, "Not implemented"); break; default: - jsExceptionHere(JSET_ERROR, "out of range\n"); + jsExceptionHere(JSET_ERROR, "Out of range"); break; } } @@ -115,14 +115,14 @@ int readADC(Pin pin){ value = adc1_get_voltage(channel); return value; } - else return -1; + else return -1; } void writeDAC(Pin pin,uint8_t value){ dac_channel_t channel; if(value > 255){ - jsExceptionHere(JSET_ERROR, "not implemented, only 8 bit supported\n"); - return; + jsExceptionHere(JSET_ERROR, "Not implemented, only 8 bit supported"); + return; } channel = pinToDacChannel(pin); if(channel >= 0) dac_out_voltage(channel, value); diff --git a/targets/esp32/jshardwareI2c.c b/targets/esp32/jshardwareI2c.c index e6a69ee373..7886703ef1 100644 --- a/targets/esp32/jshardwareI2c.c +++ b/targets/esp32/jshardwareI2c.c @@ -14,7 +14,7 @@ * Contains ESP32 board specific functions. * ---------------------------------------------------------------------------- */ - + #include "jshardware.h" #include "jshardwareI2c.h" #include "driver/i2c.h" @@ -28,12 +28,12 @@ #define ACK_VAL 0x0 /*!< I2C ack value */ #define NACK_VAL 0x1 /*!< I2C nack value */ -/* To do: +/* To do: support both i2c ports - done Test! Stop bits param - bool sendStop https://esp-idf.readthedocs.io/en/latest/api/i2c.html - + */ void jshSetDeviceInitialised(IOEventFlags device, bool isInit); @@ -42,7 +42,7 @@ static esp_err_t checkError( char * caller, esp_err_t ret ) { switch(ret) { case ESP_OK: break; case ESP_ERR_INVALID_ARG: { - jsExceptionHere(JSET_ERROR, "%s:, Parameter error\n", caller ); + jsExceptionHere(JSET_ERROR, "%s:, Parameter error", caller ); break; } case ESP_FAIL: { @@ -85,7 +85,7 @@ int getI2cFromDevice( IOEventFlags device ) { void jshI2CSetup(IOEventFlags device, JshI2CInfo *info) { int i2c_master_port = getI2cFromDevice(device); if (i2c_master_port == -1) { - jsExceptionHere(JSET_ERROR,"Only I2C1 and I2C2 supported"); + jsExceptionHere(JSET_ERROR,"Only I2C1 and I2C2 supported"); return; } if(jshIsDeviceInitialised(device)){ @@ -101,7 +101,7 @@ void jshI2CSetup(IOEventFlags device, JshI2CInfo *info) { if ( i2c_master_port == I2C_NUM_1 ) { scl = info->pinSCL != PIN_UNDEFINED ? info->pinSCL : 16; sda = info->pinSDA != PIN_UNDEFINED ? info->pinSDA : 17; - } + } i2c_config_t conf; conf.mode = I2C_MODE_MASTER; @@ -112,7 +112,7 @@ void jshI2CSetup(IOEventFlags device, JshI2CInfo *info) { conf.master.clk_speed = info->bitrate; esp_err_t err=i2c_param_config(i2c_master_port, &conf); if ( err == ESP_ERR_INVALID_ARG ) { - jsExceptionHere(JSET_ERROR,"jshI2CSetup: Invalid arguments"); + jsExceptionHere(JSET_ERROR,"jshI2CSetup: Invalid arguments"); return; } err=i2c_driver_install(i2c_master_port, conf.mode, 0, 0, 0); @@ -120,7 +120,7 @@ void jshI2CSetup(IOEventFlags device, JshI2CInfo *info) { jsDebug(DBG_INFO, "jshI2CSetup: driver installed, sda: %d scl: %d freq: %d, \n", sda, scl, info->bitrate); jshSetDeviceInitialised(device, true); } else { - checkError("jshI2CSetup",err); + checkError("jshI2CSetup",err); } } @@ -128,17 +128,17 @@ void jshI2CWrite(IOEventFlags device, unsigned char address, int nBytes, const unsigned char *data, - bool sendStop) { + bool sendStop) { int i2c_master_port = getI2cFromDevice(device); if (i2c_master_port == -1) { - jsExceptionHere(JSET_ERROR,"Only I2C1 and I2C2 supported"); + jsExceptionHere(JSET_ERROR,"Only I2C1 and I2C2 supported"); return; } esp_err_t ret; i2c_cmd_handle_t cmd = i2c_cmd_link_create(); ret=i2c_master_start(cmd); ret=i2c_master_write_byte(cmd, address << 1 | I2C_MASTER_WRITE, ACK_CHECK_EN); - ret=i2c_master_write(cmd, data, nBytes, ACK_CHECK_EN); + ret=i2c_master_write(cmd, data, nBytes, ACK_CHECK_EN); if ( sendStop ) ret=i2c_master_stop(cmd); ret = i2c_master_cmd_begin(i2c_master_port, cmd, 1000 / portTICK_RATE_MS); // 1000 seems very large for ticks_to_wait??? i2c_cmd_link_delete(cmd); @@ -155,9 +155,9 @@ void jshI2CRead(IOEventFlags device, } int i2c_master_port = getI2cFromDevice(device); if (i2c_master_port == -1) { - jsExceptionHere(JSET_ERROR,"Only I2C1 and I2C2 supported"); + jsExceptionHere(JSET_ERROR,"Only I2C1 and I2C2 supported"); return; - } + } esp_err_t ret; i2c_cmd_handle_t cmd = i2c_cmd_link_create(); ret=i2c_master_start(cmd); @@ -169,5 +169,5 @@ void jshI2CRead(IOEventFlags device, if ( sendStop ) ret=i2c_master_stop(cmd); ret = i2c_master_cmd_begin(i2c_master_port, cmd, 1000 / portTICK_RATE_MS); i2c_cmd_link_delete(cmd); - checkError( "jshI2CRead", ret); + checkError( "jshI2CRead", ret); } diff --git a/targets/esp32/jshardwareSpi.c b/targets/esp32/jshardwareSpi.c index 358938fa98..0a6e8f890a 100644 --- a/targets/esp32/jshardwareSpi.c +++ b/targets/esp32/jshardwareSpi.c @@ -80,8 +80,8 @@ implement inf->spiMSB Test with ILI9341 works, but could be faster. Espruino supports sendig byte by byte, no mass sending is supported. */ - - + + volatile spi_transaction_t spi_trans; volatile bool spi_Sending = false; @@ -121,7 +121,7 @@ void jshSPISetup( }; // SPI_DEVICE_BIT_LSBFIRST - test inf->spiMSB need to look at what values... uint32_t flags = 0; - + spi_device_interface_config_t devcfg={ .clock_speed_hz=inf->baudRate, .mode=inf->spiMode, @@ -154,7 +154,7 @@ int jshSPISend( esp_err_t ret; spi_transaction_t t; memset(&t, 0, sizeof(t)); - t.length=8; + t.length=8; t.tx_buffer=&data; t.flags=SPI_TRANS_USE_RXDATA; ret=spi_device_transmit(SPIChannels[channelPnt].spi, &t); @@ -187,10 +187,10 @@ bool jshSPISendMany(IOEventFlags device, unsigned char *tx, unsigned char *rx, s spi_trans.rx_buffer=rx; spi_Sending = true; ret=spi_device_queue_trans(SPIChannels[channelPnt].spi, &spi_trans, rx?0:portMAX_DELAY); - + if (ret != ESP_OK) { spi_Sending = false; - jsExceptionHere(JSET_INTERNALERROR, "SPI Send Error %d\n", ret); + jsExceptionHere(JSET_INTERNALERROR, "SPI Send Error %d", ret); return false; } jshSPIWait(device); @@ -233,7 +233,7 @@ void jshSPIWait(IOEventFlags device) { esp_err_t ret; ret=spi_device_get_trans_result(SPIChannels[channelPnt].spi, &spi_trans, portMAX_DELAY); if (ret != ESP_OK) { - jsExceptionHere(JSET_INTERNALERROR, "SPI Send Error %d\n", ret); + jsExceptionHere(JSET_INTERNALERROR, "SPI Send Error %d", ret); } spi_Sending = false; } @@ -242,5 +242,5 @@ void jshSPIWait(IOEventFlags device) { /** Set whether to use the receive interrupt or not */ void jshSPISetReceive(IOEventFlags device, bool isReceive) { int channelPnt = getSPIChannelPnt(device); - SPIChannels[channelPnt].spi_read = isReceive; + SPIChannels[channelPnt].spi_read = isReceive; } diff --git a/targets/esp32/jswrap_esp32.c b/targets/esp32/jswrap_esp32.c index 0b100a50c7..6da879ae4a 100644 --- a/targets/esp32/jswrap_esp32.c +++ b/targets/esp32/jswrap_esp32.c @@ -107,7 +107,7 @@ as RTC GPIOs](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-re */ void jswrap_ESP32_deepSleep_ext0(Pin pin, int level) { if (!rtc_gpio_is_valid_gpio(pin)) { - jsExceptionHere(JSET_ERROR, "Invalid pin!"); + jsExceptionHere(JSET_ERROR, "Invalid pin"); return; } esp_sleep_enable_ext0_wakeup(pin, level); @@ -144,7 +144,7 @@ void jswrap_ESP32_deepSleep_ext1(JsVar *pinVar, JsVarInt mode) { Pin pin = jshGetPinFromVarAndUnLock(jsvIteratorGetValue(&it)); if (!rtc_gpio_is_valid_gpio(pin)) { jsvIteratorFree(&it); - jsExceptionHere(JSET_ERROR, "Invalid pin (%d)!", pin); + jsExceptionHere(JSET_ERROR, "Invalid pin"); return; } pinSum += 1<>pin)&1, + pin, + (long int) (GPIO_REG_READ(GPIO_OUT_ADDRESS)>>pin)&1, (long int) (GPIO_REG_READ(GPIO_ENABLE_ADDRESS)>>pin)&1, (long int) (GPIO_REG_READ(GPIO_IN_ADDRESS)>>pin)&1); @@ -334,7 +334,7 @@ static void jshDebugPin(Pin pin) { os_printf(" dr=%s src=%s func=%ld pull-up=%ld oe=%ld\n", gpio_pin & 4 ? "open-drain" : "totem-pole", gpio_pin & 1 ? "sigma-delta" : "gpio", - (long int) ((mux>>2)&1 | (mux&3)), + (long int) ((mux>>2)&1 | (mux&3)), (long int) ((mux>>7)&1), (long int) mux&1); } @@ -366,10 +366,10 @@ void jshPinSetState( Pin pin, //!< The pin to have its state changed. JshPinState state //!< The new desired state of the pin. ) { - + os_printf("> ESP8266: jshPinSetState state: %s\n",pinStateToString(state)); /* reject analog port */ - if ((pinInfo[pin].port & JSH_PORT_MASK) == JSH_PORTA) { + if ((pinInfo[pin].port & JSH_PORT_MASK) == JSH_PORTA) { return ; } /* handle D16 */ @@ -377,7 +377,7 @@ void jshPinSetState( switch(state){ case JSHPINSTATE_GPIO_OUT: // mux configuration for XPD_DCDC to output rtc_gpio0 - WRITE_PERI_REG(PAD_XPD_DCDC_CONF, (READ_PERI_REG(PAD_XPD_DCDC_CONF) & 0xffffffbc) | (uint32)0x1); + WRITE_PERI_REG(PAD_XPD_DCDC_CONF, (READ_PERI_REG(PAD_XPD_DCDC_CONF) & 0xffffffbc) | (uint32)0x1); //mux configuration for out enable WRITE_PERI_REG(RTC_GPIO_CONF,(READ_PERI_REG(RTC_GPIO_CONF) & (uint32)0xfffffffe) | (uint32)0x0); //out enable @@ -385,11 +385,11 @@ void jshPinSetState( break; case JSHPINSTATE_GPIO_IN: // mux configuration for XPD_DCDC and rtc_gpio0 connection - WRITE_PERI_REG(PAD_XPD_DCDC_CONF,(READ_PERI_REG(PAD_XPD_DCDC_CONF) & 0xffffffbc) | (uint32)0x1); + WRITE_PERI_REG(PAD_XPD_DCDC_CONF,(READ_PERI_REG(PAD_XPD_DCDC_CONF) & 0xffffffbc) | (uint32)0x1); //mux configuration for out enable WRITE_PERI_REG(RTC_GPIO_CONF,(READ_PERI_REG(RTC_GPIO_CONF) & (uint32)0xfffffffe) | (uint32)0x0); //out disable - WRITE_PERI_REG(RTC_GPIO_ENABLE,READ_PERI_REG(RTC_GPIO_ENABLE) & (uint32)0xfffffffe); + WRITE_PERI_REG(RTC_GPIO_ENABLE,READ_PERI_REG(RTC_GPIO_ENABLE) & (uint32)0xfffffffe); break; default: jsError("only output and input are valid for D16"); @@ -397,7 +397,7 @@ void jshPinSetState( } g_pinState[pin] = state; return; - } + } /* Make sure we kill software PWM if we set the pin state * after we've started it */ @@ -473,23 +473,23 @@ void jshPinSetState( JshPinState jshPinGetState(Pin pin) { //os_printf("> ESP8266: jshPinGetState %d\n", pin); /* - os_printf("> ESP8266: pin %d, pinState %d, reg_read %d, out_addr: %d input get %d\n", + os_printf("> ESP8266: pin %d, pinState %d, reg_read %d, out_addr: %d input get %d\n", pin, g_pinState[pin], (GPIO_REG_READ(GPIO_OUT_W1TS_ADDRESS)>>pin)&1, (GPIO_REG_READ(GPIO_OUT_ADDRESS)>>pin)&1, GPIO_INPUT_GET(pin)); - */ + */ /* reject non digital ports */ - if ((pinInfo[pin].port & JSH_PORT_MASK) == JSH_PORTA) { + if ((pinInfo[pin].port & JSH_PORT_MASK) == JSH_PORTA) { return JSHPINSTATE_ADC_IN; } int rc = g_pinState[pin]; if (pin == 16) { if ((uint8)(READ_PERI_REG(RTC_GPIO_IN_DATA) & 1) &1) { rc = g_pinState[pin] | JSHPINSTATE_PIN_IS_ON; - } + } } else { if ( (GPIO_REG_READ(GPIO_OUT_ADDRESS)>>pin)&1 ) { rc = g_pinState[pin] | JSHPINSTATE_PIN_IS_ON; - } + } } return rc; } @@ -509,14 +509,14 @@ void jshPinSetValue( ) { //os_printf("> ESP8266: jshPinSetValue pin=%d, value=%d\n", pin, value); /* reject non digital ports */ - if ((pinInfo[pin].port & JSH_PORT_MASK) != JSH_PORTD) { + if ((pinInfo[pin].port & JSH_PORT_MASK) != JSH_PORTD) { return; } /* handle GPIO16 */ if (pin == 16) { WRITE_PERI_REG(RTC_GPIO_OUT,(READ_PERI_REG(RTC_GPIO_OUT) & (uint32)0xfffffffe) | (uint32)(value & 1)); } else { - if (value & 1) { + if (value & 1) { GPIO_REG_WRITE(GPIO_OUT_W1TS_ADDRESS, 1< ESP8266: jshPinAnalog: pin=%d\n", pin); if ( pin == 255 || ( pinInfo[pin].port & JSH_PORT_MASK) == JSH_PORTA ) { - return (JsVarFloat)system_adc_read() / 1024.0; + return (JsVarFloat)system_adc_read() / 1024.0; } else { return NAN; } @@ -558,11 +558,11 @@ JsVarFloat jshPinAnalog(Pin pin) { int jshPinAnalogFast(Pin pin) { //os_printf("> ESP8266: jshPinAnalogFast: pin=%d\n", pin); - if ( pin == 255 || ( pinInfo[pin].port & JSH_PORT_MASK) == JSH_PORTA ) { + if ( pin == 255 || ( pinInfo[pin].port & JSH_PORT_MASK) == JSH_PORTA ) { return (int)system_adc_read() << 6; // left-align to 16 bits } else { return 0; - } + } } @@ -754,10 +754,10 @@ void jshUSARTSetup(IOEventFlags device, JshUSARTInfo *inf) { if (device == EV_SERIAL1) uart_no = UART0; else if (device == EV_SERIAL2) uart_no = UART1; else { - jsExceptionHere(JSET_ERROR, "jshUSARTSetup Unknown device %d\n", device); + jsExceptionHere(JSET_ERROR, "jshUSARTSetup Unknown device %d", device); return; } - + if (inf->errorHandling) { jsExceptionHere(JSET_ERROR, "ESP8266 Espruino builds can't handle framing/parity errors (errors:true)"); return; @@ -970,7 +970,7 @@ void jshI2CWrite(IOEventFlags device, unsigned char address, int nBytes, return; error: i2c_master_stop(); - jsExceptionHere(JSET_INTERNALERROR, "I2CWrite: No ACK %d\n", ack); + jsExceptionHere(JSET_INTERNALERROR, "I2CWrite: No ACK %d", ack); } void jshI2CRead(IOEventFlags device, unsigned char address, int nBytes, @@ -992,7 +992,7 @@ void jshI2CRead(IOEventFlags device, unsigned char address, int nBytes, return; error: i2c_master_stop(); - jsExceptionHere(JSET_INTERNALERROR, "I2CRead: No ACK %d\n", ack); + jsExceptionHere(JSET_INTERNALERROR, "I2CRead: No ACK %d", ack); } //===== System time stuff ===== @@ -1149,7 +1149,7 @@ static void systemTimeInit(void) { os_printf("RTC: restore sys=%lu rtc=%lu\n", (long unsigned int)sysTime, (long unsigned int)rtcTime); os_printf("RTC: restored time: %lu (delta=%lu cal=%luus)\n", (long unsigned int)(rtcTimeStamp.timeStamp/1000000), - (long unsigned int)delta, + (long unsigned int)delta, (long unsigned int)(cal*1000)>>12); saveTime(&rtcTimeStamp); } @@ -1231,7 +1231,7 @@ void jshUtilTimerStart(JsSysTime period) { } void jshUtilTimerDisable() { - RTC_CLR_REG_MASK(FRC1_CTRL_ADDRESS,FRC1_ENABLE_TIMER); + RTC_CLR_REG_MASK(FRC1_CTRL_ADDRESS,FRC1_ENABLE_TIMER); //jsiConsolePrintf("utilTimer disarm\n"); } @@ -1328,7 +1328,7 @@ void jshFlashWrite( if (addr + len > flash_max) len = flash_max - addr; if (addr < flash_max) // map to active userbin_segment - addr |= userbin_segment; + addr |= userbin_segment; SpiFlashOpResult res = SPI_FLASH_RESULT_OK; /* so about that alignment... Turns out it matters @@ -1395,10 +1395,10 @@ JsVar *jshFlashGetFree() { addFlashArea(jsFreeFlash, 0x3C0000, 0x40000-0x5000); return jsFreeFlash; } - // there is no flash for running on 1MB flash without FOTA + // there is no flash for running on 1MB flash without FOTA if ( map == 2 && espFlashKB == 1024 && ESP_COMBINED_SIZE >= 1024 ) return jsFreeFlash; - + // need 1MB of flash to have more space... if (espFlashKB > 512) { addFlashArea(jsFreeFlash, 0x80000, 0x1000); @@ -1426,11 +1426,11 @@ void jshFlashErasePage( uint32_t addr //!< ) { //os_printf("jshFlashErasePage: addr=0x%lx\n", addr); - + // map to active segment as needed uint32_t flash_max=jshFlashMax(); - if (addr < flash_max) - addr |= userbin_segment; + if (addr < flash_max) + addr |= userbin_segment; SpiFlashOpResult res; res = spi_flash_erase_sector(addr >> FLASH_PAGE_SHIFT); @@ -1451,7 +1451,7 @@ size_t jshFlashGetMemMapAddress(size_t ptr) { unsigned int jshSetSystemClock(JsVar *options) { int newFreq = jsvGetInteger(options); if (newFreq != 80 && newFreq != 160) { - jsExceptionHere(JSET_ERROR, "Invalid frequency value, must be 80 or 160."); + jsExceptionHere(JSET_ERROR, "Invalid frequency value, must be 80 or 160"); return 0; } system_update_cpu_freq(newFreq); diff --git a/targets/esp8266/jswrap_esp8266.c b/targets/esp8266/jswrap_esp8266.c index 8566637c89..1f9fe987bc 100644 --- a/targets/esp8266/jswrap_esp8266.c +++ b/targets/esp8266/jswrap_esp8266.c @@ -312,7 +312,7 @@ uint32_t crc32(uint8_t *buf, uint32_t len) { }*/ JsVar *jswrap_ESP8266_crc32(JsVar *jsData) { if (!jsvIsArray(jsData)) { - jsExceptionHere(JSET_ERROR, "Data must be an array."); + jsExceptionHere(JSET_ERROR, "Data must be an array"); return NULL; } JSV_GET_AS_CHAR_ARRAY(data, len, jsData); @@ -385,10 +385,10 @@ down occurs. */ void jswrap_ESP8266_deepSleep(JsVar *jsMicros, JsVar *jsOption) { if (!jsvIsInt(jsMicros)) { - jsExceptionHere(JSET_ERROR, "Invalid microseconds."); + jsExceptionHere(JSET_ERROR, "Invalid microseconds"); return; } - + uint8_t option = jsvGetInteger(jsOption); system_deep_sleep_set_option(option); diff --git a/targets/linux/jshardware.c b/targets/linux/jshardware.c index 480f300849..13b22a0560 100644 --- a/targets/linux/jshardware.c +++ b/targets/linux/jshardware.c @@ -80,7 +80,7 @@ void sysfs_write(const char *path, const char *data) { if (f>=0) { write(f, data, strlen(data)); close(f); - } + } } void sysfs_write_int(const char *path, JsVarInt val) { @@ -95,7 +95,7 @@ void sysfs_read(const char *path, char *data, unsigned int len) { if (f>=0) { amt = read(f, data, len-1); close(f); - } + } if (amt<0) amt=0; data[amt]=0; } @@ -353,7 +353,7 @@ void jshInit() { } #ifdef SYSFS_GPIO_DIR for (i=0;ierrorHandling) { jsExceptionHere(JSET_ERROR, "Linux Espruino builds can't handle framing/parity errors (errors:true)"); return; - } - + } + char path[256]; if (jshGetDevicePath(device, path, sizeof(path))) { ioDevices[device] = open(path, O_RDWR | O_NOCTTY | O_NONBLOCK); @@ -695,10 +695,10 @@ void jshUSARTSetup(IOEventFlags device, JshUSARTInfo *inf) { cfmakeraw(&settings); settings.c_cflag &= ~(PARENB|PARODD); // none - + if (inf->parity == 1) settings.c_cflag |= PARENB|PARODD; // odd if (inf->parity == 2) settings.c_cflag |= PARENB; // even - + settings.c_cflag &= ~CSTOPB; if (inf->stopbits==2) settings.c_cflag |= CSTOPB; @@ -790,14 +790,14 @@ bool jshSleep(JsSysTime timeUntilWake) { for (pin=0;pin1000) + if (hasWatches && usecs>1000) usecs=1000; // don't sleep much if we have watches - we need to keep polling them if (usecs > 50000) usecs = 50000; // don't want to sleep too much (user input/HTTP/etc) - if (usecs >= 1000) + if (usecs >= 1000) jshDelayMicroseconds(usecs); return true; } diff --git a/targets/nrf5x/bluetooth.c b/targets/nrf5x/bluetooth.c index 1c59ea2651..e50a34055e 100644 --- a/targets/nrf5x/bluetooth.c +++ b/targets/nrf5x/bluetooth.c @@ -3250,7 +3250,7 @@ void jsble_send_hid_input_report(uint8_t *data, int length) { return; } if (!jsble_has_peripheral_connection()) { - jsExceptionHere(JSET_ERROR, "Not connected!"); + jsExceptionHere(JSET_ERROR, "Not connected"); return; } if (bleStatus & BLE_IS_SENDING_HID) { @@ -3258,7 +3258,7 @@ void jsble_send_hid_input_report(uint8_t *data, int length) { return; } if (length > HID_KEYS_MAX_LEN) { - jsExceptionHere(JSET_ERROR, "BLE HID report too long - max length = %d\n", HID_KEYS_MAX_LEN); + jsExceptionHere(JSET_ERROR, "BLE HID report too long - max length = %d", HID_KEYS_MAX_LEN); return; } diff --git a/targets/nrf5x/jshardware.c b/targets/nrf5x/jshardware.c index 512b4b2d9e..4f8976ae50 100644 --- a/targets/nrf5x/jshardware.c +++ b/targets/nrf5x/jshardware.c @@ -1555,7 +1555,7 @@ JshPinFunction jshPinAnalogOutput(Pin pin, JsVarFloat value, JsVarFloat freq, Js } if (!func) { - jsExceptionHere(JSET_ERROR, "No free Hardware PWMs. Try not specifying a frequency, or using analogWrite(pin, val, {soft:true}) for Software PWM\n"); + jsExceptionHere(JSET_ERROR, "No free Hardware PWMs. Try not specifying a frequency, or using analogWrite(pin, val, {soft:true}) for Software PWM"); return 0; } @@ -1856,7 +1856,7 @@ void jshUSARTSetup(IOEventFlags device, JshUSARTInfo *inf) { jshSetErrorHandlingEnabled(device, inf->errorHandling); if (inf->stopbits!=1) - return jsExceptionHere(JSET_INTERNALERROR, "Unsupported serial stopbits length."); + return jsExceptionHere(JSET_INTERNALERROR, "Unsupported serial stopbits length"); uart[num].isInitialised = false; if (inf->bytesize==8) { @@ -1871,7 +1871,7 @@ void jshUSARTSetup(IOEventFlags device, JshUSARTInfo *inf) { inf->parity = 0; // no parity bit for 7 bit output #endif } else - return jsExceptionHere(JSET_INTERNALERROR, "Unsupported serial byte size."); + return jsExceptionHere(JSET_INTERNALERROR, "Unsupported serial byte size"); JshPinFunction JSH_USART = JSH_USART1+(num<pinSCK)) { @@ -2050,7 +2050,7 @@ int jshSPISend(IOEventFlags device, int data) { } if (err_code != NRF_SUCCESS) { spi0Sending = false; - jsExceptionHere(JSET_INTERNALERROR, "SPI Send Error %d\n", err_code); + jsExceptionHere(JSET_INTERNALERROR, "SPI Send Error %d", err_code); } jshSPIWait(device); return rx; @@ -2113,7 +2113,7 @@ bool jshSPISendMany(IOEventFlags device, unsigned char *tx, unsigned char *rx, s #endif if (err_code != NRF_SUCCESS) { spi0Sending = false; - jsExceptionHere(JSET_INTERNALERROR, "SPI Send Error %d\n", err_code); + jsExceptionHere(JSET_INTERNALERROR, "SPI Send Error %d", err_code); return false; } if (!callback) { @@ -2230,7 +2230,7 @@ void jshI2CSetup(IOEventFlags device, JshI2CInfo *inf) { }; err_code = nrf_drv_twis_init(twis, &config, twis_event_handler); if (err_code != NRF_SUCCESS) - jsExceptionHere(JSET_INTERNALERROR, "I2C Initialisation Error %d\n", err_code); + jsExceptionHere(JSET_INTERNALERROR, "I2C Initialisation Error %d", err_code); else nrf_drv_twis_enable(twis); } else @@ -2249,7 +2249,7 @@ void jshI2CSetup(IOEventFlags device, JshI2CInfo *inf) { twi1Initialised = true; err_code = nrf_drv_twi_init(twi, &p_twi_config, NULL, NULL); if (err_code != NRF_SUCCESS) - jsExceptionHere(JSET_INTERNALERROR, "I2C Initialisation Error %d\n", err_code); + jsExceptionHere(JSET_INTERNALERROR, "I2C Initialisation Error %d", err_code); else nrf_drv_twi_enable(twi); } @@ -2271,7 +2271,7 @@ void jshI2CWrite(IOEventFlags device, unsigned char address, int nBytes, const u if (!twi || !jshIsDeviceInitialised(device)) return; uint32_t err_code = nrf_drv_twi_tx(twi, address, data, nBytes, !sendStop); if (err_code != NRF_SUCCESS) - jsExceptionHere(JSET_INTERNALERROR, "I2C Write Error %d\n", err_code); + jsExceptionHere(JSET_INTERNALERROR, "I2C Write Error %d", err_code); } void jshI2CRead(IOEventFlags device, unsigned char address, int nBytes, unsigned char *data, bool sendStop) { @@ -2279,7 +2279,7 @@ void jshI2CRead(IOEventFlags device, unsigned char address, int nBytes, unsigned if (!twi || !jshIsDeviceInitialised(device)) return; uint32_t err_code = nrf_drv_twi_rx(twi, address, data, nBytes); if (err_code != NRF_SUCCESS) - jsExceptionHere(JSET_INTERNALERROR, "I2C Read Error %d\n", err_code); + jsExceptionHere(JSET_INTERNALERROR, "I2C Read Error %d", err_code); } #endif // TWI_ENABLED diff --git a/targets/stm32/jshardware.c b/targets/stm32/jshardware.c index 187b24fe69..853a887963 100644 --- a/targets/stm32/jshardware.c +++ b/targets/stm32/jshardware.c @@ -784,7 +784,7 @@ void jshSetupRTC(bool isUsingLSI) { RCC_RTCCLKConfig(isUsingLSI ? RCC_RTCCLKSource_LSI : RCC_RTCCLKSource_LSE); // set clock source to low speed internal RCC_RTCCLKCmd(ENABLE); // enable RTC (in backup domain) RTC_WaitForSynchro(); - jshSetupRTCPrescaler(isUsingLSI); + jshSetupRTCPrescaler(isUsingLSI); } #endif @@ -931,7 +931,7 @@ void jshDelayMicroseconds(int microsec) { void jshPinSetState(Pin pin, JshPinState state) { // if this is about to mess up the neopixel output, so reset our var so we know to re-init if (pin == jshNeoPixelPin) - jshNeoPixelPin = PIN_UNDEFINED; + jshNeoPixelPin = PIN_UNDEFINED; /* Make sure we kill software PWM if we set the pin state * after we've started it */ if (BITFIELD_GET(jshPinSoftPWM, pin)) { @@ -2017,7 +2017,7 @@ IOEventFlags jshPinWatch(Pin pin, bool shouldWatch, JshPinWatchFlags flags) { EXTI_Init(&s); return shouldWatch ? (EV_EXTI0+pinInfo[pin].pin) : EV_NONE; - } else jsExceptionHere(JSET_ERROR, "Invalid pin!"); + } else jsExceptionHere(JSET_ERROR, "Invalid pin"); return EV_NONE; } @@ -2126,7 +2126,7 @@ void jshUSARTSetup(IOEventFlags device, JshUSARTInfo *inf) { usartIRQ = USART6_IRQn; #endif } else { - jsExceptionHere(JSET_INTERNALERROR, "Unknown serial port device."); + jsExceptionHere(JSET_INTERNALERROR, "Unknown serial port device"); return; } @@ -2153,7 +2153,7 @@ void jshUSARTSetup(IOEventFlags device, JshUSARTInfo *inf) { USART_InitStructure.USART_WordLength = USART_WordLength_9b; } else { - jsExceptionHere(JSET_INTERNALERROR, "Unsupported serial byte size."); + jsExceptionHere(JSET_INTERNALERROR, "Unsupported serial byte size"); return; } @@ -2164,7 +2164,7 @@ void jshUSARTSetup(IOEventFlags device, JshUSARTInfo *inf) { USART_InitStructure.USART_StopBits = USART_StopBits_2; } else { - jsExceptionHere(JSET_INTERNALERROR, "Unsupported serial stopbits length."); + jsExceptionHere(JSET_INTERNALERROR, "Unsupported serial stopbits length"); return; } // FIXME: How do we handle 1.5 stopbits? @@ -2180,7 +2180,7 @@ void jshUSARTSetup(IOEventFlags device, JshUSARTInfo *inf) { USART_InitStructure.USART_Parity = USART_Parity_Even; } else { - jsExceptionHere(JSET_INTERNALERROR, "Unsupported serial parity mode."); + jsExceptionHere(JSET_INTERNALERROR, "Unsupported serial parity mode"); return; } @@ -2234,7 +2234,7 @@ void jshSPISetup(IOEventFlags device, JshSPIInfo *inf) { if (!SPIx) return; // failed to find matching pins // this could be about to mess up the neopixel output, so reset our var so we know to re-init - jshNeoPixelPin = PIN_UNDEFINED; + jshNeoPixelPin = PIN_UNDEFINED; SPI_InitTypeDef SPI_InitStructure; SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; diff --git a/targets/stm32/stm32_ws2812b_driver.c b/targets/stm32/stm32_ws2812b_driver.c index 1157cbeb37..74f118f8fd 100644 --- a/targets/stm32/stm32_ws2812b_driver.c +++ b/targets/stm32/stm32_ws2812b_driver.c @@ -15,23 +15,23 @@ bool stm32_neopixelWrite(Pin pin, unsigned char *rgbData, size_t rgbSize) unsigned char *p = (uint8_t *)rgbData; if (!jshIsPinValid(pin)) { - jsExceptionHere(JSET_ERROR, "Pin is not valid."); + jsExceptionHere(JSET_ERROR, "Pin is not valid"); return false; } - // Set neopixel output pin + // Set neopixel output pin jshPinSetState(pin, JSHPINSTATE_GPIO_OUT); - + jshInterruptOff(); for(c = 0; c < rgbSize; c++) { for(int i = 7; i >= 0; i--) { if(p[c] & (0x01 << i)) { PATTERN_1_CODE(pin); - } + } else { PATTERN_0_CODE(pin); - } + } } } jshDelayMicroseconds(50); diff --git a/targets/stm32_ll/jshardware.c b/targets/stm32_ll/jshardware.c index f8a61a92d8..dc440d1aa3 100644 --- a/targets/stm32_ll/jshardware.c +++ b/targets/stm32_ll/jshardware.c @@ -548,7 +548,7 @@ ALWAYS_INLINE void jshPinSetState(Pin pin, JshPinState state) { bool out = JSHPINSTATE_IS_OUTPUT(state); /* bool af = JSHPINSTATE_IS_AF(state); * af function cannot be configured here because we do not know the af - * name... It should be done on the caller of jshPinSetState + * name... It should be done on the caller of jshPinSetState * (This is due to a difference between SPL and LL libraries) */ bool pullup = JSHPINSTATE_IS_PULLUP(state); bool pulldown = JSHPINSTATE_IS_PULLDOWN(state); @@ -691,7 +691,7 @@ void jshUSARTSetup(IOEventFlags device, JshUSARTInfo *inf){ usartIRQ = USART3_IRQn; #endif } else { - jsExceptionHere(JSET_INTERNALERROR, "Unknown serial port device."); + jsExceptionHere(JSET_INTERNALERROR, "Unknown serial port device"); return; } @@ -715,7 +715,7 @@ void jshUSARTSetup(IOEventFlags device, JshUSARTInfo *inf){ USART_InitStructure.DataWidth = LL_USART_DATAWIDTH_9B; } else { - jsExceptionHere(JSET_INTERNALERROR, "Unsupported serial byte size."); + jsExceptionHere(JSET_INTERNALERROR, "Unsupported serial byte size"); return; } @@ -726,7 +726,7 @@ void jshUSARTSetup(IOEventFlags device, JshUSARTInfo *inf){ USART_InitStructure.StopBits = LL_USART_STOPBITS_2; } else { - jsExceptionHere(JSET_INTERNALERROR, "Unsupported serial stopbits length."); + jsExceptionHere(JSET_INTERNALERROR, "Unsupported serial stopbits length"); return; } // FIXME: How do we handle 1.5 stopbits? @@ -742,7 +742,7 @@ void jshUSARTSetup(IOEventFlags device, JshUSARTInfo *inf){ USART_InitStructure.Parity = LL_USART_PARITY_EVEN; } else { - jsExceptionHere(JSET_INTERNALERROR, "Unsupported serial parity mode."); + jsExceptionHere(JSET_INTERNALERROR, "Unsupported serial parity mode"); return; } @@ -1518,7 +1518,7 @@ IOEventFlags jshPinWatch(Pin pin, bool shouldWatch, JshPinWatchFlags flags) { LL_EXTI_Init(&s); return shouldWatch ? (EV_EXTI0+pinInfo[pin].pin) : EV_NONE; - } else jsExceptionHere(JSET_ERROR, "Invalid pin!"); + } else jsExceptionHere(JSET_ERROR, "Invalid pin"); return EV_NONE; }