Advertisement
Guest User

Untitled

a guest
Apr 12th, 2017
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ARM 1.59 KB | None | 0 0
  1. /*
  2.  *  C to assembler menu hook
  3.  *
  4.  */
  5.  
  6. #include <stdio.h>
  7. #include <stdint.h>
  8. #include <ctype.h>
  9. #include <string.h>
  10.  
  11. #include "common.h"
  12.  
  13.  #define kClockRate 10000000
  14.  #define kMaxNumLights 8
  15.  
  16. int mg_game_demo(int delay, char* pattern, int target);
  17.  
  18. void mgGame(int action)
  19. {
  20.   uint32_t delay, target;
  21.   char pattern[kMaxNumLights + 1];
  22.   char* pchar = NULL;
  23.   int rc;
  24.  
  25.   if(action==CMD_SHORT_HELP) return;
  26.   if(action==CMD_LONG_HELP) {
  27.     printf("LED Game - Assignment 3\n\n"
  28.        "This command tests new addition function\n"
  29.        );
  30.  
  31.     return;
  32.   }
  33.  
  34.   rc = fetch_uint32_arg(&delay);
  35.   if(rc)
  36.   {
  37.     // Uses default delay
  38.     delay = 1000 * (kClockRate/10000) * 1.5; // Equal to 1 second
  39.   }
  40.   else
  41.   {
  42.     delay = delay * (kClockRate/10000) * 1.5; // Converts the passed value into ms (milliseconds)
  43.   }
  44.  
  45.   rc = fetch_string_arg(&pchar);
  46.   if(rc)
  47.   {
  48.     // Uses default pattern
  49.     strcpy(pattern, "01234567");
  50.   }
  51.   else
  52.   {
  53.     strcpy(pattern, pchar);
  54.  
  55.     if(strlen(pchar) != 8) // Check if received exactly 8 digits
  56.     {
  57.       printf("ERROR: Invalid number of digits for LED pattern. REQUIRED: 8 digits\n");
  58.       return;
  59.     }
  60.  
  61.     while(*pchar != '\0') // Check if all numbers are valid
  62.     {
  63.       if (*pchar == '9')
  64.       {
  65.         printf("ERROR: 9 is an invalid digit for the pattern. Use only 0 to 8.\n");
  66.         return;
  67.       }
  68.       pchar++;
  69.     }
  70.   }
  71.  
  72.   rc = fetch_uint32_arg(&target);
  73.   if(rc)
  74.   {
  75.     target = 5;
  76.   }
  77.  
  78.   mg_game_demo(delay,pattern,target);
  79. }
  80.  
  81. ADD_CMD("mgGame", mgGame,"\t\t LED Game for Assignment 3")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement