Skip to content

Commit

Permalink
added led feedback for long press joystick switch
Browse files Browse the repository at this point in the history
  • Loading branch information
djtulan committed Mar 18, 2018
1 parent 4459203 commit 37435f6
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 9 deletions.
38 changes: 31 additions & 7 deletions src/led.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
/// @brief led
//=============================================================================
#include <avr/pgmspace.h>
#include <avr/wdt.h>
#include <util/delay.h>

#include "ioconfig.h"

Expand All @@ -32,12 +34,12 @@ const uint8_t FLASH_DATA[NUMBER_LED_STATES][7] PROGMEM = {
{0, 0, 0, 0, 0, 0, 0}, ///< ON
{2, 12, 0, 0, 0, 0, 0}, ///< F1
{2, 4, 2, 12, 0, 0, 0} ///< F2
//{2, 4, 2, 4, 2, 12, 0}
};

static LED_State led_state = LED_OFF;
static uint8_t led_flash_index = 0;
static uint8_t led_flash_timer = 0;
static uint8_t led_lock = 0;

static void led_set(uint8_t on) {
if (on) {
Expand Down Expand Up @@ -69,10 +71,6 @@ void led_switch(LED_State state) {
led_set(1);
break;

// case LED_BLINK3:
// led_set(1);
// break;

case NUMBER_LED_STATES:
break;
}
Expand All @@ -85,6 +83,7 @@ void led_setnextstate(void) {
LED_State s = led_get_state();

s ++;

if (s == NUMBER_LED_STATES)
s = LED_OFF;

Expand All @@ -95,10 +94,35 @@ LED_State led_get_state(void) {
return (led_state);
}

void led_quick_blink(uint8_t number) {
led_lock = 1;

led_set(0);
_delay_ms(200);
wdt_reset();

for (uint8_t i = 0; i < number; i++) {
led_set(1);
_delay_ms(50);

wdt_reset();

led_set(0);
_delay_ms(50);
}

_delay_ms(400);
wdt_reset();

led_lock = 0;

led_switch(led_state);
}

void led_poll(void) {

// if ON or OFF do nothing
if (led_state == LED_OFF || led_state == LED_ON)
if (led_state == LED_OFF || led_state == LED_ON || led_lock)
return;

// set timer
Expand All @@ -112,7 +136,7 @@ void led_poll(void) {
led_set(1);
}

// count down timer
// count down timer
} else {

led_flash_timer --;
Expand Down
9 changes: 7 additions & 2 deletions src/led.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
typedef enum {
LED_OFF, ///< LED is OFF
LED_ON, ///< LED is ON
LED_BLINK1, ///< LED blinks once
LED_BLINK2, ///< LED blinks twice
LED_BLINK1, ///< LED flashes once
LED_BLINK2, ///< LED flashes twice
// LED_BLINK3, ///< LED blinks tree times

NUMBER_LED_STATES
Expand Down Expand Up @@ -60,6 +60,11 @@ extern void led_setnextstate(void);
*/
extern LED_State led_get_state(void);

/**
* @brief quick flash
*/
extern void led_quick_blink(uint8_t number);

/**
* @brief poll led routines (for flashing)
* @note This function is called by timer interrupt routine
Expand Down
2 changes: 2 additions & 0 deletions src/nunchuk64.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ int main(void) {
switched_ports = (switched_ports == FALSE) ? TRUE : FALSE;

handle_paddle_enabled(switched_ports); // handle paddle disabled

led_quick_blink(switched_ports ? 2 : 1);
}

// ===================================
Expand Down

0 comments on commit 37435f6

Please sign in to comment.