Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.72 KB | None | 0 0
  1. /*----------------------------------------------------------------------------
  2. -           SE 185: Lab 03 - Introduction to the DS4 and Functions           -
  3. -   Name:                                                                    -
  4. -   Section:                                                                 -
  5. -   NetID:                                                                   -
  6. -   Date:                                                                    -
  7. -----------------------------------------------------------------------------*/
  8.  
  9. /*----------------------------------------------------------------------------
  10. -                               Includes                                     -
  11. -----------------------------------------------------------------------------*/
  12. #include <stdio.h>
  13. #include <math.h>
  14.  
  15. /*----------------------------------------------------------------------------
  16. -                               Prototypes                                   -
  17. -----------------------------------------------------------------------------*/
  18. double magnitude(double x, double y, double z);
  19.  
  20. /*----------------------------------------------------------------------------
  21. -                                   Notes                                    -
  22. -----------------------------------------------------------------------------*/
  23. // Compile with gcc lab03-1.c -o lab03-1
  24. // Run with ./ds4rd.exe -d 054c:05c4 -D DS4_BT -t -a | ./lab03-1
  25.  
  26. /*----------------------------------------------------------------------------
  27. -                               Implementation                               -
  28. -----------------------------------------------------------------------------*/
  29. int main(int argc, char *argv[])
  30. {
  31.     /* DO NOT MODIFY THESE VARIABLE DECLARATIONS */
  32.     int t;
  33.     double ax, ay, az;
  34.  
  35.     while (1)
  36.     {
  37.         scanf("%d, %lf, %lf, %lf", &t, &ax, &ay, &az);
  38.        
  39.         /* CODE SECTION 0 */
  40.        
  41.         printf("Echoing output: %8.3lf, %7.4lf, %7.4lf, %7.4lf\n", (t/1000.0), ax, ay, az);
  42.  
  43.  
  44.         /*  CODE SECTION 1 */
  45.         printf("At %d ms, the acceleration's magnitude was: %lf\n", t, magnitude(ax, ay, az));
  46.  
  47.  
  48.         /*  CODE SECTION 2 */
  49.        
  50.             printf("At %d minutes, %d seconds, and %d milliseconds it was: %lf\n",
  51.             minutes(t), seconds(t), millis(t), magnitude(ax, ay, az));
  52.        
  53.     }
  54.  
  55.     return 0;
  56. }
  57.  
  58. /* Put your functions here */
  59. int seconds(int t){
  60.     double s = (t / 1000 / 60);
  61.    
  62.     return(s * 60);
  63.    
  64. }
  65. int minutes(int t){
  66.    
  67. }
  68. int milliseconds(int t){
  69.    
  70.    
  71. }
  72.  
  73.    
  74. /**
  75.  * Calculates and returns the magnitude of three given values.
  76.  *
  77.  * @param x - The x-axis scanned values from the DS4 controller.
  78.  * @param y - The y-axis scanned values from the DS4 controller.
  79.  * @param z - The z-axis scanned values from the DS4 controller.
  80.  * @return - The magnitude of the given values.
  81.  */
  82. double magnitude(double x, double y, double z)
  83. {
  84.     // Step 8, uncomment and modify the next line
  85.      sqrt(pow(x,2.0) + pow(y,2.0) + pow(z, 2.0));
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement