-
-
Save elliotthall/fbc4ae0c61aa96436a1f1a3648003b40 to your computer and use it in GitHub Desktop.
A sample of the main library for the Digital Ghost Hunt Seek detector
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* Query the UWB for our current location, and nearby anchors */ | |
| //% | |
| int currentLoc(){ | |
| if (mode == 0){ | |
| uint8_t RXBuffer[BUFFLEN]; | |
| uBit.serial.send((uint8_t *)GET_LOC, 2); | |
| uBit.sleep(200); | |
| int waiting = -1; | |
| int bufferIndex = -1; | |
| // How much is waiting in the RX buffer? | |
| waiting = uBit.serial.rxBufferedSize(); | |
| if (waiting > BUFFLEN){ | |
| uBit.panic(10); | |
| } | |
| if (waiting > 0){ | |
| uBit.serial.read((uint8_t *)RXBuffer,waiting,ASYNC); | |
| uBit.sleep(200); | |
| bufferIndex = 0; | |
| //Check the return byte and error code | |
| bufferIndex = parseDWMReturn(RXBuffer,bufferIndex); | |
| if (bufferIndex > 0){ // && waiting >= MIN_LOC_RETURN | |
| // Get the tag's location | |
| bufferIndex = parseLoc(pos,RXBuffer,bufferIndex); | |
| //uBit.display.scroll("PL"); | |
| //uBit.display.scroll(bufferIndex,100); | |
| if (bufferIndex > 0){ | |
| bufferIndex = parseAnchors(RXBuffer, bufferIndex); | |
| } else{ | |
| uBit.display.scroll("ERROR DWMPARSELOC"); | |
| } | |
| } else{ | |
| uBit.display.scroll("ERROR DWMReturn"); | |
| } | |
| } else { | |
| uBit.display.scroll("U12"); | |
| } | |
| //int numAnchors = RXBuffer[bufferIndex+2]; | |
| return bufferIndex; | |
| } else if (mode ==1){ | |
| //Set test data and return correct read | |
| pos[0] = 0; | |
| pos[1] = 0; | |
| pos[2] = 0; | |
| currentNumAnchors = 1; | |
| anchors[0][0] = 1234; | |
| anchors[0][1] = 3334; | |
| return 44; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment