Advertisement
Guest User

Untitled

a guest
Jun 30th, 2022
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1. //Perform only when on pins are inputs (at powerup)
  2.   bool testConnection() {
  3.       //Read current polarity config
  4.       const uint16_t old_value;
  5.       if (!this->getPolarity16(old_value) {
  6.         return false;
  7.       }
  8.      
  9.       //Write constant to polarity register
  10.       if (!this->setPolarity16(_connection_test_constant) {
  11.         return false;
  12.       }
  13.      
  14.       //Read current polarity config
  15.       const uint16_t temp;
  16.       if (!this->getPolarity16(temp) {
  17.         return false;
  18.       }
  19.      
  20.       //Write old config to polarity register
  21.       if (!this->setPolarity16(old_value) {
  22.         return false;
  23.       }
  24.      
  25.       if (temp == _connection_test_constant) {
  26.         return true;
  27.       }
  28.      
  29.       return false;
  30.   }
  31.  
  32. //Somewhere in the class private
  33. const uint16_t _connection_test_constant = 0xAABB;
  34.  
  35. //any arbitrary value, but not 0 or 0xFFFF (on teensy an unconnected spi transfer will return 0, but I don't know about other platforms)
  36.          
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement