// GPIOHelper.h

#ifndef _GPIOHELPER_h
#define _GPIOHELPER_h

#if defined(ARDUINO) && ARDUINO >= 100
	#include "Arduino.h"
#else
	#include "WProgram.h"
#endif

#include <stdio.h>
#include <LinkedList.h>
#include <EventManager.h>
#include "BoardDefs.h"

extern int transponderId;

class GPIOHelper {
public:
	GPIOHelper(EventManager& evm) :_evm(evm) {};
	void Init();
	void Reset();
	void Check();
private:
	#define PULSE_ONE 500
	#define PULSE_MIN 100
	#define PULSE_MAX 1000

	#define DATA_BIT_LENGTH 9
	
	int LastSensorState;
	unsigned long SensorPulse;
	LinkedList<int> SensorData;
	EventManager& _evm;

	void ProcessBit(unsigned long pulseWidth);
	void PublishData(LinkedList<int>& data, int checksum);
	unsigned int Num_Ones_In_Buffer(LinkedList<int>& data);
	int ConvertBitArrayToInt(LinkedList<int>& arr);
	void PrintArray(LinkedList<int>& arr);
};
#endif