This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* ----------------[ 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
device.on("ping", function(ping) { | |
device.send("pong", ping); | |
}) | |
server.log("Agent started") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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'"; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ============================================================================= | |
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; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Persist { | |
cache = null; | |
// ------------------------------------------------------------------------- | |
function read(key = null, def = null) { | |
if (cache == null) { | |
cache = server.load(); | |
} | |
return (key in cache) ? cache[key] : def; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Persist { | |
cache = null; | |
// ------------------------------------------------------------------------- | |
function read(key = null, def = null) { | |
if (cache == null) { | |
cache = server.load(); | |
} | |
return (key in cache) ? cache[key] : def; |
OlderNewer