Advertisement
ClayM1

Untitled

Apr 16th, 2015
820
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.35 KB | None | 0 0
  1. #include <LedControl.h>
  2. #include <DcsBios.h>
  3. #include <Servo.h>
  4.  
  5.  
  6. //pin 10 is connected to the DataIn
  7. //pin 11 is connected to the CLK
  8. //pin 12 is connected to LOAD
  9. LedControl lc=LedControl(10,9,8,1);//DIN,CLK,LOAD,# OF IC's
  10.  
  11. /**** In most cases, you do not have to change anything below this line ****/
  12.  
  13. /* Instantiate a ProtocolParser object to parse the DCS-BIOS export stream */
  14. DcsBios::ProtocolParser parser;
  15.  
  16. void setup() {
  17. Serial.begin(250000);
  18.  
  19. lc.shutdown(0,false); //turn on the display
  20. lc.setIntensity(0,15);//set the brightness
  21. lc.clearDisplay(0); //clear rthe display and get ready for new data
  22. }
  23.  
  24. /*
  25. Your main loop needs to pass data from the DCS-BIOS export
  26. stream to the parser object you instantiated above.
  27.  
  28. It also needs to call DcsBios::PollingInput::pollInputs()
  29. to detect changes in the state of connected controls and
  30. pass them on to DCS.
  31. */
  32. void loop() {
  33. // feed incoming data to the parser
  34. while (Serial.available()) {
  35. parser.processChar(Serial.read());
  36. }
  37.  
  38. // poll inputs
  39. DcsBios::PollingInput::pollInputs();
  40. }
  41.  
  42. /*
  43. You need to define
  44. void sendDcsBiosMessage(const char* msg, const char* arg)
  45. so that the string msg, followed by a space, the string arg
  46. and a newline gets sent to the DCS-BIOS import stream.
  47.  
  48. In this example we send it to the serial port, so you need to
  49. run socat to read the data from the serial port and send it
  50. over UDP to DCS-BIOS.
  51. */
  52.  
  53. void sendDcsBiosMessage(const char* msg, const char* arg) {
  54. Serial.write(msg);
  55. Serial.write(' ');
  56. Serial.write(arg);
  57. Serial.write('\n');
  58. }
  59.  
  60. unsigned char max7219_rows[8];
  61. unsigned char cl_row_map[48] = {
  62. 0, 0, 0, 0,
  63. 1, 1, 1, 1,
  64. 2, 2, 2, 2,
  65. 3, 3, 3, 3,
  66. 4, 4, 4, 4,
  67. 5, 5, 5, 5,
  68. 0, 0, 0, 0,
  69. 1, 1, 1, 1,
  70. 2, 2, 2, 2,
  71. 3, 3, 3, 3,
  72. 4, 4, 4, 4,
  73. 5, 5, 5, 5
  74. };
  75. #define SEG_DP (1<<7)
  76. #define SEG_A (1<<6)
  77. #define SEG_B (1<<5)
  78. #define SEG_C (1<<4)
  79. #define SEG_D (1<<3)
  80. #define SEG_E (1<<2)
  81. #define SEG_F (1<<1)
  82. #define SEG_G (1<<0)
  83. unsigned char cl_mask_map[48]= {
  84. SEG_DP, SEG_B, SEG_D, SEG_F,
  85. SEG_DP, SEG_B, SEG_D, SEG_F,
  86. SEG_DP, SEG_B, SEG_D, SEG_F,
  87. SEG_DP, SEG_B, SEG_D, SEG_F,
  88. SEG_DP, SEG_B, SEG_D, SEG_F,
  89. SEG_DP, SEG_B, SEG_D, SEG_F,
  90. SEG_A, SEG_C, SEG_E, SEG_G,
  91. SEG_A, SEG_C, SEG_E, SEG_G,
  92. SEG_A, SEG_C, SEG_E, SEG_G,
  93. SEG_A, SEG_C, SEG_E, SEG_G,
  94. SEG_A, SEG_C, SEG_E, SEG_G,
  95. SEG_A, SEG_C, SEG_E, SEG_G
  96. };
  97. void updateCautionLights(unsigned int address, unsigned int data) {
  98. unsigned char row = (address - 0x10d4) * 2;
  99. unsigned char start_index = row * 4;
  100. unsigned char column = 0;
  101. unsigned char i;
  102.  
  103. bool is_on;
  104. for (i=0; i<16; i++) {
  105. is_on = data & 0x01;
  106. // set caution light state (row, column, is_on)
  107. if (is_on) {
  108. max7219_rows[cl_row_map[start_index+i]] |= cl_mask_map[start_index+i];
  109. } else {
  110. max7219_rows[cl_row_map[start_index+i]] &= ~(cl_mask_map[start_index+i]);
  111. }
  112. data >>= 1;
  113. column++;
  114. if (column == 4) {
  115. row++;
  116. column = 0;
  117. }
  118. }
  119.  
  120. // update MAX7219
  121. for (i=0; i<8; i++) {
  122. lc.setRow(0, i, max7219_rows[i]);
  123. }
  124. }
  125. void onDcsBiosWrite(unsigned int address, unsigned int data) {
  126. if (address >= 0x10d4 && address <= 0x10d8) {
  127. updateCautionLights(address, data);
  128. }
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement