Skip to content

Instantly share code, notes, and snippets.

View phoddie's full-sized avatar

Peter Hoddie phoddie

View GitHub Profile
@phoddie
phoddie / easing.c
Created February 17, 2024 06:49
break out easing functions to module
/*
* Copyright (c) 2016-2024 Moddable Tech, Inc.
*
* This file is part of the Moddable SDK Runtime.
*
* The Moddable SDK Runtime is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
@phoddie
phoddie / network.c
Created February 23, 2022 00:13
shocking xsbug-over-wifi back to life for ESP32
#include "xsmc.h"
#include "xsHost.h"
extern void fxConnectTo(xsMachine *the, void *pcb);
extern void *modSocketGetLWIP(xsMachine *the, xsSlot *slot);
extern void espDescribeInstrumentation(xsMachine *the);
void xs_debug(xsMachine *the)
{
#ifdef mxDebug
@phoddie
phoddie / main.js
Last active February 9, 2022 00:14
Battery monitor for M5Paper
/*
* Copyright (c) 2016-2022 Moddable Tech, Inc.
*
* This file is part of the Moddable SDK.
*
* This work is licensed under the
* Creative Commons Attribution 4.0 International License.
* To view a copy of this license, visit
* <http://creativecommons.org/licenses/by/4.0>.
* or send a letter to Creative Commons, PO Box 1866,
@phoddie
phoddie / tasks.json
Last active January 6, 2022 02:06
For Visual Studio Code builds. Goes into .vscode directory.
{
"version": "2.0.0",
"tasks": [
{
"label": "Build ESP8266 Debug",
"type": "shell",
"group": {
"kind": "build",
"isDefault": true
},
@phoddie
phoddie / io-class-pattern.md
Last active August 2, 2021 10:46
For Ecma TC53

I/O class pattern

Copyright 2018 Moddable Tech, Inc.
Peter Hoddie
Patrick Soquet
Updated December 17, 2018

Overview

The I/O class pattern is designed to be applied to many different interfaces. These include digital, analog input, SPI, I2C, serial, TCP socket, UDP socket, etc. Each of these defines a class pattern for the interface (e.g. a Digital class pattern) that is a logical subclass of the I/O class pattern.

The I/O class pattern assumes read and write operations will not block for significant periods of time (this is deliberately not quantified). The model for this is non-blocking network sockets.

@phoddie
phoddie / main.js
Created February 1, 2021 21:49
RMT implementation for ESP32
import RMT from "rmt";
let a = new RMT({pin: 2, channel: 0, divider: 255}); // GPIO 2, RMT channel 0, clk_div 255
a.onWritable = function() {
a.write(0, [32000 * 9, 32000, 32000 * 9, 32000, 32000 * 9, 32000, 32000 * 9, 32000]);
}
@phoddie
phoddie / main.js
Created January 18, 2021 22:57
Moddable SDK - UDP example
import {Socket} from "socket";
import Timer from "timer"
const socket = new Socket({kind: "UDP"});
socket.callback = function(message, value) {
if (Socket.readable !== message)
return;
const buffer = this.read(ArrayBuffer);
const longs = new Uint32Array(buffer);
@phoddie
phoddie / blue.js
Last active December 5, 2020 23:29
export default function() {
trace("blue\n");
}

Algorithms for TC53

Updated November 20, 2020

Notes

  • This document is an attempt to define formal algorithms for the draft of the TC53 specification
  • This document describes somee, but not all, of the APIs. Once these are in good shape, thy will be used as a model for the remaining APIs
  • The intent is to merge these algorithms into the specification

Internal Fields

@phoddie
phoddie / SPI.md
Created October 20, 2020 23:59
SPI Module for ESP8266 and ESP32

class SPI

The SPI class provides access to the SPI bus connected to Clock, MISO, and MOSI pins along with a designated Chip Select pin.

import SPI from "pins/spi";

constructor(dictionary)

The SPI constructor takes a dictionary which contains at least the frequency of the SPI device in Hertz (hz) and a sub-object (cs) containing the chip select pin number (pin).