Skip to content

Instantly share code, notes, and snippets.

View gfwilliams's full-sized avatar

Gordon Williams gfwilliams

View GitHub Profile
@gfwilliams
gfwilliams / bootupdate-with-time-debug.js
Created October 19, 2022 15:59
bootupdate.js for Bangle.js with ability to dump how long things take
/* This rewrites boot0.js based on current settings. If settings changed then it
recalculates, but this avoids us doing a whole bunch of reconfiguration most
of the time. */
E.showMessage(/*LANG*/"Updating boot0...");
var DEBUG_TIME = true; // print time taken by each section of boot.js
var s = require('Storage').readJSON('setting.json',1)||{};
var BANGLEJS2 = process.env.HWVERSION==2; // Is Bangle.js 2
var boot = "", bootPost = "";
if (DEBUG_TIME) boot += "var t=getTime();";
if (require('Storage').hash) { // new in 2v11 - helps ensure files haven't changed
@gfwilliams
gfwilliams / clock_info.js
Created September 8, 2022 14:35
clock_info.js
var exports = {};
/* Module that allows for loading of clock 'info' displays
that can be scrolled through on the clock face.
`load()` returns an array of menu items:
* 'item.name' : friendly name
* 'item.get' : function that resolves with:
{
'text' : the text to display for this item
@gfwilliams
gfwilliams / banglejs2_new_showmenu.js
Last active February 21, 2022 20:57
test code for new Bangle.js menu style
/*
TODO
Better rounded rect
setUI could be better - maybe include 'back' widget/handling code?
submenus could allow 'back' without modifying the menu item
*/
g.fillRRect = (x,y,w,h) => g.fillPoly([
x+4,y,
x+w-4,y,
// HSB test
for (var y=0;y<176;y+=4)
for (var x=0;x<176;x+=4)
g.setColor.apply(g,E.HSBtoRGB(x/176.0,y/176.0,1,1).map(x=>x/256)).fillRect(x,y,x+3,y+3);
@gfwilliams
gfwilliams / bangle_mr2.js
Last active August 13, 2021 18:04
Code for Bangle in Jim's MR2
// Where on the screen are we?
var W = 240;
var H = 180;
var X = 0;
var Y = 30;
// Misc setup
require("Font7x11Numeric7Seg").add(Graphics);
Bangle.setLCDPower(1);
@gfwilliams
gfwilliams / bangle-layout.js
Last active June 23, 2021 14:50
Layout library test code
// fill for 2v09 firmwares
if (!g.theme) {
g.theme = {
fg:-1,bg:0,fgH:-1,bgH:"#008"
};
}
// test with widgets
//WIDGETS = {a:1};
@gfwilliams
gfwilliams / bangle-testbtn.js
Created January 29, 2021 08:59
Bangle.js button test
function draw() {
c = c=>g.setColor(c?"#ff0000":-1);
c(BTN4.read());g.fillRect(0,0,100,239);
c(BTN5.read());g.fillRect(100,0,200,239);
c(BTN1.read());g.fillRect(200,0,239,79);
c(BTN2.read());g.fillRect(200,80,239,159);
c(BTN3.read());g.fillRect(200,160,239,239);
}
[BTN1,BTN2,BTN3,BTN4,BTN5].forEach(b=>setWatch(draw,b,{repeat:1,edge:0}));
draw();
var boolean = false;
var number = 50;
// First menu
var mainmenu = {
"" : { "title" : "-- Main Menu --" },
"Backlight On" : function() { LED1.set(); },
"Backlight Off" : function() { LED1.reset(); },
"A Boolean" : {
value : boolean,
format : v => v?"On":"Off",
@gfwilliams
gfwilliams / SIM900.js
Created January 5, 2021 16:13
Tweaked SIM900 library for Espruino
/* Copyright (c) 2015 Gordon Williams, Tobias Schwalm. See the file LICENSE for copying permission. */
/*
Library for interfacing to the SIM900A.
Uses the 'NetworkJS' library to provide a JS endpoint for HTTP.
```
Serial1.setup(115200, { rx: B7, tx : B6 });
console.log("Connecting to SIM900 module");
var gprs = require('SIM900').connect(Serial1, B4, function(err) {
var WIFI_NAME = "BTHub4-XFTX";
var WIFI_PASS = "735dfd986d";
// var re = /:[^/]+/g; needs changing to
// var re = /:[^\/]+/g;
var wifi = require("Wifi");
wifi.connect(WIFI_NAME, { password : WIFI_PASS }, function(err) {
if (err) {