Skip to content

Instantly share code, notes, and snippets.

View blindman2k's full-sized avatar

Aron Steg blindman2k

  • Launch Systems Pty Ltd
  • Melbourne, Australia
View GitHub Profile
@blindman2k
blindman2k / README.md
Last active August 29, 2015 14:00
Squirrel port of the BlueGiga BLE112 BGLib using BGAPI running on an Electric Imp device.

BGLib for Squirrel

This implements the BGLib library for Bluegiga's BLE112 Bluetooth Smart module.

It assumes you have connected from the Imp to the BLE112:

  • UART (uart1289 is recommended as flow control is important)
  • Wake pin (optional depending on BLE112 configuration)
  • Reset pin (optional but really helpful as software reset is not always reliable)
@blindman2k
blindman2k / README.md
Last active August 29, 2015 14:00
Hexdump is a function to output binary data in a hex + text format on a serial port.

Hexdump

This function will dump a blob or string as a hexdump to a serial port.

The input looks like this:

hexdump("RECV", "Hello world\n", "uart57");

The output (with a more complex input!) will look like this:

@blindman2k
blindman2k / WifiTimezone.agent.nut
Last active July 24, 2016 01:57
WifiTimezone class - Requests the imp to scan for wifi networks, sends that data to Mozilla to geolocate the imp, sends that data to timezonedb to collect timezone data.
// -----------------------------------------------------------------------------
// WifiTimezone class
//
// Requests the imp to scan for wifi networks, sends that data to Google Maps to
// geolocate the imp, sends that data to Google Maps to collect timezone data
//
class WifiTimezone {
@blindman2k
blindman2k / test_scanwifinetworks.device.nut
Created May 9, 2014 21:44
Uses an impeeduino to test the imp.scanwifinetworks() while in offline mode.
// Pin 2 is the red LED
ACTIVITY <- hardware.pin2;
ACTIVITY.configure(DIGITAL_OUT);
ACTIVITY.write(1);
// Pin 8 is the orange LED
LINK <- hardware.pin8;
LINK.configure(DIGITAL_OUT);
LINK.write(1);
@blindman2k
blindman2k / neo_neopixel.device.nut
Created May 14, 2014 17:42
This is a new Neopixel class designed specifically for rectangular X/Y coordinate systems but still works fine for linear strips. Note the function names have changed.
class NeoPixels {
// when instantiated, the neopixel class will fill this array with blobs to
// represent the waveforms to send the numbers 0 to 255. This allows the blobs to be
// copied in directly, instead of being built for each pixel - which makes the class faster.
bits = null;
// Like bits, this blob holds the waveform to send the color [0,0,0], to clear pixels faster
clearblob = null;
@blindman2k
blindman2k / agent.nut
Created May 16, 2014 00:18
DA14580 boot code
server.log("Agent started, URL is " + http.agenturl());
//------------------------------------------------------------------------------------------------------------------------------
program <- null;
html <- @"<HTML>
<BODY>
<form method='POST' enctype='multipart/form-data'>
@blindman2k
blindman2k / vformat.nut
Last active August 29, 2015 14:01
vformat gives you the same functionality is format() but allows you to pass in parameters as an arbitrary length array.
function vformat(fmt,...) {
local args = [this,fmt];
if (typeof(vargv[0]) == "array") {
vargv = vargv[0];
}
args.extend(vargv);
return format.acall(args);
}
// ----------------------[ Example use ]----------------------
@blindman2k
blindman2k / override.nut
Last active August 29, 2015 14:01
Overriding imp's built-in objects can be fun :)
// This is a really simple, reusable wrapper for any internal object to turn it into a class.
// For memory and performance reasons, the built-in classes are not real classes so can't
// be extended in the normal way.
class impWrapper {
_wrapped = null;
constructor(wrapped) {
_wrapped = wrapped;
}
// -----------------------------------------------------------------------------
class Rocky
{
_handlers = null;
_timeout = 10;
// --------------------[ PUBLIC FUNCTIONS ]---------------------------------
// .........................................................................
@blindman2k
blindman2k / newblank.agent.nut
Last active August 29, 2015 14:02
This New Blank model is designed to allow simple HTTP GET commands to read and write the imp and its pins.
/*
* These are the currently supported commands (URLs)
*
* /device/hardware/pinX/configure (DIGITAL_OUT, DIGITAL_IN, ANALOG_OUT, ANALOG_IN, PWM_OUT)
* /device/hardware/pinX/read
* /device/hardware/pinX/write
*
* /device/hardware/X (all hardware.* commands like lightlevel, voltage, etc)
*
* /device/imp/X (all imp.* commands that take no parameters like getssid, rssi, etc)