Skip to content
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

ESP8266 & AVR under the Arduino IDE fails when setting a variable #12

Closed
sfranzyshen opened this issue Nov 28, 2019 · 1 comment
Closed

Comments

@sfranzyshen
Copy link

sfranzyshen commented Nov 28, 2019

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: release 0.0.16 (Installed manually into Arduino IDE library folder)
ESP8266 BOARD: 2.5.2 (Installed with board manager from Arduino IDE)
Arduino Boards: 1.8.1 (Installed with board manager from Arduino IDE)
ESP32 Board: 1.0.4 (Installed with board manager from Arduino IDE)

Test Code

#include "elk.h"  // Add Elk library

extern "C" void myDelay(int milli) {
  delay(milli);
}
extern "C" void myWrite(int pin, int val) {
  digitalWrite(pin, val);
}
extern "C" void myMode(int pin, int mode) {
  pinMode(pin, mode);
}

struct js *js;

void setup() {
  Serial.begin(115200);
  Serial.println();
  js = js_create(malloc(700), 700);
  Serial.println("malloc done");
  js_import(js, "delay", (uintptr_t) myDelay, "vi");
  js_import(js, "digitalWrite", (uintptr_t) myWrite, "vii");
  js_import(js, "pinMode", (uintptr_t) myMode, "vii");
  Serial.println("imports done");

  js_eval(js, "let pin = 2;", 0);  // <--- HERE IS THE PROBLEM ON ESP8266 & AVR

  js_eval(js, "pinMode(2, 1);", 0);  // Set LED pin to OUTPUT mode ... on esp32 set to (pin, 2)
  js_eval(js, "let loop = function() { delay(200); digitalWrite(2, 1); delay(200); digitalWrite(2, 0); };", 0);

  Serial.println("ready ... looping");
}

void loop() {
  js_eval(js, "loop();", 0);
  Serial.println(" ... looping");
}

This functions as expected on the esp32 platform ... and when I eliminate the variable from the digitalWrite function calls and remark-out the "let pin = 2" js_eval call ... everything works as expected on the esp8266 & arv platforms ... so it's defiantly the "let pin = 2;" variable setting call that's causing things to bork on the esp8266 & avr platforms ...

UPDATE: on the avr platform it reboots ... on the esp8266 it ignores any js_evals after the "let pin = 2" call ... update update ... if I don't try to access the variable ... no reboot happens ... but still doesn't function ... just setting the variable causes it to fail ...

@sfranzyshen sfranzyshen changed the title ESP8266 under the Arduino IDE fails when setting a variable ESP8266 & AVR under the Arduino IDE fails when setting a variable Nov 28, 2019
@cpq
Copy link
Member

cpq commented Dec 2, 2019

Updated API a bit.
Updated an example to use variables and printing stats to the serial.
Pushed version 17.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants