Пример #1
0
int main (int argc, char ** argv)
{
    	int execResult = 0;

	picoInit();

	// push to cut
	execResult = setAllPins(pin_OFF,pin_OFF,pin_OFF,pin_OFF,pin_ON,pin_OFF,pin_ON,pin_ON, pin_ON,pin_ON);
	if (execResult != 0)
	{
	   fprintf(stderr, "Setting all pins in cut.c failed\n");
	   resetPins();
	   exit(2);
	}
	
	delay(1000); //TODO: check with team
	
	execResult = initALBA();
	if (execResult != 0)
	{
	   fprintf(stderr, "initALBA() in cut.c failed = %d \n", execResult);
		   exit(3);
    	}
	
    	return 0;
}
Пример #2
0
/**
 * \fn DSA::DSA(int DSApin, int STBpin, int ACKpin)
 * \brief Constructor
 *
 * \param DSApin Pin to be used as "data" pin
 * \param STBpin Pin to be used as "strobe" pin
 * \param ACKpin Pin to be used as "acknowledge" pin
 */
DSA::DSA(int DSApin, int STBpin, int ACKpin)
{
	_DSApin = DSApin;
	_STBpin = STBpin;
	_ACKpin = ACKpin;
	
	resetPins();
}
Пример #3
0
/**
 * \fn bool DSA::waitForMessage(byte *opcode, byte *parameter)
 * \deprecated Try to avoid using this function. It will block your
 * program for the timeout time when no message is received.
 * Better keep checking transmitRequested() in you main loop.
 * \brief Wait for a message to receive.
 *
 * When a message is expected this function will wait for the message to arrive.
 * A timeout is set to abort this function at timeout. 
 * \param *opcode Pointer to the opcode variable that will updated after a successful transfer
 * \param *parameter Pointer to the parameter variable that will updated after a successful transfer.
 * \return True on a successful transfer, False on a timeout or communication error
 */
bool DSA::waitForMessage(byte *opcode, byte *parameter)
{
	startTimeoutTimer(DSA_TIMEOUT);
	while(!transmitRequested()) {
		if(timeOut()) {
			resetPins();
			return false;
		}
	}
	return receiveMessage(opcode, parameter);
}
Пример #4
0
// checks the keypad for key press. returns the first key press sensed.
// Returns the number of the key pressed (* = 14, # = 15)
int checkForInput() {
    char scan;

    PORTCbits.RC0 = 0; // check row1
    Delay10TCYx(10);
    scan = (PORTBbits.RB0 << 3 | PORTBbits.RB1 << 2 | PORTBbits.RB2 << 1 | PORTBbits.RB3);
    switch (scan) {
        case 0b00001110: // is on Bbits.RB3
            return resetPins(1);
        case 0b00001101: // on pin 5
            return resetPins(2);
        case 0b00001011: // on pin 6
            return resetPins(3);
        case 0b00000111: // on pin 7
            return resetPins(10);
    }

    PORTCbits.RC0 = 1; // check row2
    PORTCbits.RC1 = 0;
    Delay10TCYx(10);
    scan = (PORTBbits.RB0 << 3 | PORTBbits.RB1 << 2 | PORTBbits.RB2 << 1 | PORTBbits.RB3);
    switch (scan) {
        case 0b00001110: // is on Bbits.RB3
            return resetPins(4);
        case 0b00001101: // on pin 5
            return resetPins(5);
        case 0b00001011: // on pin 6
            return resetPins(6);
        case 0b00000111: // on pin 7
            return resetPins(11);
    }


    PORTCbits.RC1 = 1; // check row3
    PORTCbits.RC2 = 0;
    Delay10TCYx(10);
    scan = (PORTBbits.RB0 << 3 | PORTBbits.RB1 << 2 | PORTBbits.RB2 << 1 | PORTBbits.RB3);
    switch (scan) {
        case 0b00001110: // is on Bbits.RB3
            return resetPins(7);
        case 0b00001101: // on pin 5
            return resetPins(8);
        case 0b00001011: // on pin 6
            return resetPins(9);
        case 0b00000111: // on pin 7
            return resetPins(12);
    }

    PORTCbits.RC2 = 1; // check row4
    PORTCbits.RC3 = 0;
    Delay10TCYx(10);
    scan = (PORTBbits.RB0 << 3 | PORTBbits.RB1 << 2 | PORTBbits.RB2 << 1 | PORTBbits.RB3);
    switch (scan) {
        case 0b00001110: // is on Bbits.RB3
            return resetPins(14);
        case 0b00001101: // on pin 5
            return resetPins(0);
        case 0b00001011: // on pin 6
            return resetPins(15);
        case 0b00000111: // on pin 7
            return resetPins(16);
    }

    return resetPins(-1); // assume no key was pressed.
}
Пример #5
0
/**
 * \fn bool DSA::sendMessage(byte opcode, byte parameter)
 * \brief Send a message.
 *
 * A DSA message contains a opcode and a parameter send as one 16bit command.
 * \param opcode The DSA opcode to send.
 * \param parameter The DSA parameter to send.
 * \return True on a successful transfer, False on a communication error
 */
bool DSA::sendMessage(byte opcode, byte parameter)
{
	/* synchPhase */
	int command = opcode;
	command = command << 8;
	command += parameter;

	digitalWrite(_DSApin, HIGH);
	resetPins();														
	pinMode(_DSApin, OUTPUT);

	startTimeoutTimer(DSA_TIMEOUT);
	digitalWrite(_DSApin, LOW);
	
	while(digitalRead(_ACKpin)) {
		if(timeOut()) {
			resetPins();
			return false;
		}
	}
	digitalWrite(_DSApin, HIGH);

	while(!digitalRead(_ACKpin)) {
		if(timeOut()) {
			resetPins();
			return false;
		}
	}
	/* data transfer phase */
	digitalWrite(_STBpin, HIGH);
	pinMode(_STBpin, OUTPUT);

	startTimeoutTimer(DSA_TIMEOUT);

	unsigned int mask = 0x8000;
	int i;
	for (i = 0; i < 16; i++ ) {
		if(!(command & mask))
			digitalWrite(_DSApin, LOW);
		digitalWrite(_STBpin, LOW);
		while(digitalRead(_ACKpin)) {
			if(timeOut()) {
				resetPins();
				return false;
			}
		}
		digitalWrite(_STBpin, HIGH);
		digitalWrite(_DSApin, HIGH);

		while(!digitalRead(_ACKpin)) {
			if(timeOut()) {
				resetPins();
				return false;
			}
		}
		mask = mask >> 1;
	}
	/* acknowledge phase */
	digitalWrite(_ACKpin, HIGH);
	resetPins();
	pinMode(_ACKpin, OUTPUT);

	startTimeoutTimer(DSA_TIMEOUT);

	digitalWrite(_ACKpin, LOW);
	while(digitalRead(_STBpin)) {
		if(timeOut()) {
			resetPins();
			return false;
		}
	}
	if(!digitalRead(_DSApin)) {
		resetPins();
		return false;
	}	
	digitalWrite(_ACKpin, HIGH);
	while(!digitalRead(_STBpin)) {
		if(timeOut()) {
			resetPins();
			return false;
		}
	}
	resetPins();
	return true;			
}
Пример #6
0
/**
 * \fn bool DSA::receiveMessage(byte *opcode, byte *parameter)
 * \brief Receive a message.
 *
 * \param *opcode Pointer to the opcode variable that will updated after a successful transfer
 * \param *parameter Pointer to the parameter variable that will updated after a successful transfer.
 * \return True on a successful transfer, False on a communication error
 */
bool DSA::receiveMessage(byte *opcode, byte *parameter)
{
	/* synchPhase */
	word command = 0;
	digitalWrite(_ACKpin, HIGH);
	resetPins();
	pinMode(_ACKpin, OUTPUT);
	startTimeoutTimer(DSA_TIMEOUT);
	digitalWrite(_ACKpin, LOW);

	while(!digitalRead(_DSApin)) {
		if(timeOut()) {
			resetPins();
			return false;
		}
	}
	digitalWrite(_ACKpin, HIGH);
	
	/* data transmission phase */
	startTimeoutTimer(DSA_TIMEOUT);
	unsigned int mask = 0x8000;
	int i;
	for (i = 0; i < 16; i++ ) {
		while(digitalRead(_STBpin)) {
			if(timeOut()) {
				resetPins();
				return false;
			}
		}

		if (digitalRead(_DSApin))
			command = command | mask;

		digitalWrite(_ACKpin, LOW);

		while(!digitalRead(_STBpin)) {
			if(timeOut()) {
				resetPins();
				return false;
			}
		}
		digitalWrite(_ACKpin, HIGH);
		mask = mask >> 1;
	}

	/* acknowledge phase */
	pinMode(_STBpin, OUTPUT);
	pinMode(_DSApin, OUTPUT);
	pinMode(_ACKpin, INPUT);

	startTimeoutTimer(DSA_TIMEOUT);

	while(digitalRead(_ACKpin)) {
		if(timeOut()) {
			resetPins();
			return false;
		}
	}
	
	if(i != 16)
		digitalWrite(_DSApin, LOW);

	digitalWrite(_STBpin, LOW);

	while(!digitalRead(_ACKpin)) {
		if(timeOut()) {
			resetPins();
			return false;
		}
	}
	digitalWrite(_DSApin, HIGH);
	digitalWrite(_STBpin, HIGH);
	
	*parameter	= lowByte(command);
	*opcode = highByte(command);

	resetPins();
	return true;
}