Created
April 25, 2017 17:02
-
-
Save ersatzavian/d12722d4603f53a817bf64af9ce87954 to your computer and use it in GitHub Desktop.
Using an Electric Imp IR Tail as a BlinkUp fixture
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
// IR Tail Factory BlinkUp Fixture sample firmware | |
const SSID = "SSID"; | |
const PASSWORD = "PASSWORD"; | |
const BLINKUP_TIME = 5; // seconds; duration of blinkup | |
function log(msg) { | |
if (server.isconnected()) { | |
server.log(msg); | |
} | |
} | |
// FACTORY TOOLS LIBRARY ------------------------------------------------------ | |
class FactoryTools { | |
static function isFactoryFirmware() { | |
if ("factoryfirmware" in imp.configparams && imp.configparams["factoryfirmware"]) { | |
return true; | |
} | |
return false; | |
} | |
static function isFactoryImp() { | |
if (isFactoryFirmware()) { | |
if ("factory_imp" in imp.configparams) { | |
if (imp.configparams["factory_imp"] == imp.getmacaddress()) { | |
return true; | |
} | |
} | |
} | |
return false; | |
} | |
static function isDeviceUnderTest() { | |
if (isFactoryFirmware() && !isFactoryImp()) { | |
return true; | |
} | |
return false; | |
} | |
} | |
/* RUNTIME START -------------------------------------------------------------*/ | |
imp.enableblinkup(true); | |
server.log("Device Online"); | |
function runDUTPath() { | |
log("Device Under Test"); | |
log("SW Version: " +imp.getsoftwareversion()); | |
log("Memory Free: "+imp.getmemoryfree()); | |
// this is the device under test | |
} | |
function sendBlinkUp() { | |
// send on button press only, not release | |
if (!btn1.read() && !btn2.read()) { return; } | |
imp.wakeup(0.1, function() { | |
server.log("sending blinkup"); | |
blinkUpPin.write(1); | |
led.write(1); | |
imp.wakeup(BLINKUP_TIME, function() { | |
led.write(0); | |
}); | |
server.factoryblinkup(SSID, PASSWORD, blinkUpPin, BLINKUP_FAST); | |
}); | |
} | |
function runFixturePath() { | |
btn1 <- hardware.pin1; | |
btn2 <- hardware.pin2; | |
blinkUpEn <- hardware.pin7; | |
blinkUpPin <- hardware.pin8; | |
led <- hardware.pin5; | |
btn1.configure(DIGITAL_IN_PULLDOWN, sendBlinkUp); | |
btn2.configure(DIGITAL_IN_PULLDOWN, sendBlinkUp); | |
blinkUpEn.configure(DIGITAL_OUT, 1); | |
blinkUpPin.configure(DIGITAL_OUT, 1); | |
led.configure(DIGITAL_OUT, 0); | |
} | |
if (FactoryTools.isFactoryImp()) { | |
runFixturePath(); | |
} else if (FactoryTools.isDeviceUnderTest()) { | |
runDUTPath(); | |
} else { | |
server.log("This firmware is not running in a factory environment"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment