Skip to content
Permalink
Browse files

Programming mode changes (closed bolt & LED behavior)

- Board reset (hold trigger down to get into programming mode and keep holding it
  until light starts flashing red, then release to reset board)
- Change register 0 to store code version
- Reset all registers to default values if code version is old
- Added programming registers for closed bolt mode
  • Loading branch information...
sumorai committed Jun 12, 2013
1 parent 33c53ee commit 6816679f5ce388335f35a10548e3a79e68c1ff65
Showing with 247 additions and 68 deletions.
  1. +27 −11 GCode.ino
  2. +26 −12 LED.ino
  3. +79 −17 Programming.ino
  4. +19 −3 README.txt
  5. +90 −23 config.h
  6. +1 −1 debug.h
  7. +5 −1 globals.h
@@ -65,6 +65,13 @@ void setup() {
OperatingMode = MODE_FIRING;
}

// reset programming if program version was updated
byte programVersion = EEPROM.read(REGISTER_VERSION);

if( programVersion != PROGRAM_VERSION ) {
resetProgrammingToDefault();
}

// read in programming register items
Conf_Debounce = EEPROM.read(REGISTER_DEBOUNCE);
Conf_Dwell = EEPROM.read(REGISTER_DWELL);
@@ -161,6 +168,11 @@ void setup() {

// do a little power on color burst like Tadao board does
powerOnLEDBurst(OperatingMode);

if( OperatingMode = MODE_PROGRAMMING ) {
// track pull time so we can reset the board if held for a certain length of time
Prog_TriggerDownStart = millis();
}
}


@@ -181,17 +193,22 @@ void loop(){
/****************************************** Misc. Functions ************************************/
byte getMaxRegisterValue(int regNum) {
switch( regNum ) {
case REGISTER_DEBOUNCE: return REGISTER_DEBOUNCE_MAX;
case REGISTER_DWELL: return REGISTER_DWELL_MAX;
case REGISTER_LOADER_DELAY: return REGISTER_LOADER_DELAY_MAX;
case REGISTER_MECH_DEBOUNCE: return REGISTER_MECH_DEBOUNCE_MAX;
case REGISTER_FSDO_DWELL: return REGISTER_FSDO_DWELL_MAX;
case REGISTER_FIRE_MODE: return REGISTER_FIRE_MODE_MAX;
case REGISTER_DEBOUNCE: return REGISTER_DEBOUNCE_MAX;
case REGISTER_DWELL: return REGISTER_DWELL_MAX;
case REGISTER_LOADER_DELAY: return REGISTER_LOADER_DELAY_MAX;
case REGISTER_MECH_DEBOUNCE: return REGISTER_MECH_DEBOUNCE_MAX;
case REGISTER_FSDO_DWELL: return REGISTER_FSDO_DWELL_MAX;
case REGISTER_FIRE_MODE: return REGISTER_FIRE_MODE_MAX;

case REGISTER_CLOSED_DWELL: return REGISTER_CLOSED_DWELL_MAX;
case REGISTER_CLOSED_EYE_DELAY: return REGISTER_CLOSED_EYE_DELAY_MAX;
case REGISTER_CLOSED_BOLT_DELAY: return REGISTER_CLOSED_BOLT_DELAY_MAX;


case REGISTER_ROF_ON_INT: return REGISTER_ROF_ON_INT_MAX;
case REGISTER_ROF_ON_FRAC: return REGISTER_ROF_ON_FRAC_MAX;
case REGISTER_ROF_OFF_INT: return REGISTER_ROF_OFF_INT_MAX;
case REGISTER_ROF_OFF_FRAC: return REGISTER_ROF_OFF_FRAC_MAX;
case REGISTER_ROF_ON_INT: return REGISTER_ROF_ON_INT_MAX;
case REGISTER_ROF_ON_FRAC: return REGISTER_ROF_ON_FRAC_MAX;
case REGISTER_ROF_OFF_INT: return REGISTER_ROF_OFF_INT_MAX;
case REGISTER_ROF_OFF_FRAC: return REGISTER_ROF_OFF_FRAC_MAX;
default:
DEBUG_PRINT("ERROR: getMaxRegisterValue(): unrecognized register: ");
DEBUG_PRINTLN(regNum);
@@ -218,7 +235,6 @@ float convertROFValueOld(byte ROF) {
}

float convertROFValue(byte rofInt, byte rofFrac) {

if( rofInt > 1 ) {
float rof = rofInt;

38 LED.ino
@@ -54,21 +54,25 @@ void ledOff() {
}


void setLEDRegisterColor(int regNum) {
void setLEDRegisterColor(int regNum, byte colorNum) {
byte brightness = 25;
switch( regNum ) {
case REGISTER_DEBOUNCE: ledColor(LED_GREEN, brightness); break;
case REGISTER_DWELL: ledColor(LED_PURPLE, brightness); break;
case REGISTER_LOADER_DELAY: ledColor(LED_YELLOW, brightness); break;
case REGISTER_MECH_DEBOUNCE: ledColor(LED_BLUE, brightness); break;
case REGISTER_FSDO_DWELL: ledColor(LED_RED, brightness); break;
case REGISTER_FIRE_MODE: ledColor(LED_WHITE, brightness); break;
case REGISTER_ROF_ON_INT: ledColor(LED_TEAL, brightness); break;
case REGISTER_ROF_ON_FRAC: ledColor(LED_ORANGE, brightness); break;
case REGISTER_ROF_OFF_INT: ledColor(LED_PINK, brightness); break;
case REGISTER_ROF_OFF_FRAC: ledColor(LED_LIGHTBLUE, brightness); break;
case REGISTER_DEBOUNCE: ledColor(colorNum == 1 ? REGISTER_1_COLOR_1 : REGISTER_1_COLOR_2, brightness); break;
case REGISTER_DWELL: ledColor(colorNum == 1 ? REGISTER_2_COLOR_1 : REGISTER_2_COLOR_2, brightness); break;
case REGISTER_LOADER_DELAY: ledColor(colorNum == 1 ? REGISTER_3_COLOR_1 : REGISTER_3_COLOR_2, brightness); break;
case REGISTER_MECH_DEBOUNCE: ledColor(colorNum == 1 ? REGISTER_4_COLOR_1 : REGISTER_4_COLOR_2, brightness); break;
case REGISTER_FSDO_DWELL: ledColor(colorNum == 1 ? REGISTER_5_COLOR_1 : REGISTER_5_COLOR_2, brightness); break;
case REGISTER_FIRE_MODE: ledColor(colorNum == 1 ? REGISTER_6_COLOR_1 : REGISTER_6_COLOR_2, brightness); break;
case REGISTER_ROF_ON_INT: ledColor(colorNum == 1 ? REGISTER_7_COLOR_1 : REGISTER_7_COLOR_2, brightness); break;
case REGISTER_ROF_ON_FRAC: ledColor(colorNum == 1 ? REGISTER_8_COLOR_1 : REGISTER_8_COLOR_2, brightness); break;
case REGISTER_CLOSED_DWELL: ledColor(colorNum == 1 ? REGISTER_9_COLOR_1 : REGISTER_9_COLOR_2, brightness); break;
case REGISTER_CLOSED_EYE_DELAY: ledColor(colorNum == 1 ? REGISTER_10_COLOR_1 : REGISTER_10_COLOR_2, brightness); break;
case REGISTER_CLOSED_BOLT_DELAY: ledColor(colorNum == 1 ? REGISTER_11_COLOR_1 : REGISTER_11_COLOR_2, brightness); break;

case REGISTER_ROF_OFF_INT: ledColor(colorNum == 1 ? REGISTER_12_COLOR_1 : REGISTER_12_COLOR_2, brightness); break;
case REGISTER_ROF_OFF_FRAC: ledColor(colorNum == 1 ? REGISTER_13_COLOR_1 : REGISTER_13_COLOR_2, brightness); break;

default: ledColor(LED_WHITE, brightness);
default: ledColor(LED_WHITE, brightness);
}
}

@@ -101,6 +105,16 @@ void powerOnLEDBurst(byte mode) {
}
}

void resetProgrammingLEDBurst() {
for(int c = 0; c < 10; c++ ) {
if( c % 2 ) ledColor(LED_PURPLE, LDB);
else ledColor(LED_ORANGE, LDB);
delay(50);
ledOff();
delay(50);
}
}

void operatingLEDBlink() {
byte eyeCheck;
bool WaitingForTriggerInput = (TRIGGER_STATE_WAITING == TriggerState);
@@ -29,11 +29,33 @@ void programmingMode() {
// initial setup for programming mode
if( Prog_WaitForTriggerRelease ) {
TriggerState = getTriggerState();
unsigned long now = millis();

if( TRIGGER_STATE_RELEASED == TriggerState || TRIGGER_STATE_WAITING == TriggerState ) {
if( now >= (Prog_TriggerDownStart + PROG_RESET_HOLD_TIME) ) {
resetProgrammingToDefault();
Prog_TriggerDownStart = 0;
}

Prog_WaitForTriggerRelease = false;
DEBUG_PRINTLN("Trigger released, Entering programming mode...");
} else {
if( now >= (Prog_TriggerDownStart + PROG_RESET_HOLD_TIME) ) {
if( Prog_ResetWarningBlinkMS <= (now - PROG_RESET_WARNING_BLINK_TIME) ) {
if( Prog_ResetWarningLastState ) {
ledColor(LED_RED, LDB);
Prog_ResetWarningLastState = 0;
} else {
ledOff();
Prog_ResetWarningLastState = 1;
}

Prog_ResetWarningBlinkMS = now;
}
}
}



Prog_Mode = PROG_MODE_MENU;
Prog_TriggerDownStart = 0;
@@ -56,12 +78,10 @@ void programmingMode() {
if( PROG_MODE_MENU == Prog_Mode ) {
// only do this once
if( !Prog_InitialLED ) {
setLEDRegisterColor(Prog_CurrentRegister);
setLEDRegisterColor(Prog_CurrentRegister, 1);
Prog_InitialLED = true;
}

//DEBUG_PRINTLN("Main Programming Menu");


// NOTE: change this code to note when a NEW pull started (after the pull that turned on programming mode)
// this will make it more like Tadao

@@ -95,12 +115,14 @@ void programmingMode() {
if( pullLength < 1000 ) {
// move to next register
Prog_CurrentRegister++;
if( Prog_CurrentRegister >= REGISTER_COUNT ) Prog_CurrentRegister = REGISTER_DEBOUNCE;
if( Prog_CurrentRegister >= REGISTER_COUNT ) Prog_CurrentRegister = FIRST_REGISTER;

// short blink
ledOff();
delay(250);
setLEDRegisterColor(Prog_CurrentRegister);
setLEDRegisterColor(Prog_CurrentRegister, 1);
delay(100);
setLEDRegisterColor(Prog_CurrentRegister, 2);

DEBUG_PRINT("Changed to register ");DEBUG_PRINTLN(Prog_CurrentRegister);
} else {
@@ -111,7 +133,14 @@ void programmingMode() {
}
else
{
// nothing here
// still in the main menu, no input
// alternate led colors
unsigned long now = millis();
if( Prog_LastLEDBlinkMS <= (now - 200) ) {
Prog_LastLEDBlinkColor = (Prog_LastLEDBlinkColor == 2 ? 1 : 2);
setLEDRegisterColor(Prog_CurrentRegister, Prog_LastLEDBlinkColor);
Prog_LastLEDBlinkMS = now;
}
}

} else {
@@ -127,7 +156,7 @@ void programmingMode() {
// read in current value
byte registerValue = EEPROM.read(Prog_CurrentRegister);

// NOTE: temp cheat since some unset registers read 255
// NOTE: limit value just in case, since some unset registers read 255
if( registerValue > 100 ) registerValue = 10;

DEBUG_PRINT("Register ");
@@ -136,12 +165,13 @@ void programmingMode() {
DEBUG_PRINTLN(registerValue);

// output current value to user
for(int i = 0; i < registerValue; i++ ) {
progOutputRegisterValue(registerValue, Prog_CurrentRegister);
/*for(int i = 0; i < registerValue; i++ ) {
ledOff();
delay(200);
setLEDRegisterColor(Prog_CurrentRegister);
delay(200);
}
}*/

ledOff();

@@ -182,7 +212,9 @@ void programmingMode() {
progOutputRegisterValue(newValue, Prog_CurrentRegister);
} else {
// blink once
setLEDRegisterColor(Prog_CurrentRegister);
setLEDRegisterColor(Prog_CurrentRegister, 1);
delay(100);
setLEDRegisterColor(Prog_CurrentRegister, 2);
delay(250);
ledOff();
}
@@ -212,8 +244,7 @@ void programmingMode() {
} else {
// save
registerValue = newValue;
EEPROM.write(Prog_CurrentRegister, registerValue);
DEBUG_PRINT("Set new value for register "); DEBUG_PRINT(Prog_CurrentRegister); DEBUG_PRINT(" to "); DEBUG_PRINTLN(registerValue);
setRegister(Prog_CurrentRegister, registerValue);
}

// Note: this should be a #define item in config.h
@@ -229,7 +260,9 @@ void programmingMode() {
delay(500);

// reset LED color
setLEDRegisterColor(Prog_CurrentRegister);
setLEDRegisterColor(Prog_CurrentRegister, 1);
delay(100);
setLEDRegisterColor(Prog_CurrentRegister, 2);
}

// testing, reset to main
@@ -242,8 +275,37 @@ void programmingMode() {
void progOutputRegisterValue(byte value, int registerNum) {
for(int i = 0; i < value; i++ ) {
ledOff();
delay(200);
setLEDRegisterColor(registerNum);
delay(200);
delay(100);
setLEDRegisterColor(registerNum, 1);
delay(100);
//setLEDRegisterColor(registerNum, 2);
delay(100);
}
}

void setRegister(byte reg, byte val) {
EEPROM.write(reg, val);
DEBUG_PRINT("Set new value for register "); DEBUG_PRINT(reg); DEBUG_PRINT(" to "); DEBUG_PRINTLN(val);
}

void resetProgrammingToDefault() {
setRegister(REGISTER_VERSION, PROGRAM_VERSION);

setRegister(REGISTER_DEBOUNCE, DEFAULT_DEBOUNCE);
setRegister(REGISTER_DWELL, DEFAULT_DWELL);
setRegister(REGISTER_LOADER_DELAY, DEFAULT_LOADER_DELAY);
setRegister(REGISTER_MECH_DEBOUNCE, DEFAULT_MECH_DEBOUNCE);
setRegister(REGISTER_FSDO_DWELL, DEFAULT_FSDO_DWELL);
setRegister(REGISTER_FIRE_MODE, DEFAULT_FIRE_MODE);
setRegister(REGISTER_ROF_ON_INT, DEFAULT_ROF_EYES_ON_INT);
setRegister(REGISTER_ROF_ON_FRAC, DEFAULT_ROF_EYES_ON_INT);
setRegister(REGISTER_CLOSED_DWELL, DEFAULT_CLOSED_DWELL);
setRegister(REGISTER_CLOSED_EYE_DELAY, DEFAULT_CLOSED_EYE_DELAY);
setRegister(REGISTER_CLOSED_BOLT_DELAY, DEFAULT_CLOSED_BOLT_DELAY);

setRegister(REGISTER_ROF_OFF_INT, DEFAULT_ROF_EYES_OFF_INT);
setRegister(REGISTER_ROF_OFF_FRAC, DEFAULT_ROF_EYES_OFF_FRAC);

resetProgrammingLEDBurst();
DEBUG_PRINTLN("Programming registers reset");
}
@@ -147,15 +147,32 @@ v0.8 - Enabled ROF eyes off programming
- Fixed code that updates LED color to indicate eye state
- Added ability to configure whether LED blinks or not in firing mode
- Split up firingMode() code into sub-units

- Board reset (hold trigger down to get into programming mode and keep holding it
until light starts flashing red, then release to reset board)
- Change register 0 to store code version
- Reset all registers to default values if code version is old
- Added programming registers for closed bolt mode
- Added LED alternating/blinking color support for programming mode registers

TODO:

General:

+ Weird bug in programming mode where it skips to the next register too quickly
+ Shot queueing (allowed to have one shot queued)
+ Debounce trigger release
+ Dual solenoid support (closed bolt mode)
+ Fix operationalLEDBlink() so that it doesn't delay when eyes are off/blocked, or
there is no ball in the breech
+ Fix ramping code to go by shots fired timing, not trigger pull timing
(you could have pulls with the eyes off that initiate ramp and it will fire in
ramp when a ball lands in the breech)
+ Add event hooks to code (eye state change, trigger state change, shot firing, etc.)
+ Move things like LED changes into these hooks
+ Eventually these will also be used to update the LCD/OLED as well
+ Dual solenoid support (closed bolt mode)
+ OLED/LCD display support
+ Stats collection
+ Speaker + audio output support
+ Wrap all global var access in macros so we can switch between wrapper functions
/ direct access easily
+ Add testing mode for debounce code that includes a register to change debounce
@@ -169,7 +186,6 @@ General:
+ Implement comment-based documentation generation, like doxygen

Not sure about:
+ shot queueing
+ auto shut off (may not be possible with boards using an on/off switch)
+ FSDO reset time
+ Support for two pin multi color led like on the WAS Viking board

0 comments on commit 6816679

Please sign in to comment.
You can’t perform that action at this time.