From 39e771d5655b617bc47d4b57aa1b2d921fd70b18 Mon Sep 17 00:00:00 2001 From: teldredge Date: Thu, 13 Dec 2012 19:11:59 -0800 Subject: [PATCH 1/2] Create factfirmmod_wdazzle --- factfirmmod_wdazzle | 226 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 226 insertions(+) create mode 100644 factfirmmod_wdazzle diff --git a/factfirmmod_wdazzle b/factfirmmod_wdazzle new file mode 100644 index 0000000..d3b1f32 --- /dev/null +++ b/factfirmmod_wdazzle @@ -0,0 +1,226 @@ +/* + +Modified Factory Firmware +USE AT YOUR HEXBRIGHTS RISK!!! +Dec 13, 2012 +-Dazzle mode (from example code) added after blinky mode + +*/ + +#include +#include + +// Settings +#define OVERTEMP 340 +// Pin assignments +#define DPIN_RLED_SW 2 +#define DPIN_GLED 5 +#define DPIN_PWR 8 +#define DPIN_DRV_MODE 9 +#define DPIN_DRV_EN 10 +#define APIN_TEMP 0 +#define APIN_CHARGE 3 +// Modes +#define MODE_OFF 0 +#define MODE_LOW 1 +#define MODE_MED 2 +#define MODE_HIGH 3 +#define MODE_BLINKING 4 +#define MODE_BLINKING_PREVIEW 5 +#define MODE_DAZZLE 6 + +// State +byte mode = 0; +unsigned long btnTime = 0; +boolean btnDown = false; + + +void setup() +{ + // We just powered on! That means either we got plugged + // into USB, or the user is pressing the power button. + pinMode(DPIN_PWR, INPUT); + digitalWrite(DPIN_PWR, LOW); + + // Initialize GPIO + pinMode(DPIN_RLED_SW, INPUT); + pinMode(DPIN_GLED, OUTPUT); + pinMode(DPIN_DRV_MODE, OUTPUT); + pinMode(DPIN_DRV_EN, OUTPUT); + digitalWrite(DPIN_DRV_MODE, LOW); + digitalWrite(DPIN_DRV_EN, LOW); + + // Initialize serial busses + Serial.begin(9600); + Wire.begin(); + + btnTime = millis(); + btnDown = digitalRead(DPIN_RLED_SW); + mode = MODE_OFF; + + Serial.println("Powered up!"); +} + +void loop() +{ + static unsigned long lastTempTime; + unsigned long time = millis(); + + // Check the state of the charge controller + int chargeState = analogRead(APIN_CHARGE); + if (chargeState < 128) // Low - charging + { + digitalWrite(DPIN_GLED, (time&0x0100)?LOW:HIGH); + } + else if (chargeState > 768) // High - charged + { + digitalWrite(DPIN_GLED, HIGH); + } + else // Hi-Z - shutdown + { + digitalWrite(DPIN_GLED, LOW); + } + + // Check the temperature sensor + if (time-lastTempTime > 1000) + { + lastTempTime = time; + int temperature = analogRead(APIN_TEMP); + Serial.print("Temp: "); + Serial.println(temperature); + if (temperature > OVERTEMP && mode != MODE_OFF) + { + Serial.println("Overheating!"); + + for (int i = 0; i < 6; i++) + { + digitalWrite(DPIN_DRV_MODE, LOW); + delay(100); + digitalWrite(DPIN_DRV_MODE, HIGH); + delay(100); + } + digitalWrite(DPIN_DRV_MODE, LOW); + + mode = MODE_LOW; + } + } + + // Do whatever this mode does + switch (mode) + { + case MODE_BLINKING: + case MODE_BLINKING_PREVIEW: + digitalWrite(DPIN_DRV_EN, (time%300)<75); + break; + case MODE_DAZZLE: + static unsigned long lastTime; + if (millis() - lastTime > 10) + { + digitalWrite(DPIN_DRV_EN, random(4)<1); + lastTime = millis(); + } + break; + } + + // Periodically pull down the button's pin, since + // in certain hardware revisions it can float. + pinMode(DPIN_RLED_SW, OUTPUT); + pinMode(DPIN_RLED_SW, INPUT); + + // Check for mode changes + byte newMode = mode; + byte newBtnDown = digitalRead(DPIN_RLED_SW); + switch (mode) + { + case MODE_OFF: + if (btnDown && !newBtnDown && (time-btnTime)>20) + newMode = MODE_LOW; + if (btnDown && newBtnDown && (time-btnTime)>500) + newMode = MODE_BLINKING_PREVIEW; + break; + case MODE_LOW: + if (btnDown && !newBtnDown && (time-btnTime)>50) + newMode = MODE_MED; + break; + case MODE_MED: + if (btnDown && !newBtnDown && (time-btnTime)>50) + newMode = MODE_HIGH; + break; + case MODE_HIGH: + if (btnDown && !newBtnDown && (time-btnTime)>50) + newMode = MODE_OFF; + break; + case MODE_BLINKING_PREVIEW: + // This mode exists just to ignore this button release. + if (btnDown && !newBtnDown) + newMode = MODE_BLINKING; + break; + case MODE_BLINKING: + if (btnDown && !newBtnDown && (time-btnTime)>50) + newMode = MODE_DAZZLE; + break; + case MODE_DAZZLE: + if (btnDown && !newBtnDown && (time-btnTime)>50) + newMode = MODE_OFF; + break; + } + + // Do the mode transitions + if (newMode != mode) + { + switch (newMode) + { + case MODE_OFF: + Serial.println("Mode = off"); + pinMode(DPIN_PWR, OUTPUT); + digitalWrite(DPIN_PWR, LOW); + digitalWrite(DPIN_DRV_MODE, LOW); + digitalWrite(DPIN_DRV_EN, LOW); + break; + case MODE_LOW: + Serial.println("Mode = low"); + pinMode(DPIN_PWR, OUTPUT); + digitalWrite(DPIN_PWR, HIGH); + digitalWrite(DPIN_DRV_MODE, LOW); + analogWrite(DPIN_DRV_EN, 64); + break; + case MODE_MED: + Serial.println("Mode = medium"); + pinMode(DPIN_PWR, OUTPUT); + digitalWrite(DPIN_PWR, HIGH); + digitalWrite(DPIN_DRV_MODE, LOW); + analogWrite(DPIN_DRV_EN, 255); + break; + case MODE_HIGH: + Serial.println("Mode = high"); + pinMode(DPIN_PWR, OUTPUT); + digitalWrite(DPIN_PWR, HIGH); + digitalWrite(DPIN_DRV_MODE, HIGH); + analogWrite(DPIN_DRV_EN, 255); + break; + case MODE_BLINKING: + case MODE_BLINKING_PREVIEW: + Serial.println("Mode = blinking"); + pinMode(DPIN_PWR, OUTPUT); + digitalWrite(DPIN_PWR, HIGH); + digitalWrite(DPIN_DRV_MODE, HIGH); + break; + case MODE_DAZZLE: + Serial.println("Mode = dazzle"); + pinMode(DPIN_PWR, OUTPUT); + digitalWrite(DPIN_PWR, HIGH); + digitalWrite(DPIN_DRV_MODE, HIGH); + break; + } + + mode = newMode; + } + + // Remember button state so we can detect transitions + if (newBtnDown != btnDown) + { + btnTime = time; + btnDown = newBtnDown; + delay(50); + } +} From 064093acf60743a01eee2334ff6005aea2f70f94 Mon Sep 17 00:00:00 2001 From: teldredge Date: Sun, 16 Dec 2012 14:59:48 -0800 Subject: [PATCH 2/2] Create factfirmmod --- factfirmmod | 246 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 246 insertions(+) create mode 100644 factfirmmod diff --git a/factfirmmod b/factfirmmod new file mode 100644 index 0000000..bdc41ae --- /dev/null +++ b/factfirmmod @@ -0,0 +1,246 @@ +/* + +Modified Factory Firmware +USE AT YOUR HEXBRIGHTS RISK +Dec 13, 2012 +-Dazzle mode (from example code) added after blinky mode +Dec 16, 2012 +-Off by holding button down between LOW|MED|HIGH +-Added ultra low mode +*/ + +#include +#include + +// Settings +#define OVERTEMP 340 +// Pin assignments +#define DPIN_RLED_SW 2 +#define DPIN_GLED 5 +#define DPIN_PWR 8 +#define DPIN_DRV_MODE 9 +#define DPIN_DRV_EN 10 +#define APIN_TEMP 0 +#define APIN_CHARGE 3 +// Modes +#define MODE_OFF 0 +#define MODE_ULTRA_LOW 1 +#define MODE_LOW 2 +#define MODE_MED 3 +#define MODE_HIGH 4 +#define MODE_BLINKING 5 +#define MODE_BLINKING_PREVIEW 6 +#define MODE_DAZZLE 7 + +// State +byte mode = 0; +unsigned long btnTime = 0; +boolean btnDown = false; + + +void setup() +{ + // We just powered on! That means either we got plugged + // into USB, or the user is pressing the power button. + pinMode(DPIN_PWR, INPUT); + digitalWrite(DPIN_PWR, LOW); + + // Initialize GPIO + pinMode(DPIN_RLED_SW, INPUT); + pinMode(DPIN_GLED, OUTPUT); + pinMode(DPIN_DRV_MODE, OUTPUT); + pinMode(DPIN_DRV_EN, OUTPUT); + digitalWrite(DPIN_DRV_MODE, LOW); + digitalWrite(DPIN_DRV_EN, LOW); + + // Initialize serial busses + Serial.begin(9600); + Wire.begin(); + + btnTime = millis(); + btnDown = digitalRead(DPIN_RLED_SW); + mode = MODE_OFF; + + Serial.println("Powered up!"); +} + +void loop() +{ + static unsigned long lastTempTime; + unsigned long time = millis(); + + // Check the state of the charge controller + int chargeState = analogRead(APIN_CHARGE); + if (chargeState < 128) // Low - charging + { + digitalWrite(DPIN_GLED, (time&0x0100)?LOW:HIGH); + } + else if (chargeState > 768) // High - charged + { + digitalWrite(DPIN_GLED, HIGH); + } + else // Hi-Z - shutdown + { + digitalWrite(DPIN_GLED, LOW); + } + + // Check the temperature sensor + if (time-lastTempTime > 1000) + { + lastTempTime = time; + int temperature = analogRead(APIN_TEMP); + Serial.print("Temp: "); + Serial.println(temperature); + if (temperature > OVERTEMP && mode != MODE_OFF) + { + Serial.println("Overheating!"); + + for (int i = 0; i < 6; i++) + { + digitalWrite(DPIN_DRV_MODE, LOW); + delay(100); + digitalWrite(DPIN_DRV_MODE, HIGH); + delay(100); + } + digitalWrite(DPIN_DRV_MODE, LOW); + + mode = MODE_LOW; + } + } + + // Do whatever this mode does + switch (mode) + { + case MODE_BLINKING: + case MODE_BLINKING_PREVIEW: + digitalWrite(DPIN_DRV_EN, (time%300)<75); + break; + case MODE_DAZZLE: + static unsigned long lastTime; + if (millis() - lastTime > 10) + { + digitalWrite(DPIN_DRV_EN, random(4)<1); + lastTime = millis(); + } + break; + } + + // Periodically pull down the button's pin, since + // in certain hardware revisions it can float. + pinMode(DPIN_RLED_SW, OUTPUT); + pinMode(DPIN_RLED_SW, INPUT); + + // Check for mode changes + byte newMode = mode; + byte newBtnDown = digitalRead(DPIN_RLED_SW); + switch (mode) + { + case MODE_OFF: + if (btnDown && !newBtnDown && (time-btnTime)>20) + newMode = MODE_ULTRA_LOW; + if (btnDown && newBtnDown && (time-btnTime)>500) + newMode = MODE_BLINKING_PREVIEW; + break; + case MODE_ULTRA_LOW: + if (btnDown && !newBtnDown && (time-btnTime)>50) + newMode = MODE_LOW; + if (btnDown && !newBtnDown && (time-btnTime)>500) + newMode = MODE_OFF; + break; + case MODE_LOW: + if (btnDown && !newBtnDown && (time-btnTime)>50) + newMode = MODE_MED; + if (btnDown && !newBtnDown && (time-btnTime)>500) + newMode = MODE_OFF; + break; + case MODE_MED: + if (btnDown && !newBtnDown && (time-btnTime)>50) + newMode = MODE_HIGH; + if (btnDown && !newBtnDown && (time-btnTime)>500) + newMode = MODE_OFF; + break; + case MODE_HIGH: + if (btnDown && !newBtnDown && (time-btnTime)>50) + newMode = MODE_OFF; + break; + case MODE_BLINKING_PREVIEW: + // This mode exists just to ignore this button release. + if (btnDown && !newBtnDown) + newMode = MODE_BLINKING; + break; + case MODE_BLINKING: + if (btnDown && !newBtnDown && (time-btnTime)>50) + newMode = MODE_DAZZLE; + break; + case MODE_DAZZLE: + if (btnDown && !newBtnDown && (time-btnTime)>50) + newMode = MODE_OFF; + break; + } + + // Do the mode transitions + if (newMode != mode) + { + switch (newMode) + { + case MODE_OFF: + Serial.println("Mode = off"); + pinMode(DPIN_PWR, OUTPUT); + digitalWrite(DPIN_PWR, LOW); + digitalWrite(DPIN_DRV_MODE, LOW); + digitalWrite(DPIN_DRV_EN, LOW); + break; + case MODE_ULTRA_LOW: + Serial.println("Mode = ultra low"); + pinMode(DPIN_PWR, OUTPUT); + digitalWrite(DPIN_PWR, HIGH); + digitalWrite(DPIN_DRV_MODE, LOW); + analogWrite(DPIN_DRV_EN, 16); + break; + case MODE_LOW: + Serial.println("Mode = low"); + pinMode(DPIN_PWR, OUTPUT); + digitalWrite(DPIN_PWR, HIGH); + digitalWrite(DPIN_DRV_MODE, LOW); + analogWrite(DPIN_DRV_EN, 64); + break; + case MODE_MED: + Serial.println("Mode = medium"); + pinMode(DPIN_PWR, OUTPUT); + digitalWrite(DPIN_PWR, HIGH); + digitalWrite(DPIN_DRV_MODE, LOW); + analogWrite(DPIN_DRV_EN, 255); + break; + case MODE_HIGH: + Serial.println("Mode = high"); + pinMode(DPIN_PWR, OUTPUT); + digitalWrite(DPIN_PWR, HIGH); + digitalWrite(DPIN_DRV_MODE, HIGH); + analogWrite(DPIN_DRV_EN, 255); + break; + case MODE_BLINKING: + case MODE_BLINKING_PREVIEW: + Serial.println("Mode = blinking"); + pinMode(DPIN_PWR, OUTPUT); + digitalWrite(DPIN_PWR, HIGH); + digitalWrite(DPIN_DRV_MODE, HIGH); + break; + case MODE_DAZZLE: + Serial.println("Mode = dazzle"); + pinMode(DPIN_PWR, OUTPUT); + digitalWrite(DPIN_PWR, HIGH); + digitalWrite(DPIN_DRV_MODE, HIGH); + break; + } + + mode = newMode; + } + + // Remember button state so we can detect transitions + if (newBtnDown != btnDown) + { + btnTime = time; + btnDown = newBtnDown; + delay(50); + } +}