buttonry.c File Reference

#include <avr/io.h>
#include <avr/interrupt.h>
#include <inttypes.h>
#include <stdio.h>
#include "buttonry.h"
#include "util.h"
#include "rtc.h"
#include "modes.h"
Include dependency graph for buttonry.c:

Defines

#define DDRBUTTONS   DDRC
#define PORTBUTTONS   PORTC
#define PINBUTTONS   PINC
#define BUTTON1   5
#define BUTTON2   4
#define set_blinkhandler(x)

Enumerations

enum  _setstates {
  SET_NONE = 0, SET_HOUR, SET_MINUTE, SET_SEC0,
  SET_YEAR, SET_MONTH, SET_DAY
}

Functions

void debounce (uint8_t port, uint8_t *state, void(*handler)(uint8_t))
 Catch button press and release moments, call handler.
void buttons_init ()
 Initialize ports and variables.
void set_voltage_dot ()
void button1_handler (uint8_t on)
 Handler for button 1: "SET".
void button2_handler (uint8_t on)
 Handler for button 2, "+".
uint8_t is_setting ()
void buttonry_tick ()

Variables

RTC_TIME rtc_time

Define Documentation

#define BUTTON1   5
#define BUTTON2   4
#define DDRBUTTONS   DDRC
#define PINBUTTONS   PINC
#define PORTBUTTONS   PORTC
#define set_blinkhandler (  ) 
Value:
{ cli();\
                              if (blinkhandler == NULL) {\
                                blinkhandler = x;\
                                skip = 1;\
                              }\
                              sei();\
                            }

Enumeration Type Documentation

enum _setstates
Enumerator:
SET_NONE 
SET_HOUR 
SET_MINUTE 
SET_SEC0 
SET_YEAR 
SET_MONTH 
SET_DAY 

00011                 {
00012     SET_NONE = 0,
00013     SET_HOUR,
00014     SET_MINUTE,
00015     SET_SEC0,
00016     SET_YEAR,
00017     SET_MONTH,
00018     SET_DAY,
00019 };


Function Documentation

void button1_handler ( uint8_t  on  ) 

Handler for button 1: "SET".

00070                                  {
00071     static uint8_t skip = 0;
00072     
00073     if (on) {
00074         blinkmode_set(blinkmode_get() | 0200);  // don't blink while button is being depressed
00075 
00076         if (skip > 0) {
00077             skip--;
00078             return;
00079         }
00080         
00081         switch (set_state) {
00082             case SET_NONE:
00083                 mode_next();
00084                 set_voltage_dot();
00085                 skip = 1;
00086                 break;
00087                 
00088             case SET_HOUR:
00089                 set_blinkhandler(button1_handler);
00090                 
00091                 rtc_time.hour = bcd_increment(rtc_time.hour);
00092 
00093                 if (rtc_time.hour == 0x24) rtc_time.hour = 0;
00094                 
00095                 rtc_xhour(rtc_time.hour);
00096                 
00097                 fadeto((get_display_value() & 0377) | (rtc_time.hour << 8));
00098                 break;
00099                 
00100             case SET_MINUTE:
00101                 set_blinkhandler(button1_handler);
00102                 
00103                 rtc_time.minute = bcd_increment(rtc_time.minute);
00104                 if (rtc_time.minute == 0x60) rtc_time.minute = 0;
00105                 rtc_xminute(rtc_time.minute);
00106                 
00107                 fadeto((get_display_value() & 0xff00) | rtc_time.minute);
00108                 break;
00109                 
00110             case SET_YEAR:
00111                 set_blinkhandler(button1_handler);
00112                 
00113                 rtc_time.year = bcd_increment(rtc_time.year);
00114                 rtc_xyear(rtc_time.year);
00115 
00116                 rtc_xdow(day_of_week(frombcd(rtc_time.year), frombcd(rtc_time.month), frombcd(rtc_time.day)));
00117 
00118                 fadeto(0x2000 + rtc_time.year);
00119                 break;     
00120                        
00121             case SET_MONTH:
00122                 set_blinkhandler(button1_handler);
00123 
00124                 rtc_time.month = bcd_increment(rtc_time.month);
00125                 if (rtc_time.month == 0x13) rtc_time.month = 1;                
00126                 rtc_xmonth(rtc_time.month);
00127 
00128                 rtc_xdow(day_of_week(frombcd(rtc_time.year), frombcd(rtc_time.month), frombcd(rtc_time.day)));
00129                 
00130                 fadeto(maketime(rtc_time.day, rtc_time.month));
00131                 break;
00132             
00133             case SET_DAY:
00134                 set_blinkhandler(button1_handler);
00135                 
00136                 rtc_time.day = bcd_increment(rtc_time.day);
00137                 if (rtc_time.day > days_in_month_bcd(rtc_time.year, rtc_time.month)) {
00138                     rtc_time.day = 1;
00139                 }
00140                 rtc_xday(rtc_time.day);
00141                 
00142                 rtc_xdow(day_of_week(frombcd(rtc_time.year), frombcd(rtc_time.month), frombcd(rtc_time.day)));
00143                 
00144                 fadeto(maketime(rtc_time.day, rtc_time.month));
00145                 break;
00146         }
00147     } else {
00148         blinkmode_set(blinkmode_get() & 0177);  // re-enable blinking
00149         cli(); blinkhandler = NULL; skip = 0; sei();
00150     }
00151 }

Here is the call graph for this function:

void button2_handler ( uint8_t  on  ) 

Handler for button 2, "+".

00154                                  {
00155     if (on) {
00156         switch (set_state) {
00157             case SET_NONE:
00158                 switch (mode_get()) {
00159                 case MMSS:
00160                     rtc_xseconds(0);
00161                     break;
00162                 case HHMM:
00163                     set_state = SET_HOUR;
00164                     blinkmode_set(BLINK_HH);
00165                     fade_set(FADE_OFF);
00166                     dotmode_set(DOT_ON);
00167                     
00168                     rtc_time.hour = rtc_xhour(-1);
00169                     rtc_time.minute = rtc_xminute(-1); 
00170                     fadeto(maketime(rtc_time.hour, rtc_time.minute));
00171                     break;
00172                 case VOLTAGE:
00173                     savingmode_next();
00174                     set_voltage_dot();
00175                     break;
00176                 default:
00177                     break;
00178                 }
00179                 break;
00180             case SET_HOUR:
00181                 set_state = SET_MINUTE;
00182                 blinkmode_set(BLINK_MM);
00183                 break;
00184             case SET_MINUTE:
00185                 set_state = SET_YEAR;
00186                 blinkmode_set(BLINK_ALL);
00187                 dotmode_set(DOT_OFF);
00188                 rtc_time.year = rtc_xyear(-1);
00189                 fadeto(0x2000 + rtc_time.year);
00190                 break;
00191             case SET_YEAR:
00192                 set_state = SET_MONTH;
00193                 blinkmode_set(BLINK_MM);
00194                 
00195                 rtc_time.month = rtc_xmonth(-1);
00196                 if (rtc_time.month == 0) rtc_time.month = 1;
00197                 
00198                 rtc_time.day   = rtc_xday(-1);
00199                 if (rtc_time.day == 0) rtc_time.day = 1;
00200                 
00201                 fadeto(maketime(rtc_time.day, rtc_time.month));
00202                 break;
00203             case SET_MONTH:
00204                 set_state = SET_DAY;
00205                 blinkmode_set(BLINK_HH);
00206                 break;
00207             case SET_DAY:
00208             default:
00209                 set_state = SET_NONE;
00210                 blinkmode_set(BLINK_NONE);
00211                 fade_set(FADE_SLOW);
00212                 dotmode_set(DOT_BLINK);
00213                 break;
00214         }
00215     } else {
00216         cli(); blinkhandler = NULL; sei();
00217     }
00218 }

Here is the call graph for this function:

void buttonry_tick (  ) 

00224                      {
00225     debounce(PINBUTTONS & _BV(BUTTON1), &button1_state, button1_handler);
00226     debounce(PINBUTTONS & _BV(BUTTON2), &button2_state, button2_handler);
00227 }

Here is the call graph for this function:

void buttons_init (  ) 

Initialize ports and variables.

00044                     {
00045     DDRBUTTONS &= ~BV2(BUTTON1,BUTTON2);
00046     PORTBUTTONS |= BV2(BUTTON1,BUTTON2);
00047     button1_state = button2_state = 0;
00048 }

void debounce ( uint8_t  port,
uint8_t *  state,
void(*)(uint8_t)  handler 
)

Catch button press and release moments, call handler.

00037                                                                       {
00038     if (*state && !port) handler(1);
00039     if (!*state && port) handler(0);
00040     *state = port;
00041 }

uint8_t is_setting (  ) 

00220                      {
00221     return set_state != SET_NONE;
00222 }

void set_voltage_dot (  ) 

00059                        {
00060     if (mode_get() == VOLTAGE) {
00061         if (savingmode_get() == SAVENIGHT) {
00062             dotmode_set(DOT_BLINK);
00063         } else {
00064             dotmode_set(DOT_OFF);
00065         }
00066     }
00067 }

Here is the call graph for this function:


Variable Documentation


Generated on Wed Jan 27 00:29:55 2010 for Patashnik by  doxygen 1.6.1