//
//

// version 2 array of buttons, still using callback mecahnism
// I could not get the event methods to do anything useful

#include <Arduino.h>
#include "Button.h"

// button user data - here used just to get button number. perhaps the button handle coud, um, handle that directly
byte list[] = {0, 2, 3, 1};
// on which pins
gpio_num_t pin[] = {GPIO_NUM_35, GPIO_NUM_32, GPIO_NUM_33, GPIO_NUM_25, };

const byte NBUTTONS = sizeof list / sizeof *list;

Button *buttonArray[NBUTTONS];

char *text[] = {"ALPHA", "BRAVO", "CHARLIE", "DELTA", };

static void pressedAButton(void *button_handle, void *usr_data) {

  byte code = *(byte *) usr_data;

  Serial.print("Button went down. Code is ");
  Serial.print(code);
  Serial.print(" and it means ");
  Serial.println(text[code]);
}

void setup()
{
  Serial.begin(115200);

// make the buttons
  for (int ii = 0; ii < NBUTTONS; ii++)
    buttonArray[ii] = new Button(pin[ii], false);

// set the callback
  for (int ii = 0; ii < NBUTTONS; ii++)
    buttonArray[ii]->attachPressDownEventCb(&pressedAButton, list + ii);
}

void loop()
{
// look Ma, no code!
    delay(10);
}

/* version 1 - two buttons copy/paste/edit
#include <Arduino.h>
#include "Button.h"

static void onButtonPressDownCb(void *button_handle, void *usr_data) {
    Serial.print("Button pressed down  ");
    Serial.println(* (int *) usr_data);
}

int list[] = {0, 2, 4, 6, 8, 10, 12, 420, 16, 18, 20};

void setup()
{
    // put your setup code here, to run once:
    Serial.begin(115200);

    // initializing a button

    Button *btn1 = new Button(GPIO_NUM_35, false);

    btn1->attachPressDownEventCb(&onButtonPressDownCb, list + 7);


    Button *btn2 = new Button(GPIO_NUM_32, false);

    btn2->attachPressDownEventCb(&onButtonPressDownCb, list + 8);

}

void loop()
{
    delay(10);
}
*/
/* version 0 one button
#include <Arduino.h>
#include "Button.h"

static void onButtonPressDownCb(void *button_handle, void *usr_data) {
    Serial.print("Button pressed down  ");
    Serial.println(* (int *) usr_data);
}

int list[] = {0, 2, 4, 6, 8, 10, 12, 420, 16, 18, 20};

void setup()
{
    // put your setup code here, to run once:
    Serial.begin(115200);

    // initializing a button
    Button *btn = new Button(GPIO_NUM_35, false);

    btn->attachPressDownEventCb(&onButtonPressDownCb, list + 7);


}

void loop()
{
    delay(10);
}
*/