
#include "buttons.h"	
#include <stm32f10x.h>



int B1Pressed (void) {
  static char KeyCount1 = 0, KeyPressed1 = 1;

  if (KeyPressed1) {
    if (!((GPIOC->IDR & B1) == 0 )) {             // Check if S2 is not pressed
      if (KeyCount1 < UNBOUNCE_CNT) KeyCount1++;
      else {
        KeyPressed1 = 0;
        KeyCount1 = 0;    
      }
    }
  }
  else {
    if (((GPIOC->IDR & B1) == 0 ))  {             // Check if S2 is pressed
      if (KeyCount1 < UNBOUNCE_CNT) KeyCount1++;
      else {
        KeyPressed1 = 1;
        KeyCount1 = 0;
		return (1);
      }
    }
  }
  return (0);
}

int B2Pressed (void) {
  static char KeyCount2 = 0, KeyPressed2 = 1;

  if (KeyPressed2) {
    if (!((GPIOC->IDR & B2) == 0 )) {             // Check if S2 is not pressed
      if (KeyCount2 < UNBOUNCE_CNT) KeyCount2++;
      else {
        KeyPressed2 = 0;
        KeyCount2 = 0;    
      }
    }
  }
  else {
    if (((GPIOC->IDR & B2) == 0 ))  {             // Check if S2 is pressed
      if (KeyCount2 < UNBOUNCE_CNT) KeyCount2++;
      else {
        KeyPressed2 = 1;
        KeyCount2 = 0;
		return (1);
      }
    }
  }
  return (0);
}

int B3Pressed (void) {
  static char KeyCount3 = 0, KeyPressed3 = 1;

  if (KeyPressed3) {
    if (!((GPIOC->IDR & B3) == 0 )) {             // Check if S2 is not pressed
      if (KeyCount3 < UNBOUNCE_CNT) KeyCount3++;
      else {
        KeyPressed3 = 0;
        KeyCount3 = 0;    
      }
    }
  }
  else {
    if (((GPIOC->IDR & B3) == 0 ))  {             // Check if S2 is pressed
      if (KeyCount3 < UNBOUNCE_CNT) KeyCount3++;
      else {
        KeyPressed3 = 1;
        KeyCount3 = 0;
		return (1);
      }
    }
  }
  return (0);
}

int B4Pressed (void) {
  static char KeyCount4 = 0, KeyPressed4 = 1;

  if (KeyPressed4) {
    if (!((GPIOC->IDR & B4) == 0 )) {             // Check if S2 is not pressed
      if (KeyCount4 < UNBOUNCE_CNT) KeyCount4++;
      else {
        KeyPressed4 = 0;
        KeyCount4 = 0;    
      }
    }
  }
  else {
    if (((GPIOC->IDR & B4) == 0 ))  {             // Check if S2 is pressed
      if (KeyCount4 < UNBOUNCE_CNT) KeyCount4++;
      else {
        KeyPressed4 = 1;
        KeyCount4 = 0;
		return (1);
      }
    }
  }
  return (0);
}
