mbed tokyotech
Dependencies: C12832 EthernetInterface HTTPClient USBDevice mbed-rtos mbed Speaker
Revision 4:52109f4cb132, committed 2016-02-11
- Comitter:
- Mickemoj
- Date:
- Thu Feb 11 01:46:42 2016 +0000
- Parent:
- 3:6d2b9fcb8fa8
- Commit message:
- Program dies after gameover screen, probably due to tickhandler
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 6d2b9fcb8fa8 -r 52109f4cb132 main.cpp --- a/main.cpp Thu Feb 11 00:52:47 2016 +0000 +++ b/main.cpp Thu Feb 11 01:46:42 2016 +0000 @@ -29,14 +29,12 @@ // Length of an audio packet: each ms, we receive 48 * 16bits ->48 * 2 bytes. As there is one channel, the length will be 48 * 2 * 1 #define AUDIO_LENGTH_PACKET 48 * 2 * 1 -Serial pc(USBTX, USBRX); +RawSerial pc(USBTX, USBRX); //Variables for audio streaming // USBAudio -//USBAudio audio(FREQ, NB_CHA, 8000, 1, 0x7180, 0x7500); - - +USBAudio audio(FREQ, NB_CHA, 8000, 1, 0x7180, 0x7500); // Ticker to send data to the speaker at the required frequency Ticker tic; @@ -70,6 +68,8 @@ Speaker speaker2(p26); +int toggle_flag = 1; + // sting buffers for tweeting char str[512]; char buf[512]; @@ -142,8 +142,8 @@ } void gameOverFun(){ - speaker2.PlayNote(969.0, 0.5, 1.0); - speaker2.PlayNote(800.0, 0.5, 1.0); + //speaker2.PlayNote(969.0, 0.5, 1.0); + //speaker2.PlayNote(800.0, 0.5, 1.0); lcd.cls(); lcd.locate(xDim / 2 - 10, yDim / 2); lcd.printf("Game Over"); @@ -162,7 +162,7 @@ setUpGame(); while(!gameOverScreen) { - pc.printf("Inne"); + //pc.printf("Inne"); //Handles joystick-input if(joy) { @@ -219,7 +219,7 @@ if(hit2) createNewFood(); else if(hitE){ - + //tic.detach(); gameOver = true; gameOverScreen = true; gameOverFun(); @@ -256,22 +256,22 @@ url = url + msg; //pc.printf("URL: %s\n", url.c_str()); - pc.printf("i tweet3"); + //pc.printf("i tweet3"); // send HTTP request int ret = http.get(url.c_str(), str, 128); - pc.printf("i tweet4"); + //pc.printf("i tweet4"); if (ret == HTTP_OK) { - pc.printf("Success!\n"); + //pc.printf("Success!\n"); } else { - pc.printf("Error #%d\n", ret); + //pc.printf("Error #%d\n", ret); } //Used to restart game setUpGame(); - pc.printf("Response code: %d\n", http.getHTTPResponseCode()); + //pc.printf("Response code: %d\n", http.getHTTPResponseCode()); } @@ -284,18 +284,19 @@ void tweetHighscore(void const *args){ //tic.detach(); + //available = false; setUpNetwork(); while(true) { //locker.lock(); if (gameOver) { - pc.printf("I game over"); + //pc.printf("I game over"); //tic.detach(); std::string msg; ostringstream convert; convert << "Score: " << score << ", " << xKiller; msg = convert.str(); tweet(msg); - pc.printf("efter tweet(msg)"); + //pc.printf("efter tweet(msg)"); locker.lock(); gameOver = false; bool kalle = true; @@ -311,7 +312,7 @@ } // Function executed each 1/FREQ s -/*void tic_handler() { +void tic_handler() { float speaker_value; if (available) { @@ -341,13 +342,13 @@ // Send value to the speaker speaker.write_u16((uint16_t)speaker_value); -}*/ +} int main() { + // Attach a function executed each 1/FREQ s - // tic.attach_us(tic_handler, 1000000.0/(float)FREQ); - + tic.attach_us(tic_handler, 1000000.0/(float)FREQ); //pc.printf("hej"); createNewFood(); //pc.printf("after create food"); @@ -356,17 +357,19 @@ //pc.printf("after threads"); - /*while (1) { + while (1) { // Read an audio packet - if(gameOver){ - - Thread::wait(10000); - } + /*if(gameOver){ + + tic.detach(); + + + }*/ audio.read((uint8_t *)buf2); available = true; - }*/ - while(true) { + } + /*while(true) { Thread::wait(500); - } + }*/ } \ No newline at end of file