Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: main.cpp
- Revision:
- 8:3fc2849c098d
- Parent:
- 7:7a73065d2d92
- Child:
- 9:bfb877e5fecf
--- a/main.cpp Wed Apr 22 06:36:01 2015 +0000 +++ b/main.cpp Fri Apr 24 07:09:59 2015 +0000 @@ -30,7 +30,8 @@ double rotate_time; int current_slice; char slice_data [NUMBER_OF_SLICES][16]; //[slice][specific led distance] (0 is closest) & with approppriate bit for each arm -int firstTime; +bool firstTime; + //serial port for pc and bluetooth Serial pc(USBTX, USBRX); // tx, rx @@ -38,16 +39,17 @@ //define variables for ziggbee MRF24J40 mrf(p11, p12, p13, p14, p26); +char rxBuffer[128]; char txBuffer[128]; -char rxBuffer[128]; int rxLen; +char buffer [4]; int rf_receive(char *data, uint8_t maxLength) { uint8_t len = mrf.Receive((uint8_t *)data, maxLength); uint8_t header[8]= {1, 8, 0, 0xA1, 0xB2, 0xC3, 0xD4, 0x00}; - + if(len > 10) { //Remove the header and footer of the message for(uint8_t i = 0; i < len-2; i++) { @@ -59,17 +61,34 @@ data[i-8] = data[i]; } } - + //pc.printf("Received: %s length:%d\r\n", data, ((int)len)-10); } return ((int)len)-10; } -void recievePoint (int slice, int distance, char addChar){ - //TODO make this edit the other thing +void recievePoint (int slice, int distance, char addChar, char operation){ + //pc.printf("recieved %i %i %X %c \r\n" , slice, distance, addChar, operation); + if (operation == 'x'){ + //pc.printf("odl slice data with x %X is \r\n", slice_data[slice][distance]); + slice_data [slice] [distance] ^= addChar; + //pc.printf("new slice data with X %X is \r\n", slice_data[slice][distance]); + return; + } + if (operation == 'o'){ + // pc.printf("odl slice data with o %X is \r\n", slice_data[slice][distance]); + slice_data [slice] [distance] |= addChar; + //pc.printf("new slice data with 0 %X is \r\n", slice_data[slice][distance]); + return; + } + if (operation == 'a'){ + slice_data [slice] [distance] = slice_data[slice][distance] & addChar; + return; + } } void pushData (char bits [16]){ - bt.printf("pushing data \r\n"); + + // pc.printf("pushing data \r\n"); for (int i = 8; i < 16; i ++){ dataArmOne = bits [i] & 0x01; dataArmTwo = bits [i] & 0x02; @@ -104,6 +123,7 @@ //periodic display interrupt void nextLedPush(){ + // pc.printf("next led push"); if (current_slice < NUMBER_OF_SLICES){ pushData(slice_data[current_slice]); current_slice ++; @@ -114,17 +134,18 @@ //Hall sensor interupt void rotate_sense(){ - bt.printf("interupt"); + // pc.printf("interupt"); if (firstTime){ rotationTime.reset(); rotationTime.start(); firstTime = false; - pc.printf("first time"); + // pc.printf(" first time"); return; - } else if(current_slice < NUMBER_OF_SLICES / 4){ + } + if(current_slice < NUMBER_OF_SLICES / 4){ return; - } - bt.printf("seconod time \n"); + } + // pc.printf(" seconod time \n"); rotate_time = rotationTime.read_us(); rotationTime.reset(); rotationTime.start(); @@ -139,59 +160,94 @@ int main() { - bt.printf("started"); + pc.printf("started"); firstTime = true; - current_slice = 0; + current_slice = 100; - uint8_t channel = 6; - //mrf.SetChannel(channel); + uint8_t channel = 2; + mrf.SetChannel(channel); hallSensor.fall(&rotate_sense); + /* for (int i = 0; i < 60; i ++){ + slice_data [i][0] = 0x11; // bit 0 is high on arm 0 + slice_data [i][1] = 0x11; + slice_data [i][2] = 0x11; + slice_data [i][3] = 0x11; + slice_data [i][4] = 0x11; + slice_data [i][5] = 0x11; + slice_data [i][6] = 0x11; + slice_data [i][7] = 0x11; + slice_data [i][8] = 0x11; + slice_data [i][9] = 0x11; + slice_data [i][10] = 0x11; + slice_data [i][11] = 0x11; + slice_data [i][12] = 0x11; + slice_data [i][13] = 0x11; + slice_data [i][14] = 0x11; + slice_data [i][15] = 0x11; + }*/ + /* for (int i = 0; i < 60; i ++){ - slice_data [i][0] = 0x01; // bit 0 is high on arm 0 - slice_data [i][1] = 0x01; - slice_data [i][2] = 0x01; - slice_data [i][3] = 0x01; - slice_data [i][4] = 0x01; - slice_data [i][5] = 0x01; - slice_data [i][6] = 0x01; - slice_data [i][7] = 0x01; - slice_data [i][8] = 0x01; - slice_data [i][9] = 0x01; - slice_data [i][10] = 0x01; - slice_data [i][11] = 0x01; - slice_data [i][12] = 0x01; - slice_data [i][13] = 0x01; - slice_data [i][14] = 0x01; - slice_data [i][15] = 0x01; + slice_data [i][0] = 0x00; // bit 0 is high on arm 0 + slice_data [i][1] = 0x00; + slice_data [i][2] = 0x00; + slice_data [i][3] = 0x00; + slice_data [i][4] = 0x00; + slice_data [i][5] = 0x00; + slice_data [i][6] = 0x08; + slice_data [i][7] = 0x00; + slice_data [i][8] = 0x00; + slice_data [i][9] = 0x00; + slice_data [i][10] = 0x00; + slice_data [i][11] = 0x00; + slice_data [i][12] = 0x00; + slice_data [i][13] = 0x00; + slice_data [i][14] = 0x00; + slice_data [i][15] = 0x00; } + for (int i = 60; i < 120; i++){ slice_data [i][0] = 0x00; // bit 0 is high on arm 0 - slice_data [i][1] = 0x01; + slice_data [i][1] = 0x00; slice_data [i][2] = 0x00; - slice_data [i][3] = 0x01; - slice_data [i][4] = 0x00; - slice_data [i][5] = 0x01; + slice_data [i][3] = 0x00; + slice_data [i][4] = 0x08; + slice_data [i][5] = 0x00; slice_data [i][6] = 0x00; - slice_data [i][7] = 0x01; + slice_data [i][7] = 0x00; slice_data [i][8] = 0x00; - slice_data [i][9] = 0x01; + slice_data [i][9] = 0x00; slice_data [i][10] = 0x00; - slice_data [i][11] = 0x01; + slice_data [i][11] = 0x00; slice_data [i][12] = 0x00; - slice_data [i][13] = 0x01; + slice_data [i][13] = 0x00; slice_data [i][14] = 0x00; - slice_data [i][15] = 0x01; + slice_data [i][15] = 0x00; } + */ + slice_data [60][15] = 0xFF; + for (int i = 0; i < 120; i ++){ + for (int j = 0; j < 16; j++){ + slice_data [i][j] = 0x00; + } + } + slice_data[60][14] = 0xFF; - pushData(slice_data[80]); while(true) { + //Try to receive some data - - //rxLen = rf_receive(rxBuffer, 24); - //if(rxLen > 24) { + rxLen = rf_receive(rxBuffer, 128); + if(rxLen > 0) { + int slice = (int) rxBuffer[0]; + int distance = (int) rxBuffer[1]; + char addChar = (char) rxBuffer[2]; + char operation = (char) rxBuffer[3]; - //} + //pc.printf("we got his from the buffer slice %i distance %i char %X operation %c \r\n", slice, distance, addChar, operation); + recievePoint(slice, distance, addChar, operation); + //TODO this means we got a + //char + } } }