Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -----------------------------------
- **********DcsBios.h**********
- ------------------------------------
- #ifndef __DCSBIOS_H
- extern unsigned int pinValues;
- [...]
- class Switch2PosSR : PollingInput {
- private:
- void pollInput();
- char* msg_;
- char srinput_;
- int lastState_;
- unsigned int pinValues_;
- public:
- Switch2PosSR(char* msg, char srinput);
- };
- [...]
- -----------------------------------
- **********DcsBios.cpp**********
- ------------------------------------
- [...]
- Switch2PosSR::Switch2PosSR(char* msg, char srinput) {
- msg_ = msg;
- srinput_ = srinput;
- pinValues_ = pinValues;
- lastState_ = pinValues_ & (1<< srinput_);
- }
- void Switch2PosSR::pollInput() {
- int state = pinValues_ & (1<< srinput_);
- if (state != lastState_) {
- sendDcsBiosMessage(msg_, state == 0 ? "0" : "1");
- }
- lastState_ = state;
- }
- [...]
- -----------------------------
- *********.INO FILE:********
- ---------------------------------
- #include <DcsBios.h>
- #include <Servo.h>
- DcsBios::ActionButton ahcpHudModeToggle("AHCP_HUD_MODE", "TOGGLE", 44);
- DcsBios::Switch2PosSR ahcpCicu("AHCP_CICU", 1);
- int ploadPin = 2; // Connects to Parallel load pin the 165
- int dataPin = 3; // Connects to the Q7 pin the 165
- int clockPin = 4; // Connects to the Clock pin the 165
- unsigned int pinValues = read_shift_regs();
- unsigned int oldPinValues;
- unsigned int read_shift_regs()
- {
- byte bitVal;
- unsigned int bytesVal = 0;
- /* Trigger a parallel Load to latch the state of the data lines,
- */
- digitalWrite(ploadPin, LOW);
- delayMicroseconds(5);
- digitalWrite(ploadPin, HIGH);
- /* Loop to read each bit value from the serial out line
- * of the SN74HC165N.
- */
- for(int i = 0; i < 8; i++)
- {
- bitVal = digitalRead(dataPin);
- /* Set the corresponding bit in bytesVal.
- */
- bytesVal |= (bitVal << ((8-1) - i));
- /* Pulse the Clock (rising edge shifts the next bit).
- */
- digitalWrite(clockPin, HIGH);
- delayMicroseconds(5);
- digitalWrite(clockPin, LOW);
- }
- return(bytesVal);
- }
- DcsBios::ProtocolParser parser;
- void setup() {
- Serial.begin(500000);
- /* Initialize our digital pins...
- */
- pinMode(ploadPin, OUTPUT);
- pinMode(clockPin, OUTPUT);
- pinMode(dataPin, INPUT);
- digitalWrite(clockPin, LOW);
- digitalWrite(ploadPin, HIGH);
- /* Read in and display the pin states at startup.
- */
- pinValues = read_shift_regs();
- oldPinValues = pinValues;
- }
- void loop() {
- // feed incoming data to the parser
- while (Serial.available()) {
- parser.processChar(Serial.read());
- }
- // poll inputs
- DcsBios::PollingInput::pollInputs();
- pinValues = read_shift_regs();
- oldPinValues = pinValues;
- }
- void sendDcsBiosMessage(const char* msg, const char* arg) {
- Serial.write(msg);
- Serial.write(' ');
- Serial.write(arg);
- Serial.write('\n');
- }
- void onDcsBiosWrite(unsigned int address, unsigned int value) {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement