Commit f6a93131 authored by Michael Nelson's avatar Michael Nelson

wip

parent 6ab440dd
#include <avr/power.h>
#define MODE_OFF 0
#define DEBUG_WITH_BUILTIN_LED true
#define DEBUG_WITH_BUILTIN_LED false
// Foreground Modes
#define FG_MODE_BLINK_L 1
......@@ -14,14 +14,23 @@
#define BG_MODE_AUXILARY_LIGHTS 4
// Pins 2-6 are for itmes on the handlebars.
// Ethernet coloring plan:
// Brown - Ground
// Brown striped - Speaker
// Green - Left button
// Green striped - Right button
// Orange - Left button LED
// Orange striped - Right button LED
// Blue - Available
// Blue striped - Available
// Inputs
#define PIN_IN_LEFT_BUTTON 4
#define PIN_IN_RIGHT_BUTTON 5
// Outputs
#define PIN_OUT_LEFT_BUTTON_LED 3
#define PIN_OUT_RIGHT_BUTTON_LED 2
#define PIN_OUT_LEFT_BUTTON_LED 2
#define PIN_OUT_RIGHT_BUTTON_LED 3
#define PIN_OUT_SPEAKER 6
#define PIN_OUT_BLINKER_L 7
......@@ -36,6 +45,7 @@
int fg_mode = MODE_OFF;
int bg_mode = MODE_OFF;
int blinker_light_state;
int last_fg_mode = MODE_OFF;
// Just-released variables
bool left_just_released = false;
......@@ -51,7 +61,7 @@ int both_hold_time = 0;
void setup()
{
// Initialize a serial connection for reporting values to the host
Serial.begin(9600);
/* Serial.begin(9600); */
pinMode(PIN_IN_LEFT_BUTTON, INPUT_PULLUP);
pinMode(PIN_IN_RIGHT_BUTTON, INPUT_PULLUP);
......@@ -64,7 +74,7 @@ void setup()
/* clock_prescale_set(clock_div_2); */
Serial.println("Started.");
/* Serial.println("Started."); */
}
void blink_frame()
......@@ -77,8 +87,13 @@ void blink_frame()
blink_speaker_frame();
digitalWrite(fg_mode == FG_MODE_BLINK_R ? PIN_OUT_BLINKER_R : PIN_OUT_BLINKER_L, blinker_light_state ? LOW : HIGH);
digitalWrite(fg_mode == FG_MODE_BLINK_R ? PIN_OUT_LEFT_BUTTON_LED : PIN_OUT_RIGHT_BUTTON_LED, blinker_light_state ? LOW : HIGH);
// Actual light
digitalWrite(fg_mode == FG_MODE_BLINK_R ? PIN_OUT_BLINKER_R : PIN_OUT_BLINKER_L,
blinker_light_state ? LOW : HIGH);
// Indicator on button
digitalWrite(fg_mode == FG_MODE_BLINK_R ? PIN_OUT_LEFT_BUTTON_LED : PIN_OUT_RIGHT_BUTTON_LED,
blinker_light_state ? LOW : HIGH);
#if DEBUG_WITH_BUILTIN_LED
digitalWrite(LED_BUILTIN, blinker_light_state ? LOW : HIGH);
......@@ -174,28 +189,37 @@ void set_up_mode()
fg_mode = fg_mode == FG_MODE_BLINK_R ? MODE_OFF : FG_MODE_BLINK_R;
}
void reset_all()
{
cycle_time = 0;
#if DEBUG_WITH_BUILTIN_LED
digitalWrite(LED_BUILTIN, LOW);
#endif
digitalWrite(PIN_OUT_BLINKER_L, LOW);
digitalWrite(PIN_OUT_BLINKER_R, LOW);
digitalWrite(PIN_OUT_LEFT_BUTTON_LED, LOW);
digitalWrite(PIN_OUT_RIGHT_BUTTON_LED, LOW);
digitalWrite(PIN_OUT_WHITES, LOW);
}
void loop()
{
set_up_mode();
Serial.println(bg_mode);
/* Serial.println(cycle_time); */
/* Serial.println(fg_mode); */
if (fg_mode != last_fg_mode && fg_mode != MODE_OFF)
reset_all();
if (fg_mode == FG_MODE_BLINK_L || fg_mode == FG_MODE_BLINK_R)
blink_frame();
/* else if (fg_mode == HAZARDS_MODE) */
/* hazard_frame(); */
else
{
cycle_time = 0;
reset_all();
#if DEBUG_WITH_BUILTIN_LED
digitalWrite(LED_BUILTIN, LOW);
#endif
digitalWrite(PIN_OUT_BLINKER_L, LOW);
digitalWrite(PIN_OUT_BLINKER_R, LOW);
digitalWrite(PIN_OUT_LEFT_BUTTON_LED, LOW);
digitalWrite(PIN_OUT_RIGHT_BUTTON_LED, LOW);
digitalWrite(PIN_OUT_WHITES, LOW);
}
last_fg_mode = fg_mode;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment