/*********************************************************************
 * FileName:        buttons.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"



/** V A R I A B L E S ********************************************************/
#pragma udata
unsigned char		RC_Buttons0;
unsigned char		RC_Buttons1;
unsigned char		RC_Buttons2;

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

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

	RC_Buttons0 = 0;
	RC_Buttons1 = 0;
	RC_Buttons2 = 0;
}	//Button_Init



// die Tasten 1..8 werden durch Kanal5..8 gesteuert
// erste  Taste aktiv wenn <30%
// zweite Taste aktiv wenn >70%
// die Tasten 9..16 werden durch Tasten an PORTB gesteuert
// die Tasten 27..24 dienen momentan fuer Debug
void	UP_Button(void)
{
	// Taster aus Kanaelen
	RC_Buttons0 = 0;
	RC_Buttons1 = 0;
	RC_Buttons2 = 0;
	// Kanäle steuern Buttons
	switch (KanalZahl)
	{
	case 12:
		if (Axis[11] <  75) RC_Buttons1 |= 0b00000100;	// Bt 13
		if (Axis[11] > 180) RC_Buttons1 |= 0b00001000;	// Bt 14
	case 11:
		if (Axis[10] <  75) RC_Buttons1 |= 0b00000100;	// Bt 11
		if (Axis[10] > 180) RC_Buttons1 |= 0b00001000;	// Bt 12
	case 10:
		if (Axis[9]  <  75) RC_Buttons1 |= 0b00000001;	// Bt 9
		if (Axis[9]  > 180) RC_Buttons1 |= 0b00000010;	// Bt 10
	case 9:
		if (Axis[8]  <  75) RC_Buttons0 |= 0b01000000;	// Bt 7
		if (Axis[8]  > 180) RC_Buttons0 |= 0b10000000;	// Bt 8
	case 8:
		if (Axis[7] <  75) RC_Buttons0 |= 0b00010000;	// Bt 5
		if (Axis[7] > 180) RC_Buttons0 |= 0b00100000;	// Bt 6
	case 7:
		if (Axis[6] <  75) RC_Buttons0 |= 0b00000100;	// Bt 3
		if (Axis[6] > 180) RC_Buttons0 |= 0b00001000;	// Bt 4
	case 6:
		if (Axis[5] <  75) RC_Buttons0 |= 0b00000001;	// Bt 1
		if (Axis[5] > 180) RC_Buttons0 |= 0b00000010;	// Bt 2
		break;
	}
}	//UP_Button



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