Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /*
  2. * scphat.c:
  3. * Little program to allow use of the Pimoroni Scroll pHAT
  4. * from the command-line.
  5. *
  6. * Copyright (c) 2015-2016 Gordon Henderson.
  7. ***********************************************************************
  8. * This file is part of wiringPi:
  9. * https://github.com/WiringPi/WiringPi
  10. *
  11. * wiringPi is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Lesser General Public License as published by
  13. * the Free Software Foundation, either version 3 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * wiringPi is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Lesser General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Lesser General Public License
  22. * along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
  23. ***********************************************************************
  24. */
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include <errno.h>
  28. #include <string.h>
  29. #include <wiringPi.h>
  30. #include <scrollPhat.h>
  31. static char *progName ;
  32. /*
  33. * checkArgs:
  34. * Count the arguments for each little function
  35. *********************************************************************************
  36. */
  37. static void checkArgs (char *command, int num, int arg, int argc)
  38. {
  39. if ((arg + num) < argc)
  40. return ;
  41. fprintf (stderr, "%s: Not enough data for %s command.\n", progName, command) ;
  42. exit (EXIT_FAILURE) ;
  43. }
  44. /*
  45. * doClear:
  46. * Clear the display
  47. *********************************************************************************
  48. */
  49. static int doClear (void)
  50. {
  51. scrollPhatClear () ;
  52. return 1 ;
  53. }
  54. /*
  55. * doBright
  56. *********************************************************************************
  57. */
  58. static int doBright (int arg, int argc, char *argv [])
  59. {
  60. checkArgs ("bright", 1, arg, argc) ;
  61. scrollPhatIntensity (atoi (argv [arg+1])) ;
  62. return 2 ;
  63. }
  64. /*
  65. * doPlot
  66. *********************************************************************************
  67. */
  68. static int doPlot (int arg, int argc, char *argv [])
  69. {
  70. checkArgs ("plot", 2, arg, argc) ;
  71. scrollPhatPoint (atoi (argv [arg+1]), atoi (argv [arg+2]), 1) ;
  72. scrollPhatUpdate () ;
  73. return 3 ;
  74. }
  75. /*
  76. * doLine
  77. *********************************************************************************
  78. */
  79. static int doLine (int arg, int argc, char *argv [])
  80. {
  81. checkArgs ("line", 4, arg, argc) ;
  82. scrollPhatLine (atoi (argv [arg+1]), atoi (argv [arg+2]),
  83. atoi (argv [arg+3]), atoi (argv [arg+4]), 1) ;
  84. scrollPhatUpdate () ;
  85. return 5 ;
  86. }
  87. /*
  88. * doLineTo
  89. *********************************************************************************
  90. */
  91. static int doLineTo (int arg, int argc, char *argv [])
  92. {
  93. checkArgs ("lineto", 2, arg, argc) ;
  94. scrollPhatLineTo (atoi (argv [arg+1]), atoi (argv [arg+2]), 1) ;
  95. scrollPhatUpdate () ;
  96. return 3 ;
  97. }
  98. /*
  99. * doWait
  100. *********************************************************************************
  101. */
  102. static int doWait (int arg, int argc, char *argv [])
  103. {
  104. checkArgs ("wait", 1, arg, argc) ;
  105. delay (atoi (argv [arg+1]) * 100) ;
  106. scrollPhatUpdate () ;
  107. return 2 ;
  108. }
  109. /*
  110. * doSpeed
  111. *********************************************************************************
  112. */
  113. static int doSpeed (int arg, int argc, char *argv [])
  114. {
  115. checkArgs ("speed", 1, arg, argc) ;
  116. scrollPhatPrintSpeed (atoi (argv [arg+1])) ;
  117. return 2 ;
  118. }
  119. /*
  120. * doScroll
  121. *********************************************************************************
  122. */
  123. static int doScroll (int arg, int argc, char *argv [])
  124. {
  125. checkArgs ("scroll", 1, arg, argc) ;
  126. scrollPhatPuts (argv [arg+1]) ;
  127. return 2 ;
  128. }
  129. static void failUsage (void)
  130. {
  131. fprintf (stderr, "Usage: %s command [paremters] ...\n", progName) ;
  132. fprintf (stderr, " commands:\n") ;
  133. fprintf (stderr, " clear/cls - Clear the display\n") ;
  134. fprintf (stderr, " bright N - Set display brightness; 1-100\n") ;
  135. fprintf (stderr, " plot X Y - Set a single pixel at location X Y; 0-10, 0-4\n") ;
  136. fprintf (stderr, " line X1 Y1 X2 Y2 - Draw a line from the 2 points\n") ;
  137. fprintf (stderr, " lineto X2 Y2 - Draw a line from the last point to the new one\n") ;
  138. fprintf (stderr, " wait/delay N - Wait for N 10ths seconds\n") ;
  139. fprintf (stderr, " speed N - Set scrolling speed (cps)\n") ;
  140. fprintf (stderr, " scroll S - Scroll the given string\n") ;
  141. fprintf (stderr, "\n") ;
  142. fprintf (stderr, " Example: %s plot 0 0 wait 50 scroll \" Hello \"\n", progName) ;
  143. exit (EXIT_FAILURE) ;
  144. }
  145. /*
  146. * the works
  147. *********************************************************************************
  148. */
  149. int main (int argc, char *argv [])
  150. {
  151. int arg = 1 ;
  152. char *command ;
  153. progName = argv [0] ;
  154. wiringPiSetupSys () ;
  155. if (scrollPhatSetup () != 0)
  156. {
  157. fprintf (stderr, "%s: Unable to initialise the scrollPhat: %s\n", progName, strerror (errno)) ;
  158. exit (EXIT_FAILURE) ;
  159. }
  160. progName = argv [0] ;
  161. if (argc < 2)
  162. {
  163. fprintf (stderr, "%s: Nothing to do...\n", argv [0]) ;
  164. failUsage () ;
  165. }
  166. while (arg != argc)
  167. {
  168. command = argv [arg] ;
  169. /**/ if (strcasecmp (command, "clear") == 0) arg += doClear () ;
  170. else if (strcasecmp (command, "cls") == 0) arg += doClear () ;
  171. else if (strcasecmp (command, "bright") == 0) arg += doBright (arg, argc, argv) ;
  172. else if (strcasecmp (command, "plot") == 0) arg += doPlot (arg, argc, argv) ;
  173. else if (strcasecmp (command, "line") == 0) arg += doLine (arg, argc, argv) ;
  174. else if (strcasecmp (command, "lineto") == 0) arg += doLineTo (arg, argc, argv) ;
  175. else if (strcasecmp (command, "wait") == 0) arg += doWait (arg, argc, argv) ;
  176. else if (strcasecmp (command, "delay") == 0) arg += doWait (arg, argc, argv) ;
  177. else if (strcasecmp (command, "speed") == 0) arg += doSpeed (arg, argc, argv) ;
  178. else if (strcasecmp (command, "scroll") == 0) arg += doScroll (arg, argc, argv) ;
  179. else
  180. {
  181. fprintf (stderr, "%s: Unknown command: %s.\n", argv [0], argv [arg]) ;
  182. failUsage () ;
  183. }
  184. }
  185. return 0 ;
  186. }