void showStatus(uint8_t verdieping, uint16_t hoogte, uint8_t motor) { // "rechtsom aan", "Hoogte: 100 " showScreenLCD(" ", "H: V: "); setCursorPosLCD(0, 13); writeStringLCD_P("aan"); // motor status switch (motor) { case MOTOR_IDLE: setCursorPosLCD(0, 13); writeStringLCD_P("uit"); break; case MOTOR_LEFT: setCursorPosLCD(0, 0); writeStringLCD_P("Linksom"); break; case MOTOR_RIGHT: setCursorPosLCD(0, 0); writeStringLCD_P("Rechtsom"); break; } setCursorPosLCD(1, 3); writeIntegerLCD(hoogte, DEC); setCursorPosLCD(1, 15); writeIntegerLCD(verdieping, DEC); setLEDs(1 << verdieping); }
/* * Initialize the pathfinder */ void pathfinder_init(uint8_t x, uint8_t y, direction currentDirection) { lastDirection = currentDirection; clearLCD(); setCursorPosLCD(0, 2); writeIntegerLCD(x, DEC); setCursorPosLCD(0, 5); writeIntegerLCD(y, DEC); mSleep(5000); // initialize root node root = malloc(sizeof(root)); root->count = nodeCount; root->x = x; root->y = y; root->north = NULL; root->west = NULL; root->south = NULL; root->east = NULL; // make the current node the root node current = root; // also, initialize the empty node empty = malloc(sizeof(empty)); empty->count = 255; empty->x = 255; empty->y = 255; empty->north = NULL; empty->west = NULL; empty->south = NULL; empty->east = NULL; // initialize the current node if (!hal_hasWallLeft()) { current->west = empty; } if (!hal_hasWallFront()) { current->north = empty; } if (!hal_hasWallRight()) { current->east = empty; } }
/* * Make a new step */ direction pathfinder_NextStep(direction currentDirection, uint8_t x, uint8_t y) { // first check if we have reached the target already if ((x == targetX) && (y == targetY)) { // we ain't going anywhere soon! return NONE; } setCursorPosLCD(0, 2); writeIntegerLCD(root->x, DEC); setCursorPosLCD(0, 5); writeIntegerLCD(root->y, DEC); setCursorPosLCD(1, 0); writeIntegerLCD(current->count, DEC); setCursorPosLCD(1, 4); writeIntegerLCD(nodeCount, DEC); // now check if we can only go one direction if (hal_hasWallLeft() && hal_hasWallRight() && !hal_hasWallFront()) { return currentDirection; } else if (hal_hasWallLeft() && !hal_hasWallRight() && hal_hasWallFront()) { return turnRight(currentDirection); } else if (!hal_hasWallLeft() && hal_hasWallRight() && hal_hasWallFront()) { return turnLeft(currentDirection); } // we cannot keep cruising normally // get the node or create a new one struct node *node = getNode(current); if (!node) { node = createNode(current, currentDirection, x, y); } if (hal_hasWallLeft() && hal_hasWallRight() && hal_hasWallFront()) { // dead end current = node; currentDirection = turnAround(currentDirection); } else { // ok, decide where we're gonna go chooseDirection(currentDirection, node, x, y); current = node; } lastDirection = currentDirection; return currentDirection; }
void showSimParams( void ) { clearPosLCD(0,7,5); setCursorPosLCD(0, 7); writeIntegerLCD( Balloon_get_height(), DEC); clearPosLCD(1,3,5); setCursorPosLCD(1, 3); if(Balloon_get_valvestate() == OPEN) { writeStringLCD("OPEN "); } else { writeStringLCD("CLOSED"); } clearPosLCD(1,13,5); setCursorPosLCD(1, 13); if(Balloon_get_burnerstate() == ON) { writeStringLCD("ON "); } else { writeStringLCD("OFF"); } }
int main(void) { initRP6Control(); // Always call this first! The Processor will not work // correctly otherwise. bars(2); writeString_P("\n\nRP6Control Selftest!\n\n"); bars(2); setLEDs(0b1111); mSleep(50); initLCD(); showScreenLCD("################", "################"); mSleep(400); showScreenLCD("################", "################"); showScreenLCD("RP6Control M32", "SELFTEST"); mSleep(1000); uint8_t keynumber = 0; while(keynumber < 6) { uint8_t key = checkReleasedKeyEvent(); if(key == keynumber) { keynumber++; showScreenLCD("PRESS BUTTON", "NUMBER "); writeIntegerLCD(keynumber,DEC); setLEDs(0b0000); writeString_P("### PRESS BUTTON NUMBER "); writeInteger(keynumber,DEC); writeString_P("!\n"); } } showScreenLCD("Testing", "BEEPER & LEDS"); mSleep(250); // Play a sound to indicate that our program starts: sound(50,50,100); setLEDs(0b0000); sound(80,50,100); setLEDs(0b0001); sound(100,50,100);setLEDs(0b0010); sound(120,50,100);setLEDs(0b0100); sound(140,50,100);setLEDs(0b1000); sound(160,50,100);setLEDs(0b1001); sound(180,50,100);setLEDs(0b1011); sound(200,50,100);setLEDs(0b1111); mSleep(400); setLEDs(0b0000); showScreenLCD("Testing", "EERPOM"); test(1); writeString_P("\nEEPROM TEST\n"); writeString_P("\nErasing 250 Bytes...\n"); uint8_t cnt; for(cnt = 0; cnt < 250; cnt++) { SPI_EEPROM_writeByte(cnt, 0xFF); while(SPI_EEPROM_getStatus() & SPI_EEPROM_STAT_WIP); } writeString_P("...Done!\nWriting 250 Bytes to EEPROM:\n"); for(cnt = 0; cnt < 250; cnt++) { writeIntegerLength(cnt, DEC, 3); SPI_EEPROM_writeByte(cnt, cnt); while(SPI_EEPROM_getStatus() & SPI_EEPROM_STAT_WIP); writeChar(','); if(cnt % 10 == 0) writeChar('\n'); } mSleep(400); setLEDs(0b1111); writeString_P("\nReading and verifying:\n"); for(cnt = 0; cnt < 250; cnt++) { uint8_t result = SPI_EEPROM_readByte(cnt); if(result != cnt) { writeString_P("\nEEPROM VERIFY ERROR!!!! EEPROM DAMAGED!!!\n"); writeString_P("Data read: "); writeInteger(result,DEC); writeString_P(", should be: "); writeInteger(cnt,DEC); writeChar('\n'); errors++; } else writeIntegerLength(result,DEC,3); writeChar(','); if(cnt % 10 == 0) writeChar('\n'); } writeString_P("\nErasing 250 Bytes...\n"); for(cnt = 0; cnt < 250; cnt++) { SPI_EEPROM_writeByte(cnt, 0xFF); while(SPI_EEPROM_getStatus() & SPI_EEPROM_STAT_WIP); } mSleep(400); setLEDs(0b0000); writeString_P("\nEEPROM TEST DONE!\n"); writeString_P("\nI2C TWI TEST:\n"); showScreenLCD("I2C TWI", "TEST"); I2CTWI_initMaster(100); I2CTWI_setTransmissionErrorHandler(I2C_transmissionError); uint8_t runningLight = 1; for(cnt = 0; cnt < 24; cnt++) { writeIntegerLength(cnt,DEC,3); writeChar(':'); writeIntegerLength(runningLight,DEC,3); writeChar(','); writeChar(' '); I2CTWI_transmit3Bytes(I2C_RP6_BASE_ADR, 0, 3, runningLight); I2CTWI_transmitByte(I2C_RP6_BASE_ADR, 29); uint8_t result = I2CTWI_readByte(I2C_RP6_BASE_ADR); if(result != runningLight) { writeString_P("\nTWI TEST ERROR!\n"); errors++; } runningLight <<= 1; if(runningLight > 32) runningLight = 1; if((cnt+1) % 6 == 0) writeChar('\n'); mSleep(100); } I2CTWI_transmit3Bytes(I2C_RP6_BASE_ADR, 0, 3, 0); writeString_P("\nTWI TEST DONE!\n"); writeString_P("\nMicrophone Test\n"); writeString_P("Hit the Microphone three times with your finger!\n"); showScreenLCD("MIC TEST:", ""); #define PREPARE 1 #define WAIT 2 uint8_t state = PREPARE; startStopwatch2(); while(true) { static uint8_t peak_count = 3; if(state == PREPARE) { if(getStopwatch2() > 250) { setCursorPosLCD(1, 6); writeIntegerLengthLCD( peak_count, DEC, 1); dischargePeakDetector(); state = WAIT; setStopwatch2(0); } } else if(state == WAIT) { uint8_t key = checkReleasedKeyEvent(); if(key) { break; } if(getStopwatch2() > 50) { uint16_t tmp = getMicrophonePeak(); if(tmp > 4) { externalPort.LEDS = 0; uint16_t i; uint8_t j; for(i = 0, j = 2; i < tmp; i+= 40) { if(i < 40) { externalPort.LEDS++; } else { externalPort.LEDS <<=1; externalPort.LEDS++; } } outputExt(); if(tmp > 120) { state = PREPARE; peak_count--; } if(peak_count == 0) break; } else setLEDs(0b0000); setStopwatch2(0); } } } writeString_P("\nMICROPHONE TEST DONE!\n"); showScreenLCD("ALL TESTS", "DONE!"); writeString_P("\n\n\n\n"); bars(2); writeString_P("\n\nALL TESTS DONE!\n\n"); if(errors) { bars(4); writeString_P("\nERROR ERROR ERROR ERROR ERROR ERROR ERROR\n"); writeString_P("\nATTENTION: TESTS FINISHED WITH ERRORS!!!\n"); writeString_P("PLEASE CHECK RP6-M32 ASSEMBLY!!!\n\n"); bars(4); writeString_P("\n\n"); } // Now we just show a running light... startStopwatch1(); uint8_t runLEDs = 1; uint8_t dir = 0; while(true) { if(getStopwatch1() > 100) { setLEDs(runLEDs); if(dir == 0) runLEDs <<= 1; else runLEDs >>= 1; if(runLEDs > 7 ) dir = 1; else if (runLEDs < 2 ) dir = 0; setStopwatch1(0); } }
void ir_receiveBaseStation(void) { uint8_t tijdelijk; writeString_P("aap!\n"); while ((personX == 0xFF) || (personY == 0xFF) || (startX == 0xFF) || (startY == 0xFF)) { I2CTWI_transmitByte(I2C_RP6_BASE_ADR, 27); tijdelijk = I2CTWI_readByte(I2C_RP6_BASE_ADR); writeString_P("ADDR: "); writeInteger((int16_t) tijdelijk, DEC); I2CTWI_transmitByte(I2C_RP6_BASE_ADR, 28); tijdelijk = I2CTWI_readByte(I2C_RP6_BASE_ADR); writeString_P(" DATA: "); writeInteger((int16_t) tijdelijk, DEC); writeString_P("\n"); mSleep(100); // implement device bit 0 - device bit - code // Oops! i did it again (van 44 naar 9) if (tijdelijk >= 48 && tijdelijk <= 56) { startY = tijdelijk - 48; } else if (tijdelijk >= 32 && tijdelijk <= 38) { startX = tijdelijk - 32; } else if (tijdelijk >= 16 && tijdelijk <= 24) { personY = tijdelijk - 16; } else if (tijdelijk <= 6) { personX = tijdelijk; } // for now, just put it on the screen clearLCD(); setCursorPosLCD(0, 0); writeCharLCD('X'); setCursorPosLCD(0, 2); writeIntegerLCD(startX, DEC); setCursorPosLCD(0, 10); writeCharLCD('Y'); setCursorPosLCD(0, 12); writeIntegerLCD(startY, DEC); setCursorPosLCD(1, 0); writeCharLCD('X'); setCursorPosLCD(1, 2); writeIntegerLCD(personX, DEC); setCursorPosLCD(1, 10); writeCharLCD('Y'); setCursorPosLCD(1, 12); writeIntegerLCD(personY, DEC); } }