/*********************************************************************
 * FileName:        switches.c
 * Dependencies:    See INCLUDES section below
 * Processor:       PIC18
 * Compiler:        C18 2.30.01+
 * Company:         sprut
 * Copyright:       2012 Joerg Bredendiek (sprut)
 *
 *
 ********************************************************************/


/** I N C L U D E S **********************************************************/
#include <p18cxxx.h>
#include "GenericTypeDefs.h"
#include "HardwareProfile.h"             // I/O pin mapping
#include "delays.h"
#include "capture_rc.h"
#include "axis.h"
#include "buttons.h"
#include "switches.h"



/** V A R I A B L E S ********************************************************/
#pragma udata
unsigned char		rcMarke;
unsigned char		rcInvers;


/** D E C L A R A T I O N S **************************************************/
#pragma code

void	Switches_Init(void)
{
	// RB0..7 sind die Tastereingaenge  > input  und pull up
    TRISB = 0xFF;
	LATB  = 0;
	INTCON2bits.RBPU = 0;	// pull up

	rcMarke  = rcFutaba;
	rcInvers = 0;
}	//Switches_Init


unsigned char ModAxis(char index)
{
	unsigned char Achse = Axis[index];
	switch (index)
	{
		case 0: if (rcInvers & 0x01) Achse = 255 - Achse; break;
		case 1: if (rcInvers & 0x02) Achse = 255 - Achse; break;
		case 2: if (rcInvers & 0x04) Achse = 255 - Achse; break;
		case 3: if (rcInvers & 0x08) Achse = 255 - Achse; break;
	}
	return Achse;
}


void	UP_Switches(void)
{
	rcMarke  = (PORTB ^ 0xFF) & 0x03;
	rcInvers = (PORTB ^ 0xFF) >> 4;
}	//UP_Switches



/** EOF ************************************************************/