![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Proj 324 Final
Fork of ELEC351_Group_T by
Diff: main.cpp
- Revision:
- 55:e0e684531825
- Parent:
- 54:a4c5949707ca
- Child:
- 56:bc5345bc6650
diff -r a4c5949707ca -r e0e684531825 main.cpp --- a/main.cpp Wed May 16 19:57:52 2018 +0000 +++ b/main.cpp Thu May 24 13:31:20 2018 +0000 @@ -14,6 +14,17 @@ */ //Colours Cubelet_Colours_string[]; +int colour_data = 0; +int temp_colour_data_1 = 0; +int temp_colour_data_2 = 0; +int temp_colour_data_3 = 0; +int temp_colour_data_4 = 0; +int temp_colour_data_5 = 0; +int temp_colour_data_6 = 0; +int temp_colour_data_7 = 0; +int temp_colour_data_8 = 0; +int temp_colour_data_9 = 0; + int SPI_RX_DATA = 0; int Cubelet_Colours[9] = {0,0,0,0,0,0,0,0,0};//9 cubelets store colours here int Received_data = 0; @@ -67,28 +78,13 @@ Thread::wait(1000); while(1) { - //Do stuff cs= 0; SPI_RX_DATA = spi.write(0xF0); wait_us(3); cs= 1; - //SPI_RX_DATA = SPI_RX_DATA >> 7; - //SPI_RX_DATA = SPI_RX_DATA << 1; - //std::bitset<16> bits(SPI_RX_DATA); - //cout << bits << endl; - - //if(bits != 0) - //{ - //find the location possition - //find the colour value - //Store these values in to the tempory array - //When all of the data is received all 9 cubelets set a global variable high / thread signal - - //} + colour_data = SPI_RX_DATA; pc.printf("Received data = %d\n", SPI_RX_DATA); - //wait_us(3); - Thread::wait(1000); - + Thread::wait(1000); } } @@ -101,15 +97,15 @@ } else if(Colour == 2) { - colours_return_value = Red; + colours_return_value = Orange; } else if(Colour == 3) { - colours_return_value = Orange; + colours_return_value = Blue; } else if(Colour == 4) { - colours_return_value = Blue; + colours_return_value = Red; } else if(Colour == 5) { @@ -119,27 +115,68 @@ { colours_return_value = Yellow; } - return colours_return_value; } void Store_Cubelet_data() -{ - - /* - enum Colours//The posible colours of each point on the cube map -{ - White,//Front - Red,//Upper - Orange,//Down - Blue,//Left - Green,//Right - Yellow//Back -}; - - */ - - //signal::wait(Cubelet_data_ready); - if(Cubelet_Colours[5] == 1) +{ + if((8 >= colour_data) && (colour_data <= 15)) + { + temp_colour_data_1 = colour_data - 8;//Result shall be the colour + Cubelet_Colours[0] = temp_colour_data_1;//Stores the colour value to the mememory map + //take colour_data postion value and subtract it and you will be left with just the colour + } + + if((16 >= colour_data) && (colour_data <= 23)) + { + temp_colour_data_2 = colour_data - 16;//Result shall be the colour + Cubelet_Colours[1] = temp_colour_data_2;//Stores the colour value to the mememory map + //take colour_data postion value and subtract it and you will be left with just the colour + } + if((24 >= colour_data) && (colour_data <= 31)) + { + temp_colour_data_3 = colour_data - 24;//Result shall be the colour + Cubelet_Colours[2] = temp_colour_data_3;//Stores the colour value to the mememory map + //take colour_data postion value and subtract it and you will be left with just the colour + } + if((32 >= colour_data) && (colour_data <= 39)) + { + temp_colour_data_4 = colour_data - 32;//Result shall be the colour + Cubelet_Colours[3] = temp_colour_data_4;//Stores the colour value to the mememory map + //take colour_data postion value and subtract it and you will be left with just the colour + } + if((40 >= colour_data) && (colour_data <= 47)) + { + temp_colour_data_5 = colour_data - 40;//Result shall be the colour + Cubelet_Colours[4] = temp_colour_data_5;//Stores the colour value to the mememory map + //take colour_data postion value and subtract it and you will be left with just the colour + } + if((48 >= colour_data) && (colour_data <= 55)) + { + temp_colour_data_6 = colour_data - 48;//Result shall be the colour + Cubelet_Colours[5] = temp_colour_data_6;//Stores the colour value to the mememory map + //take colour_data postion value and subtract it and you will be left with just the colour + } + if((56 >= colour_data) && (colour_data <= 63)) + { + temp_colour_data_7 = colour_data - 56;//Result shall be the colour + Cubelet_Colours[6] = temp_colour_data_7;//Stores the colour value to the mememory map + //take colour_data postion value and subtract it and you will be left with just the colour + } + if((64 >= colour_data) && (colour_data <= 71)) + { + temp_colour_data_8 = colour_data - 64;//Result shall be the colour + Cubelet_Colours[7] = temp_colour_data_8;//Stores the colour value to the mememory map + //take colour_data postion value and subtract it and you will be left with just the colour + } + if((72 >= colour_data) && (colour_data <= 79)) + { + temp_colour_data_9 = colour_data - 72;//Result shall be the colour + Cubelet_Colours[8] = temp_colour_data_9;//Stores the colour value to the mememory map + //take colour_data postion value and subtract it and you will be left with just the colour + } + + + if(Cubelet_Colours[5] == 1)//Store data to the white side { CubeMap[0][0][0] = convert(Cubelet_Colours[0]); CubeMap[0][0][1] = convert(Cubelet_Colours[1]); @@ -150,8 +187,72 @@ CubeMap[0][2][0] = convert(Cubelet_Colours[6]); CubeMap[0][2][1] = convert(Cubelet_Colours[7]); CubeMap[0][2][2] = convert(Cubelet_Colours[8]); - //CubeMap[6][3][3] + //Store this to the white face + } + if(Cubelet_Colours[5] == 2)//Store data to the orange side + { + CubeMap[1][0][0] = convert(Cubelet_Colours[0]); + CubeMap[1][0][1] = convert(Cubelet_Colours[1]); + CubeMap[1][0][2] = convert(Cubelet_Colours[2]); + CubeMap[1][1][0] = convert(Cubelet_Colours[3]); + CubeMap[1][1][1] = convert(Cubelet_Colours[4]); + CubeMap[1][1][2] = convert(Cubelet_Colours[5]); + CubeMap[1][2][0] = convert(Cubelet_Colours[6]); + CubeMap[1][2][1] = convert(Cubelet_Colours[7]); + CubeMap[1][2][2] = convert(Cubelet_Colours[8]); + //Store this to the white face + } + if(Cubelet_Colours[5] == 3)//Store data to the blue side + { + CubeMap[2][0][0] = convert(Cubelet_Colours[0]); + CubeMap[2][0][1] = convert(Cubelet_Colours[1]); + CubeMap[2][0][2] = convert(Cubelet_Colours[2]); + CubeMap[2][1][0] = convert(Cubelet_Colours[3]); + CubeMap[2][1][1] = convert(Cubelet_Colours[4]); + CubeMap[2][1][2] = convert(Cubelet_Colours[5]); + CubeMap[2][2][0] = convert(Cubelet_Colours[6]); + CubeMap[2][2][1] = convert(Cubelet_Colours[7]); + CubeMap[2][2][2] = convert(Cubelet_Colours[8]); //Store this to the white face + } + if(Cubelet_Colours[5] == 4)//Store data to the red side + { + CubeMap[3][0][0] = convert(Cubelet_Colours[0]); + CubeMap[3][0][1] = convert(Cubelet_Colours[1]); + CubeMap[3][0][2] = convert(Cubelet_Colours[2]); + CubeMap[3][1][0] = convert(Cubelet_Colours[3]); + CubeMap[3][1][1] = convert(Cubelet_Colours[4]); + CubeMap[3][1][2] = convert(Cubelet_Colours[5]); + CubeMap[3][2][0] = convert(Cubelet_Colours[6]); + CubeMap[3][2][1] = convert(Cubelet_Colours[7]); + CubeMap[3][2][2] = convert(Cubelet_Colours[8]); + //Store this to the white face + } + if(Cubelet_Colours[5] == 5)//Store data to the green side + { + CubeMap[4][0][0] = convert(Cubelet_Colours[0]); + CubeMap[4][0][1] = convert(Cubelet_Colours[1]); + CubeMap[4][0][2] = convert(Cubelet_Colours[2]); + CubeMap[4][1][0] = convert(Cubelet_Colours[3]); + CubeMap[4][1][1] = convert(Cubelet_Colours[4]); + CubeMap[4][1][2] = convert(Cubelet_Colours[5]); + CubeMap[4][2][0] = convert(Cubelet_Colours[6]); + CubeMap[4][2][1] = convert(Cubelet_Colours[7]); + CubeMap[4][2][2] = convert(Cubelet_Colours[8]); + //Store this to the white face + } + if(Cubelet_Colours[5] == 6)//Store data to the yellow side + { + CubeMap[5][0][0] = convert(Cubelet_Colours[0]); + CubeMap[5][0][1] = convert(Cubelet_Colours[1]); + CubeMap[5][0][2] = convert(Cubelet_Colours[2]); + CubeMap[5][1][0] = convert(Cubelet_Colours[3]); + CubeMap[5][1][1] = convert(Cubelet_Colours[4]); + CubeMap[5][1][2] = convert(Cubelet_Colours[5]); + CubeMap[5][2][0] = convert(Cubelet_Colours[6]); + CubeMap[5][2][1] = convert(Cubelet_Colours[7]); + CubeMap[5][2][2] = convert(Cubelet_Colours[8]); + //Store this to the white face } } @@ -199,14 +300,13 @@ int main() { - set_time(1515530152); //Sets time pc.baud(9600); //Sets the Serial Comms Baud Rate //SPI_INIT(); cs = 1; //Active Low // Setup the spi for 8 bit data, high steady state clock, // second edge capture, with a 1MHz clock rate - spi.format(16,1); // 8 Data bits phase 0 polarity 0 + spi.format(16,1); // 8 Data bits phase 0 polarity 0 //CHECK THIS spi.frequency(1000000);//Output clock frequency 1Mhz //post(); //Power on Self Test