-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bitwise AND operator #14
Comments
Just to make sure: |
in this case numPixels() always returns 8 ... i believe that to be in range |
In you C code, capture the result of execution and print it - that could help to catch some obvious errors: jsval_t v = js_eval(js, " this triggers error ", 0);", 0);
printf("result: %s\n", js_str(js, v));
js_gc(js, v); |
Yes I am referencing global variables because when I tried to use in-function let statements it didn't work ... the variables seamed to interfering with each other ... or at least it appeared that way ... perhaps like you suggested I can print the results out to get a better understanding of what's happening ... and I'll post full code used instead of snippets ... sometime tonight ... cheers and thanks! |
Thank you! |
I've tried to cover everything within this test code addressing both the open issues #13 & #14 ... LINUX_DIST="Linux Mint 18.3 Sylvia MATE 32-bit" ARDUINO IDE: 1.8.10 (32bit) (Full)Test Code 0.0.17
Results
LINUX_DIST="Linux Mint 18.3 Sylvia MATE 32-bit" ARDUINO IDE: 1.8.10 (32bit) Test Code 0.0.16
Results
working test code all in arduino c
code progression - elk <- c while loops <- c for loops (original)
|
When I edit the while loops to have the let statements within them rather than at the top of each function ... for example: from this ... to this ... I get this response ...
and this in 0.0.17
|
Are you sure you're running the latest version? |
I performed all test on both 0.0.16 & 0.0.17 ... shown above (0.0.17 code is listed first) is the code used for the 0.0.17 test ... and (second) the next block of code was used for testing 0.0.16 ... so ... Yes, I'm running the latest version! ... and the 0.0.16 older version too! ... I was trying to show how somethings were working under 0.0.16 ... and are now not working in 0.0.17 ... sorry for all the content above ... and if it caused any confusion (I tried to label everything ...) |
Ah, sorry about that. Also please note that elk's numbers are packed into the C 32-bit Of course this point does not address an issue you've reported. We'll try to reproduce. |
Starting to repro. This works fine on my 16-pixel strip: // example of using the elk javascript engine innen Arduino Environment on esp32
// Adafruit_NeoPixel strandtest.ino ported to elk javascript engine ...
#include <Adafruit_NeoPixel.h>
#include <elk.h>
#define ALLOC 4096 // also tried 8192
#define LED_PIN 10
#define LED_COUNT 16
#define DEBUG 1
struct js *js = js_create(malloc(ALLOC), ALLOC);
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
void setup() {
Serial.begin(115200);
Serial.println();
Serial.println("Starting-up ...");
js_import(js, "delay", (uintptr_t) Sys_delay, "vi");
js_import(js, "print", (uintptr_t) Sys_print, "vs");
js_import(js, "show", (uintptr_t) Neo_show, "v");
js_import(js, "setPixelColor", (uintptr_t) Neo_setPixelColor, "viiii");
js_eval(js, "let colorWipe = function(d, r, g, b) { let i = 0; while (i < 16) { i++; setPixelColor(i, r, g, b); show(); delay(d); } };", 0);
strip.begin();
strip.show();
strip.setBrightness(50);
Serial.println("setup complete ...");
}
extern "C" void Neo_show() { strip.show(); }
extern "C" void Neo_setPixelColor(uint16_t n, int r, int g, int b) { strip.setPixelColor(n, strip.Color(r, g, b)); }
extern "C" void Sys_delay(unsigned long milli) { delay(milli); }
extern "C" void Sys_print(const char *str) { Serial.println(str); }
void loop() {
Serial.println(" ... looping");
js_eval(js, "colorWipe(50, 255, 0, 0);", 0);
js_eval(js, "colorWipe(50, 0, 255, 0);", 0);
} |
Added theaterChase() which also works fine (see below). // example of using the elk javascript engine innen Arduino Environment on esp32
// Adafruit_NeoPixel strandtest.ino ported to elk javascript engine ...
#include <Adafruit_NeoPixel.h>
#include <elk.h>
#define ALLOC 4096 // also tried 8192
#define LED_PIN 10
#define LED_COUNT 16
#define DEBUG 1
struct js *js = js_create(malloc(ALLOC), ALLOC);
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
void setup() {
Serial.begin(115200);
Serial.println();
Serial.println("Starting-up ...");
js_import(js, "delay", (uintptr_t) Sys_delay, "vi");
js_import(js, "print", (uintptr_t) Sys_print, "vs");
js_import(js, "show", (uintptr_t) Neo_show, "v");
js_import(js, "clear", (uintptr_t) Neo_clear, "v");
js_import(js, "setPixelColor", (uintptr_t) Neo_setPixelColor, "viiii");
js_eval(js, "let colorWipe = function(d, r, g, b) { let i = 0; while (i < 16) { i++; setPixelColor(i, r, g, b); show(); delay(d); } };", 0);
js_eval(js, "let theaterChase = function(d, r, g, b) { let a = 0, b, c; while (a < 10) { b = 0; while (b < 3) { clear(); c=b; while (c<16) { setPixelColor(c, r,g,b); c += 3; } show(); delay(d); b++; } a++; } };", 0);
strip.begin();
strip.show();
strip.setBrightness(50);
Serial.println("setup complete ...");
}
extern "C" void Neo_show() { strip.show(); }
extern "C" void Neo_clear() { strip.clear(); }
extern "C" void Neo_setPixelColor(uint16_t n, int r, int g, int b) { strip.setPixelColor(n, strip.Color(r, g, b)); }
extern "C" void Sys_delay(unsigned long milli) { delay(milli); }
extern "C" void Sys_print(const char *str) { Serial.println(str); }
void loop() {
Serial.println(" ... looping");
js_eval(js, "colorWipe(50, 255, 0, 0);", 0);
js_eval(js, "colorWipe(50, 0, 255, 0);", 0);
js_eval(js, "theaterChase(50, 255, 0, 0);", 0);
} |
The ColorWipe works fine every time ... however ... i'm clearly still getting different results for the theaterChase ... the first three times loop() is called theaterChase does not finish the while loop correctly (it's ending early) then i get strange colors on the first and second leds ... that I don't experience run a straight c version of the code ... i'll print some things out to see what's going on ... UPDATE: While running both patterns at the same time ... colorWipe also acts irregularly too ... definitely something is corrupting variables ... therefore also affecting while loops ... |
LINUX_DIST="Linux Mint 18.3 Sylvia MATE 32-bit" ARDUINO IDE: 1.8.10 (32bit) Here I have (isolated) theaterChase() echoing back to the console ... and you can clearly see it's not working as expected ... the function never (returns) reaches the end of all the loops ... it bombs out after a couple outer and inner loops ... see below for the results TEST CODE
RESULT
|
stripped down to nothing but elk ... it's clearly still having issues with either variables or while loops or both TEST CODE
TEST FUNCTION
RESULT
|
There was an issue indeed, around loops scope handling. Released 0.0.18. #include "elk.h"
char mem[600];
struct js *js = js_create(mem, sizeof(mem));
extern "C" void Sys_print(jsval_t v) { Serial.println(js_str(js, v)); }
void setup() {
Serial.begin(115200);
Serial.println("Starting-up ...");
js_import(js, "print", (uintptr_t) Sys_print, "vj");
js_eval(js, "let f = function(d) { let a = 0, b, c; while(a < 10) { print({a:a}); "
"b = 0; while(b < 3) { print({b:b}); c = b; while(c < 8) { print({c:c}); c += 3; } b++; } a++; } };", 0);
}
void loop() {
js_eval(js, "f();", 0);
Serial.println(js_info(js));
delay(1000);
} |
TY confirmed to be working in 0.0.18 :) @cpq |
LINUX_DIST="Linux Mint 18.3 Sylvia MATE 32-bit" ARDUINO IDE: 1.8.10 (32bit) I still seam to be having a problem with bitwise operations throwing off execution order ... below is a snippet of the code I've been working on to demonstrate what happens ... In the first example setPixelColor() gets called after WheelR() BUT before WheelG() or WheelB() are called ... so the g & b variables are always set to zero (0) ... setting it to a variable first solved the problem for me ... but it may still be a problem in some cases ... NOT WORKING
WORKING
|
UPDATE: it now appears as if the problem isn't with the bitwise operation itself but rather with the function parameters and how they are being processed (order) ... here is another example ... again in the first example the setPixelColor() function gets called before the WheelX() functions get called ... again leaving rgb (them) all set to zero ... not the desired outcome ... however when I pass the first parameter to setPixelColor() as a pre-calculated variable ... it functions as expected ... NOT WORKING
WORKING
|
Just for fun here's my final working code ...
|
Nice! Can that neopixel code work on Uno? Since that is a different issue, please open a new one - I'd appreciate a minimal example. |
I haven't tried this on anything else (yet!) but on the esp32 ... I'll try and get it working today ... Cheers and Thanks for the great work! |
Could you reduce that to a one-liner please? |
LINUX_DIST="Linux Mint 18.3 Sylvia MATE 32-bit"
KERNEL=Linux computer 4.10.0-38-generic i686 i686 i686 GNU/Linux
ARDUINO IDE: 1.8.10 (32bit)
elk Library: version 0.0.16 (Installed using Arduino IDE library manager)
ESP32 boards (DEVKIT): 1.0.4 (Installed with board manager from Arduino IDE)
I'm having difficulty with some code I'm trying to get working on the esp32 ... I believe my problem stems from my use of the Bitwise AND operator ... here is a snippet
code snippet
The text was updated successfully, but these errors were encountered: