Exemplo n.º 1
0
int main(void)
{
	
	serial_initialise();

	button_t button_1 = debounce_init("PB0");
	button_t button_2 = debounce_init("PB2");
	
	button_auto_acknowledge(button_2);
	
	sei();

	serial_send_data("Off we go\r\n");
	
    while (1) 
    {

		if(button_check(button_1) == BUTTON_PRESS_SHORT) {
			serial_send_data("Button 1 short");
			button_acknowledge(button_1);
		}

		if(button_check(button_1) == BUTTON_PRESS_LONG) {
			serial_send_data("Button 1 long");
			button_acknowledge(button_1);
		}
		
		switch (button_check(button_2)) {
			case BUTTON_PRESS_SHORT:	
				serial_send_data("Button 2 short");
				break;

			case BUTTON_PRESS_LONG:
				serial_send_data("Button 2 long");
				break;
		}
		
		_delay_ms(200);

		serial_send_data("Canary\r\n");

 }
}
void matrix_init(void) {

  custom_matrix_init();

  // initialize matrix state: all keys off
  for (uint8_t i=0; i < MATRIX_ROWS; i++) {
    raw_matrix[i] = 0;
    matrix[i] = 0;
  }

  debounce_init(MATRIX_ROWS);

  matrix_init_quantum();
}
Exemplo n.º 3
0
void matrix_init(void) {

    // initialize row and col
#if (DIODE_DIRECTION == COL2ROW)
    unselect_rows();
    init_cols();
#elif (DIODE_DIRECTION == ROW2COL)
    unselect_cols();
    init_rows();
#endif

    // initialize matrix state: all keys off
    for (uint8_t i=0; i < MATRIX_ROWS; i++) {
        raw_matrix[i] = 0;
        matrix[i] = 0;
    }
    debounce_init(MATRIX_ROWS);

    matrix_init_quantum();
}
Exemplo n.º 4
0
void matrix_init(void) {
  debug_enable = true;
  debug_matrix = true;
  debug_mouse  = true;

  // Set pinout for right half if pinout for that half is defined
  if (!isLeftHand) {
#ifdef MATRIX_ROW_PINS_RIGHT
    const uint8_t row_pins_right[MATRIX_ROWS] = MATRIX_ROW_PINS_RIGHT;
    for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
      row_pins[i] = row_pins_right[i];
    }
#endif
#ifdef MATRIX_COL_PINS_RIGHT
    const uint8_t col_pins_right[MATRIX_COLS] = MATRIX_COL_PINS_RIGHT;
    for (uint8_t i = 0; i < MATRIX_COLS; i++) {
      col_pins[i] = col_pins_right[i];
    }
#endif
  }

  thisHand = isLeftHand ? 0 : (ROWS_PER_HAND);
  thatHand = ROWS_PER_HAND - thisHand;

  // initialize key pins
  init_pins();

  // initialize matrix state: all keys off
  for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
    matrix[i] = 0;
  }

  debounce_init(ROWS_PER_HAND);

  matrix_init_quantum();
}
Exemplo n.º 5
0
/**************************************
* Miscellaneous periodic routines
***************************************/
void task_periodic()
{
  const static WORD ledgal[2][3]={G1_LED1,G3_LED1,G5_LED1,G1_LED2,G3_LED2,G5_LED2};
  BYTE i, lastmode=0, newmode=0;
  WORD second=0, lastcredit=-1, crSecs=0, blinktimer=0;
  BYTE blink;
  DEBOUNCE debmode;
  MCX_MAILBOX mbox_outp;
  DEVMSG_OUTP outp;

  outp.devtype = DEV_OUTP;
  mbox_outp.message = &outp;
  debounce_init(&debmode, 0, 3);      /* init debounce structure  */

  mcx_timer_start(MYSELF,SEMA_periodic,-TM_PERIODIC);
  while ( FOREVER )
    {
    mcx_sema_wait(SEMA_periodic);

    /*************************************
    * Accumilate gallon count from slave *
    **************************************/
    if (gMaster && gSlaveGalCount)
      {
      sei();
      gGallonCount  +=  gSlaveGalCount;   /* Add to Total gallon count */
      gROgalcnt     +=  gSlaveGalCount;   /* Add to RO gallon count    */
      gSlaveGalCount = 0;
      cli();
      }

    /*************************
    * read mode switch
    **************************/
    newmode = debounce(&debmode,!(PORTE&MODESW));
    /* newmode -- True if pressed, FALSE otherwise */
    if (lastmode!=newmode )
      {
      if (newmode)
        {
        gServiceTimeout = 0;
        keypadchar = KEY_MODE;
        mcx_sema_signal(SEMA_keypad);
        }
      lastmode = newmode;
      }


    /****************************************
    * Blink or turn on water pouring lights *
    *****************************************/
    if ((blinktimer += TM_PERIODIC) > TM_800ms)
      blinktimer = 0;
    blink = blinktimer<TM_400ms;
    outp.ctrl = MASK;
    outp.mask = G1_LED1 | G3_LED1 | G5_LED1 | G1_LED2 | G3_LED2| G5_LED2;
    outp.select = 0;
    if (!gServiceMode)
    {
      for (i=0; i<2; i++)
      {
        // both tasks active
        if ((gVendTaskActive[0]) && (gVendTaskActive[1]))
          outp.select = ledgal[0][gGalSelect[0]] | ledgal[1][gGalSelect[1]];         // turn on both sides
        // if one task is active
        else if (gVendTaskActive[i])
        {
          outp.select = ledgal[i][gGalSelect[i]];                                    // turn on that side
          if (gCredit >= gPrice[GAL1] && (!gVendFailTimer[!i]))                      // blink other if not SO
            outp.select |= (blink) ? ledgal[!i][GAL1] : 0;
          if (gCredit >= gPrice[GAL3] && (!gVendFailTimer[!i]))                      // blink other if not SO
            outp.select |= (blink) ? ledgal[!i][GAL3] : 0;
          if (gCredit >= gPrice[GAL5] && (!gVendFailTimer[!i]))                      // blink other if not SO
            outp.select |= (blink) ? ledgal[!i][GAL5] : 0;
        }
        // if both tasks aren't active
        else if (!gVendTaskActive[0] && !gVendTaskActive[1] && !gVendFailTimer[i])   // not SO
        {
          if (gCredit >= gPrice[GAL1])   // blink 1 gallons
            outp.select |= (blink) ? ledgal[i][GAL1] : 0;
          if (gCredit >= gPrice[GAL3])   // blink 3 gallons  Version 1.24
            outp.select |= (blink) ? ledgal[i][GAL3] : 0;
          if (gCredit >= gPrice[GAL5])   // blink 5 gallons
            outp.select |= (blink) ? ledgal[i][GAL5] : 0;
        }
      }
    }
    mcx_mailbox_send(TASK_dev,0,&mbox_outp);
    /********************
    * Do countup timers *
    *********************/
    gServiceTimeout += TM_PERIODIC;
    gVendTimer[0] += TM_PERIODIC;
    gVendTimer[1] += TM_PERIODIC;
    second += TM_PERIODIC;

    if (!gCredit)
      gFirstTry = FALSE;

    /*******************
    * Do second timers *
    ********************/
    if (second>=TM_1sec)
      {
      second = 0;

      /**************************
      * Update countup counters *
      ***************************/
      if (gNoPulseTimer[0] < 5)
        gNoPulseTimer[0]++;
      if (gNoPulseTimer[1] < 5)
        gNoPulseTimer[1]++;
      gROpostTimer++;
      if (gROtimerOff>=(4*60*60))       /* Four hours */
      {
        gROstate = ON;
        gROTimer = 0;
        gROtimerOff = 0;
      }
      else if (gROstate==ON)
      {
        gROtimerOff = 0;
        gROTimer++;
      }
      else
        gROtimerOff++;

      gPourTimer[0]++;
      gPourTimer[1]++;

      if (gVendTaskActive[0] || gVendTaskActive[1])
        gReturnTime = 0;
      else
        gReturnTime++;
      /**************************
      * Update countdown timers *
      ***************************/
      if (gVendFailTimer[0])
        --gVendFailTimer[0];
      if (gVendFailTimer[1])
        --gVendFailTimer[1];

      /************************************
      * Zero untouched credit over 5 mins *
      *************************************/
      crSecs++;
      if (gCredit != lastcredit)
        crSecs = 0;
      else if (crSecs > FiveMinutes)
        crSecs = gCredit = coin.tokenused = FALSE;
      lastcredit = gCredit;


      }
    }
  }
Exemplo n.º 6
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);
}