Пример #1
0
void check_for_keypresses(){

  if (debounce_just_pressed(hours_debounce,hours_switch_raw)){
    inc_hours();
    inc_metric_sw_hours();
  } else if (debounce_held_down(hours_debounce,hours_switch_raw)) {
    silly_hour_display = !silly_hour_display;
    eeprom_write_uint32(silly_hour_display,EEPROM_ADDR_SILLY_HOUR_DISPLAY);
    trigger_save_eeprom();

    // Be user friendly and undo the initial increment.
    dec_hours();
  }

  if (debounce_just_pressed(mins_debounce,mins_switch_raw)){
    inc_mins();
    inc_metric_sw_mins();
  }

  if (debounce_just_pressed(secs_debounce,secs_switch_raw)){
    clear_secs();
    inc_metric_sw_secs();
  }

  debounce_add_sample(hours_debounce,hours_switch_raw);
  debounce_add_sample(mins_debounce,mins_switch_raw);
  debounce_add_sample(secs_debounce,secs_switch_raw);
}
Пример #2
0
void save_track(track* my_track) {
	eeprom_write_uint32(0x04, my_track->sectors);	
}
Пример #3
0
void init_user(){
  uint8_t i;

  init_display();

  TRISBbits.TRISB2 = 1;

  // SDCC is missing the TRISA7 bit in the define...
#if 0
  TRISAbits.TRISA0 = 1;
  TRISAbits.TRISA6 = 1;
  TRISAbits.TRISA7 = 1;
#else
  TRISA = TRISA | b(11010001);
#endif

  // Setup pwm and adc for the led brightness control
  ADCON0 = b(00000001);
  ADCON1 = b(01111110);
  ADCON2 = b(00000000);

  CCP1CON = b(00001100);
  PR2 = 0xFF;
  T2CON = b(00000100);
  CCPR1L = 0x00;

  debounce_init(hours_debounce,hours_switch_raw);
  debounce_init(mins_debounce,mins_switch_raw);
  debounce_init(secs_debounce,secs_switch_raw);

  if (!hours_switch_raw && !mins_switch_raw && secs_switch_raw){
    mode = fast_clock;
  } else if (hours_switch_raw && !mins_switch_raw && !secs_switch_raw){
    mode = slow_clock;
  } else if (!hours_switch_raw && mins_switch_raw && !secs_switch_raw){
    // Oooh! Metrics display mode! Don't see that very often...
    inc_metric_meta();

    // Basically just cycle through the bytes in the eeprom and display them on
    // screen forever.

    i = 0;
    while (1){
      display_digits(
                     i / 16,i % 16,
                     CHAR_BLANK,CHAR_BLANK,
                     (((uint8_t *)(&eeprom_data))[i] / 16),
                      ((uint8_t *)(&eeprom_data))[i] % 16);

      delay10tcy(1);

      if (debounce_just_pressed(hours_debounce,hours_switch_raw)){
        i++;
        if (i >= sizeof(eeprom_data))
          i = 0;
      }
      if (debounce_just_pressed(secs_debounce,secs_switch_raw)){
        i--;
        if (i >= sizeof(eeprom_data))
          i = sizeof(eeprom_data) - 1;
      }

      debounce_add_sample(hours_debounce,hours_switch_raw);
      debounce_add_sample(secs_debounce,secs_switch_raw);
    }

  } else {
    mode = none_chosen;
  }

  if (mode == none_chosen){
    mode = eeprom_read_uint32(EEPROM_ADDR_MODE);  
  } else {
    eeprom_write_uint32(mode,EEPROM_ADDR_MODE);
    trigger_save_eeprom();
  }

  silly_hour_display = eeprom_read_uint32(EEPROM_ADDR_SILLY_HOUR_DISPLAY);
}