Doch.
RP6RobotBaseLib.c Zeile 247 - 335
 
	Code:
	/*****************************************************************************/
// HIGHT_Bumpers:
/**
 * Returns true if the the left Bumper is hit. 
 * This function turns off the LED connected to the port, reads the Bumper 
 * value and restores previous LED state afterwards!
 *
 * Example:
 *
 *        if(getBumperLeft())
 *            // do something
 */
uint8_t getHIGHTBumperLeft(void)
{ 
    PORTB &= ~SL5;
    DDRB &= ~SL5; 
    nop();
    uint8_t tmp = PINB & SL5;
    if(statusLEDs.LED5) { 
        DDRB |= SL5; 
        PORTB |= SL5; 
    }
    return tmp;
}
/**
 * Returns true if the the right Bumper is hit. 
 * This function turns off the LED connected to the port, reads the Bumper 
 * value and restores previous LED state afterwards!
 *
 * Example:
 *
 *        if(getBumperRight())
 *            // do something
 */
uint8_t getHIGHTBumperRight(void)
{
    PORTC &= ~SL2;
    DDRC &= ~SL2; 
    nop();
    uint8_t tmp = PINC & SL2;
    if(statusLEDs.LED2) { 
        DDRC |= SL2; 
        PORTC |= SL2; 
    }
    return tmp;
}
// -------------------------------
// HIGHT Bumpers State changed handler:
void HIGHT_BUMPERS_stateChanged_DUMMY(void){}
static void (*HIGHT_BUMPERS_stateChangedHandler)(void) = HIGHT_BUMPERS_stateChanged_DUMMY;
/**
 * Use this function to set the Bumpers state change handler. 
 * 
 */
void HIGHT_BUMPERS_setStateChangedHandler(void (*hightbumperHandler)(void)) 
{
    HIGHT_BUMPERS_stateChangedHandler = hightbumperHandler;
}
// -------------------------------
volatile uint8_t hight_bumper_timer;
uint8_t hight_bumper_left;
uint8_t hight_bumper_right;
/**
 * If you call this frequently out of the mainloop (or use task_RP6System which
 * calls this routine for you), the global bumper_left and bumper_right
 * variables are updated automatically every 50ms and can be used everywhere
 * in your program. It can also call an event handler routine, that you
 * need to register with BUMPERS_setStateChangedHandler before.
 */
void task_hight_Bumpers(void)
{
    if(hight_bumper_timer > 50) { // 50ms
        uint8_t hleft = getHIGHTBumperLeft();
        uint8_t hright = getHIGHTBumperRight();
        if(hight_bumper_left != hleft || hight_bumper_right != hright) {
            hight_bumper_left = hleft;
            hight_bumper_right = hright;
            HIGHT_BUMPERS_stateChangedHandler();
        }
        hight_bumper_timer = 0;
    }
}
 RP6RobotBaseLib.h 
	Code:
	/ HightBumpers
uint8_t gethightBumperLeft(void);
uint8_t gethightBumperRight(void);
extern uint8_t hight_bumper_left;
extern uint8_t hight_bumper_right;
#define ishightBumperLeft() (hight_bumper_left)
#define ishightBumperRight() (hight_bumper_right)
void HIGHT_BUMPERS_setStateChangedHandler(void (*hightbumperHandler)(void)); 
void task_Hight_Bumpers(void);
 Thorben
- - - Aktualisiert - - -
Danke Dirk waren Schreibfehler drin
						
					
Lesezeichen