Skip to content

Instantly share code, notes, and snippets.

View blindman2k's full-sized avatar

Aron Steg blindman2k

View GitHub Profile
@blindman2k
blindman2k / lala_tone_generator.nut
Last active December 21, 2015 20:09
Squirrel code for outputting a three second tone from an Imp "Lala" audio board.
/* ----------------[ PIN CONFIGURATION ]----------------------------------------
Pinout:
1 = Wake / SPI CLK
2 = Sampler (Audio In)
5 = DAC (Audio Out)
6 = Button 1
7 = SPI CS_L
8 = SPI MOSI
9 = SPI MISO
@blindman2k
blindman2k / serializer.nut
Last active December 21, 2015 21:29
Squirrel code for serializing and de-serializing any serializable object.
/*
Copyright (C) 2013 electric imp, inc.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
and associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute,
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial
@blindman2k
blindman2k / loggly.nut
Created September 26, 2013 00:38
Posting log entries to Loggly
const LOGGLY_URL = "https://logs-01.loggly.com/inputs/TOKEN/tag/imp/";
function log(message, callback = null) {
if (typeof message != "object") {
message = {message = message};
}
http.post(LOGGLY_URL, {}, http.jsonencode(message)).sendasync(function (res) {
if (res.statuscode != 200) server.log("Error posting to Logly: " + res.statuscode);
if (callback) callback(res);
})
// RGB sensor code, stripped to basics, to get initialization working...
const i2c_ioexp = 0x7C; // I2C channel base adddreses
const i2c_als = 0xE8; // adjusted to 8 bit values
// Initialise the imp hardware
local i2c = hardware.i2c89;
i2c.configure(CLOCK_SPEED_100_KHZ);
// ------------------------------------------------ rgbdcs register definitions -----------------------------------------------------
const rgbdcsRED = 0; const rgbdcsGREEN = 1; const rgbdcsBLUE = 2; const rgbdcsCLEAR = 3;
@blindman2k
blindman2k / agent_ping.agent.js
Last active December 24, 2015 00:59
The device pings the agent every second. If it misses a pong response it turns on the light for at least 10 seconds.
device.on("ping", function(ping) {
device.send("pong", ping);
})
server.log("Agent started")
@blindman2k
blindman2k / strtodate.nut
Created March 15, 2014 08:27
strtodate populates a date() table with the time represented by a string (and a timezone offset)
//
// strtodate populates a date() table with the time represented by a string (and a timezone offset)
// Note it is a very rigid date format. It is an exercise for the reader to expand/adapt the format to their needs.
//
function strtodate(str, tz=-300) {
// Capture the components of the date time string
local ex = regexp(@" ([a-zA-Z]+) ([0-9]+), ([0-9]+) ([0-9]+):([0-9]+) ([AP]M)");
local ca = ex.capture(str);
if (ca.len() != 7) throw "We are currently expecting, exactly, this format: 'Tuesday, January 7, 2014 9:57 AM'";
// =============================================================================
const NUMPIXELS = 24;
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;
@blindman2k
blindman2k / uart_gateway.agent.nut
Last active August 29, 2015 14:00
Imp gateway demo - communicate with a line-oriented UART device through a web interface
const HTML = @"
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='utf-8'>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<title>Imp Gateway Demo</title>
@blindman2k
blindman2k / persist.agent.nut
Created April 26, 2014 05:14
Agent persistent storage class
class Persist {
cache = null;
// -------------------------------------------------------------------------
function read(key = null, def = null) {
if (cache == null) {
cache = server.load();
}
return (key in cache) ? cache[key] : def;
@blindman2k
blindman2k / persist.agent.nut
Created April 26, 2014 05:14
Agent persistent storage class
class Persist {
cache = null;
// -------------------------------------------------------------------------
function read(key = null, def = null) {
if (cache == null) {
cache = server.load();
}
return (key in cache) ? cache[key] : def;