espruino / Espruino

The Espruino JavaScript interpreter - Official Repo
http://www.espruino.com/
Other
2.75k stars 739 forks source link

Add function deepSleepExt1 for EXP32 #2369

Closed cwilling closed 1 year ago

cwilling commented 1 year ago

An array of RTC enabled GPIOs can be used to wake from deep sleep. Example code:

// Flash LED1 (while awake) var on = false; setInterval(function() { on = !on; LED1.write(on); }, 500);

// Every 10secs, sleep until any of pinArray is pressed setInterval(function() { var pinArray = [D4,D15];

ESP32.deepSleepExt1(pinArray, 1); }, 10000);

gfwilliams commented 1 year ago

Thanks! For the array, please could you use jsvIterator instead?

  JsvIterator it;
  jsvIteratorNew(&it, array, JSIF_DEFINED_ARRAY_ElEMENTS);
  while (jsvIteratorHasElement(&it)) {
   ... jsvIteratorGetValue(&it);
    jsvIteratorNext(&it);
  }
  jsvIteratorFree(&it);

There are some plans to change the way arrays are stored eventually (to make them a tree), so when doing that using LastChild would break.

cwilling commented 1 year ago

OK, using JsvIterator now.

gfwilliams commented 1 year ago

That was quick! But sorry - just spotted some other minor things...

cwilling commented 1 year ago

Done. Thanks for the tips.

gfwilliams commented 1 year ago

Great! Thanks!