Advertisement
Guest User

Untitled

a guest
Jan 24th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.63 KB | None | 0 0
  1. // Include the most common headers from the C standard library
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <time.h>
  6.  
  7. // Include the main libnx system header, for Switch development
  8. #include <switch.h>
  9.  
  10. // Main program entrypoint
  11. int main(int argc, char* argv[])
  12. {
  13. // This example uses a text console, as a simple way to output text to the screen.
  14. // If you want to write a software-rendered graphics application,
  15. // take a look at the graphics/simplegfx example, which uses the libnx Framebuffer API instead.
  16. // If on the other hand you want to write an OpenGL based application,
  17. // take a look at the graphics/opengl set of examples, which uses EGL instead.
  18. consoleInit(NULL);
  19.  
  20. // Other initialization goes here.
  21. printf("Hello World!\n");
  22. printf("This is a stopwatch\n\n\n");
  23. printf("**Press 'B' to start.\n");
  24. printf("**Press 'A' to pause.\n");
  25. printf("**Press '+' to exit.\n");
  26. int nSec;
  27. int nMin;
  28. int nHrs;
  29. int nDay;
  30.  
  31. struct timespec start_time, end_time;
  32. clock_gettime(CLOCK_REALTIME, &start_time);
  33.  
  34. // Main loop
  35. while (appletMainLoop()) // Start loop A
  36. {
  37. hidScanInput();
  38. // hidKeysDown returns information about which buttons have been
  39. // just pressed in this frame compared to the previous one
  40. u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO); // define kDown (press a button)
  41. u64 kHeld = hidKeysHeld(CONTROLLER_P1_AUTO); // define kHeld (hold a button)
  42.  
  43. //Exit:
  44. if (kDown & KEY_PLUS) // If + is pressed then:
  45. break; // End loop A and exit application
  46.  
  47. // Start:
  48. if (kDown & KEY_B) // If B is pressed
  49. {
  50. while (1) // Start loop B
  51. {
  52. hidScanInput();
  53. u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO); // define kDown (press a button)
  54. u64 kHeld = hidKeysHeld(CONTROLLER_P1_AUTO); // define kHeld (hold a button)
  55.  
  56. clock_gettime(CLOCK_REALTIME, &end_time);
  57. nSec = (end_time.tv_sec - start_time.tv_sec) + (end_time.tv_nsec - start_time.tv_nsec) /1000000000.0;
  58. nMin = (nSec/60);
  59. nHrs = (nMin/60);
  60. nDay = (nHrs/24);
  61. printf("\r"); // Print new line
  62. printf("Elapsed: %i Days & %i:%i:%f \r", nDay, nHrs%24, nMin%60, nSec%60); // Print new time
  63. consoleUpdate(NULL);// Update the console, sending a new frame to the display
  64. // Stop:
  65. if (kDown & KEY_A) // If A is pressed then
  66. break; // End loop B and return to loop A
  67. } // End loop B
  68.  
  69. if (kDown & KEY_B)
  70. {
  71. printf("Lap time: %f\n", (nSec/60) % 60); // Print time
  72. if (kDown); // Wait for input
  73. }
  74. else break; // End loop B and exit application if B is not pressed
  75. }; // Stop timer
  76. printf("Final Time %f\r", nSec); //display final time
  77.  
  78. consoleUpdate(NULL); // Update the console, sending a new frame to the display
  79. } // End loop A
  80.  
  81.  
  82.  
  83. /* =============================== END ======================================= */
  84.  
  85. printf("\n Goodbye."); // Say goodbye before exiting. (very important!)
  86. consoleUpdate(NULL);
  87. svcSleepThread(1e+9L);
  88. // Deinitialize and clean up resources used by the console (important!)
  89. consoleExit(NULL);
  90. return 0;
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement