Skip to content

Instantly share code, notes, and snippets.

View MaBecker's full-sized avatar

Mark Becker MaBecker

  • SBIT GmbH
  • Germany, Rauenberg
View GitHub Profile
// Captive Portal
var http = require('http');
var Wifi = require('Wifi');
var dgram = require('dgram');
var server = dgram.createSocket('udp4');
var SSID = 'CaptivePortalTest';
@MaBecker
MaBecker / scrollString.js
Created January 15, 2018 22:04
Scroll String on 3 x 8x8 neopixel panel
// scrollString.js
// tested on ESP8266 12F
var pin = D4;
// connected to three neopixel plate (x,y)=(0-7,0-23)
var leds = Graphics.createArrayBuffer(8,24,24);
leds.setRotation(1,false);
leds.flip = function(){require("neopixel").write(pin,leds.buffer);};
leds.off = function(){leds.clear();leds.flip();};
/*
test_remap.js
sample how to remap a pixel on a sequential 8x8 wired panel
*/
var np = {
pin : D4,
neopixels : 0,
leds : [],
pannelList : [],
@MaBecker
MaBecker / jswrap_wifi_save.c
Last active May 2, 2018 11:29
function: jswrap_wifi_save.c
void jswrap_wifi_save(JsVar *what) {
DBGV("> Wifi.save\n");
JsVar *o = jsvNewObject();
if (!o) return;
if (jsvIsString(what) && jsvIsStringEqual(what, "clear")) {
JsVar *name = jsvNewFromString(WIFI_CONFIG_STORAGE_NAME);
jswrap_storage_erase(name);
jsvUnLock(name);
DBG("Wifi.save(clear)\n");
@MaBecker
MaBecker / function: jswrap_wifi_restore
Last active May 2, 2018 11:31
jswrap_wifi_save.c
void jswrap_wifi_restore(void) {
DBG("Wifi.restore\n");
JsVar *name = jsvNewFromString(WIFI_CONFIG_STORAGE_NAME);
JsVar *o = jswrap_storage_readJSON(name);
if (!o) { // no data
jsvUnLock2(name,o);
return;
}
/*
function queue
based on
https://stackoverflow.com/questions/17528749/semaphore-like-queue-in-javascript/17528961#17528961
*/
@MaBecker
MaBecker / using_font_from_storage.js
Created December 5, 2018 19:28
Espruino: store FontHaxorNarrow7x17 in storage and print single and double size without using any RAM for font and widths
var s = require('Storage');
/* use this code only once to save font and widths in Storage
s.write('fHN7x17',atob("AAAAAAAAAAAB/MAAAJAAcAAAABIADgAAAAACAAngB4AeeAHgB5AAQAAAAHEAREAiID/4CIgERAEcAAAAwMCQgEmAGTADJAISBgYAAAAHgHQgRBAjCA5kAAwAPQAAAkABwAAAAAfADBgIAggAgAACACCAIDBgB8AAAAEgAGAA/AAYABIAAAABAACAAEAB/AAQAAgABAAAAAAkABwAAAAgABAACAAEAAIAAAAADAAGAAAAAIABgAMABgAMABgAAAAB/AEBAQxAjCAgIA/gAAACAAIAAgAB/8AAACBwIMgQhAiCA4EAAACAgIAgQhAhCA94AAAAGAA0ACIAYQB/8ABAAAAPhARBAiCBEECHwAAAH/ARBAiCBEEBHwAAAIAAQPAhgBMADgAAAAHvAQhAhCBCEB7wAAAHhAQhAhCBCEB/wAAADDAGGAAAAYUAwwAAAAQABQAEQAQQBAQAAABEACIAEQAIgARAAiAAAAICAIIAIgAKAAIAAAAIAAgABBMCEAEQAHAAAAAf8BAECOIEiQJEgP4AAAAP8BiAEEAGIAD/AAAB/8CEIEIQIQgPeAAAA/4CAIEAQIAgICAAAB/8CAIEAQEBAH8AAAB/8CEIEIQIQgQBAAAB/8CIAEQAIgAQAAAAA/4CAIEAQIQgI+AAAB/8AEAAIAAQAf/AAABAED/4EAQAAAQGAgCBAECAIH/gAAAf/ABAAFAAxgGAwAAAf/AACAAEAAIAAQAAAf/AYAAMABgAH/wAAAf/AYAAMAAGAH/wAAAP+AgCBAECAID/gAAAf/AhABCACEADwAAAAP+AgCBAUCAQD/QAAAf/AhABCACHADxwAAAOCAiCBCECCICDgAAAQAAgAB/8CAAEAAAAAf+AACAAEAAIH/gAAAfAAB4AAMAHgHwAAAAf8
@MaBecker
MaBecker / test_case_module_sbus.js
Created December 11, 2018 05:42
Special char in modules cause error when using require to load from storage
s = require('Storage');
s.write('SBUS',`exports.connect = function(uart, rxPin) {
var sbus = {
channels : new Uint16Array(18),
frameLoss : false,
failSafe : false
};
uart.setup(100000, {rx:rxPin, parity:"e",stopbits:2});
uart.removeAllListeners();
@MaBecker
MaBecker / welcome.js
Created November 30, 2019 09:17
MySample
g.clear();
g.setFont("6x8",3);
g.setColor(0x07E0);
g.drawString("Welcome\nto the\nBangle.js\nEmulator",20,60);
@MaBecker
MaBecker / complex_fillPoly.js
Created December 1, 2019 13:44
Sample for complex paths that are not rendered as expected in 2v04 build 250
var flake1 = [114,120,126,120,126,150,150,168,144,180,126,168,126,192,114,192,114,168,96,180,90,168,114,150,114,120];
var flake2 = [114,20,126,20,126,50,150,68,144,80,126,68,126,92,114,92,114,68,96,80,90,68,114,50,114,20];
g.clear();
g.drawPoly(flake1);
g.fillPoly(flake2);