Advertisement
Guest User

outside loop, not working

a guest
Jan 24th, 2015
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.11 KB | None | 0 0
  1. -----------------------------------
  2. **********DcsBios.h**********
  3. ------------------------------------
  4.  
  5. #ifndef __DCSBIOS_H
  6. extern unsigned int pinValues;
  7.  
  8. [...]
  9.  
  10. class Switch2PosSR : PollingInput {
  11.     private:
  12.         void pollInput();
  13.         char* msg_;
  14.         char srinput_;
  15.         int lastState_;
  16.         unsigned int pinValues_;
  17.     public:
  18.         Switch2PosSR(char* msg, char srinput);
  19. };
  20.  
  21. [...]
  22.  
  23. -----------------------------------
  24. **********DcsBios.cpp**********
  25. ------------------------------------
  26.  
  27. [...]
  28.  
  29. Switch2PosSR::Switch2PosSR(char* msg, char srinput) {
  30.     msg_ = msg;
  31.     srinput_ = srinput;
  32.     pinValues_ = pinValues;
  33.     lastState_ = pinValues_ & (1<< srinput_);
  34. }
  35. void Switch2PosSR::pollInput() {
  36.    
  37.      int state = pinValues_ & (1<< srinput_);
  38.    
  39.     if (state != lastState_) {
  40.    
  41.         sendDcsBiosMessage(msg_, state == 0 ? "0" : "1");
  42.     }
  43.     lastState_ = state;
  44. }
  45.  
  46. [...]
  47.  
  48. -----------------------------
  49. *********.INO FILE:********
  50. ---------------------------------
  51.  
  52. #include <DcsBios.h>
  53. #include <Servo.h>
  54.  
  55.  
  56. DcsBios::ActionButton ahcpHudModeToggle("AHCP_HUD_MODE", "TOGGLE", 44);
  57. DcsBios::Switch2PosSR ahcpCicu("AHCP_CICU", 1);
  58.  
  59.  
  60. int ploadPin        = 2;  // Connects to Parallel load pin the 165
  61. int dataPin         = 3; // Connects to the Q7 pin the 165
  62. int clockPin        = 4; // Connects to the Clock pin the 165
  63.  
  64.  
  65. unsigned int pinValues = read_shift_regs();
  66. unsigned int oldPinValues;
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74. unsigned int read_shift_regs()
  75. {
  76.     byte bitVal;
  77.     unsigned int bytesVal = 0;
  78.  
  79.     /* Trigger a parallel Load to latch the state of the data lines,
  80.     */
  81.     digitalWrite(ploadPin, LOW);
  82.     delayMicroseconds(5);
  83.     digitalWrite(ploadPin, HIGH);
  84.  
  85.     /* Loop to read each bit value from the serial out line
  86.      * of the SN74HC165N.
  87.     */
  88.     for(int i = 0; i < 8; i++)
  89.     {
  90.         bitVal = digitalRead(dataPin);
  91.  
  92.         /* Set the corresponding bit in bytesVal.
  93.         */
  94.         bytesVal |= (bitVal << ((8-1) - i));
  95.  
  96.         /* Pulse the Clock (rising edge shifts the next bit).
  97.         */
  98.         digitalWrite(clockPin, HIGH);
  99.         delayMicroseconds(5);
  100.         digitalWrite(clockPin, LOW);
  101.     }
  102.  
  103.     return(bytesVal);
  104. }
  105.  
  106.  
  107. DcsBios::ProtocolParser parser;
  108.  
  109. void setup() {
  110.   Serial.begin(500000);
  111.  
  112. /* Initialize our digital pins...
  113.     */
  114.     pinMode(ploadPin, OUTPUT);
  115.     pinMode(clockPin, OUTPUT);
  116.     pinMode(dataPin, INPUT);
  117.  
  118.     digitalWrite(clockPin, LOW);
  119.     digitalWrite(ploadPin, HIGH);
  120.  
  121.     /* Read in and display the pin states at startup.
  122.     */
  123.     pinValues = read_shift_regs();
  124.    
  125.     oldPinValues = pinValues;
  126.    
  127.    
  128. }
  129.  
  130. void loop() {
  131.  
  132.   // feed incoming data to the parser
  133.   while (Serial.available()) {
  134.       parser.processChar(Serial.read());
  135.   }
  136.     // poll inputs
  137.   DcsBios::PollingInput::pollInputs();
  138.  
  139.  
  140.    pinValues = read_shift_regs();
  141.    oldPinValues = pinValues;
  142.    
  143.  
  144.    
  145.    
  146.    
  147.    
  148.    
  149.     }
  150.    
  151.  
  152. void sendDcsBiosMessage(const char* msg, const char* arg) {
  153.   Serial.write(msg);
  154.   Serial.write(' ');
  155.   Serial.write(arg);
  156.   Serial.write('\n');
  157. }
  158.  
  159.  
  160. void onDcsBiosWrite(unsigned int address, unsigned int value) {
  161.  
  162. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement