Monitoring du Phytotron
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

7segments.c 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. * DD2 Monitoring
  3. *
  4. * ncurses seven segment display
  5. */
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <ctype.h>
  10. #include <getopt.h>
  11. #include <ncurses.h>
  12. #include "ecran.h"
  13. int verbosity;
  14. /* ---------------------------------------------------------------- */
  15. int aff7segs_base(WINDOW * win, int lig, int col, int bits, int k)
  16. {
  17. int numbit, mask;
  18. int foo;
  19. for (foo=0; foo<9; foo++) {
  20. mvwhline(win, lig+foo, col, '~', 6);
  21. }
  22. #define KC '+'
  23. #define KS "++++"
  24. wstandout(win);
  25. for (numbit=0; numbit<8; numbit++) {
  26. mask = 1 << numbit;
  27. switch(mask & bits) {
  28. case 0x01:
  29. mvwaddstr(win, lig, col+1, KS);
  30. break;
  31. case 0x02:
  32. mvwaddch(win, lig+1, col+5, KC);
  33. mvwaddch(win, lig+2, col+5, KC);
  34. mvwaddch(win, lig+3, col+5, KC);
  35. break;
  36. case 0x04:
  37. mvwaddch(win, lig+5, col+5, KC);
  38. mvwaddch(win, lig+6, col+5, KC);
  39. mvwaddch(win, lig+7, col+5, KC);
  40. break;
  41. case 0x08:
  42. mvwaddstr(win, lig+8, col+1, KS);
  43. break;
  44. case 0x10:
  45. mvwaddch(win, lig+5, col, KC);
  46. mvwaddch(win, lig+6, col, KC);
  47. mvwaddch(win, lig+7, col, KC);
  48. break;
  49. case 0x20:
  50. mvwaddch(win, lig+1, col , KC);
  51. mvwaddch(win, lig+2, col , KC);
  52. mvwaddch(win, lig+3, col , KC);
  53. break;
  54. case 0x40:
  55. mvwaddstr(win, lig+4, col+1, KS);
  56. break;
  57. case 0x80:
  58. /* decimal point */
  59. mvwaddch(win, lig+7, col+2 , KC);
  60. mvwaddch(win, lig+7, col+3 , KC);
  61. mvwaddch(win, lig+8, col+2 , KC);
  62. mvwaddch(win, lig+8, col+3 , KC);
  63. break;
  64. }
  65. }
  66. wstandend(win);
  67. return 0;
  68. }
  69. /* ---------------------------------------------------------------- */
  70. int aff7segs_digit(WINDOW * win, int lig, int col, char digit)
  71. {
  72. int bits;
  73. #if TRACE > 1
  74. fprintf(stderr, ">>> %s ( %p %d %d '%c' )\n", __func__,
  75. win, lig, col, digit);
  76. #endif
  77. if (isxdigit(digit)) digit = toupper(digit);
  78. switch (digit) {
  79. case '0': bits = 0x3f; break;
  80. case '1': bits = 0x06; break;
  81. case '2': bits = 0x5b; break;
  82. case '3': bits = 0x4f; break;
  83. case '4': bits = 0x66; break;
  84. case '5': bits = 0x6d; break;
  85. case '6': bits = 0x7d; break;
  86. case '7': bits = 0x07; break;
  87. case '8': bits = 0x7f; break;
  88. case '9': bits = 0x6f; break;
  89. /* hexadecimal letters */
  90. case 'A': bits = 0x77; break;
  91. case 'B': bits = 0x7c; break;
  92. case 'C': bits = 0x39; break;
  93. case 'D': bits = 0x5e; break;
  94. case 'E': bits = 0x79; break;
  95. case 'F': bits = 0x71; break;
  96. case ' ': bits = 0; break;
  97. case '.': bits = 0x80; break;
  98. case '-': bits = 0x40; break;
  99. default: bits = 0x49; break;
  100. }
  101. aff7segs_base(win, lig, col, bits, 0);
  102. return 0;
  103. }
  104. /* ---------------------------------------------------------------- */
  105. int aff7segs_short(WINDOW * win, int lig, int col, short value)
  106. {
  107. char buff[10];
  108. int idx;
  109. sprintf(buff, "%6d", value);
  110. // mvwaddstr(win, lig-1, col, buff);
  111. for (idx=0; idx<strlen(buff); idx++) {
  112. aff7segs_digit(win, lig, col+(idx*9), buff[idx]);
  113. }
  114. wrefresh(win);
  115. return 0;
  116. }
  117. /* ---------------------------------------------------------------- */
  118. int aff7segs_float(WINDOW * win, int lig, int col, float value)
  119. {
  120. char buff[10];
  121. int idx;
  122. sprintf(buff, "%6.2f", value);
  123. // mvwaddstr(win, lig-1, col, buff);
  124. for (idx=0; idx<strlen(buff); idx++) {
  125. aff7segs_digit(win, lig, col+(idx*9), buff[idx]);
  126. }
  127. wrefresh(win);
  128. return 0;
  129. }
  130. /* ---------------------------------------------------------------- */