/*
 * Computer Switchboard
 * 
 * Because interfacing with computers should be fun
 * and a keyboard is not enough.
 * 
 * Let's turn a computer into an airplane (interface wise).
 * 
 * 
 * 
 * MINIMAL: 
 * I only need the button to shutdown the computer. No rotary or 7seg.
 */

 //todo: debounce, see neotimer

//makes serial slower so it can be read
#define DEBUGMODE 0

#include <avr/io.h>
#include <avr/interrupt.h>

 


//switch

// digital pin 9 has a pushbutton attached to it. Give it a name:
int pushButton = 9;




// Example showing use of the MD_KeySwitch library
// 
// Momentary switch 
// 
// Prints the switch value on the Serial Monitor
// Allows setting of options to see theior effect (see setup())
//
#include <MD_KeySwitch.h>

// This is just an average debounce -steak
// what i need is a way to actually, not register if I don't pick up the depressed button
// but good enough for now

 
const uint8_t SWITCH_PIN = 9;       // switch connected to this pin
const uint8_t SWITCH_ACTIVE = LOW;  // digital signal when switch is pressed 'on'

MD_KeySwitch S(SWITCH_PIN, SWITCH_ACTIVE);


 
void setup() {
  // initialize I/O pins

  Serial.begin(9600);
  Serial.println("GnuxSwitcher");

  pinMode(pushButton, INPUT_PULLUP);
  pinMode(LED_BUILTIN, OUTPUT);
  
  S.begin();
  //S.enableDoublePress(true);
  //S.enableLongPress(true);
  /*S.enableRepeat(true);
  S.enableRepeatResult(true);*/

  
}

void loop() {






 



//BUTTONS

 /* int resultb = 0;
  resultb = PINB;
  delay(100);
  if (resultb == 0 ){
                      
                       
    decPt = 1;

    Serial.print("User Pressed button: ");
    Serial.println(segdisp);

  }
  else{
    decPt = 0;
  }
  */
  // too fast, print serial when checking switch only
  // Serial.println(resultb,BIN); // noisy, but reads 0 when low.

switch(S.read())
  {
    case MD_KeySwitch::KS_NULL:       /* Serial.println("NULL"); */   break;
    
    case MD_KeySwitch::KS_PRESS:      
      //Serial.println("\nSINGLE PRESS"); 
      Serial.println("Initiate the Shutdown Procedure Immediately");
      digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
      delay(1000);                       // wait for a second
      digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW 
      break;

    /*
    case MD_KeySwitch::KS_DPRESS:     Serial.print("\nDOUBLE PRESS"); 
    break;*/
   
    //case MD_KeySwitch::KS_LONGPRESS:  Serial.print("\nLONG PRESS");   
    //break; //this doesn't seem to work at all. - steak
   /*
    case MD_KeySwitch::KS_RPTPRESS:   Serial.print("\nREPEAT PRESS");
    break;
    */
    default:                          Serial.print("\nUNKNOWN");      
    break;
  }


  
} 










