The codebase to run the *spark d-fuser controller www.sparkav.co.uk/dvimixer
Dependencies: SPK-TVOne DMX DmxArtNet NetServicesMin OSC PinDetect mRotaryEncoder iniparser mbed spk_oled_ssd1305 filter
spk_mRotaryEncoder.h
00001 // *SPARK D-FUSER 00002 // A project by Toby Harris 00003 // Copyright *spark audio-visual 2012 00004 // 00005 // spkRotaryEncoder extends mRotaryEncoder to return the change on pot state since last queried 00006 // This allows the encoder to be polled when the host program is ready, and return info suitable for driving a TVOne style menu 00007 // Importantly to driving such a menu, it will ignore any further rotation after the switch is pressed. 00008 00009 #include "mRotaryEncoder.h" 00010 00011 class SPKRotaryEncoder : public mRotaryEncoder { 00012 00013 public: 00014 bool hasPressed(); 00015 int getChange(); 00016 int getPos(); // This would be a Get() override, but its not virtual. We use this instead to correct for positions-per-detent 00017 SPKRotaryEncoder(PinName pinA, PinName pinB, PinName pinSW, PinMode pullMode=PullUp, int debounceTime_us=1000); 00018 00019 private: 00020 void onPress(); 00021 bool m_hasPressed; 00022 int m_positionOld; 00023 int m_positionOnPress; 00024 00025 }; 00026 00027 SPKRotaryEncoder::SPKRotaryEncoder(PinName pinA, PinName pinB, PinName pinSW, PinMode pullMode, int debounceTime_us) : mRotaryEncoder(pinA, pinB, pinSW, pullMode, debounceTime_us) 00028 { 00029 attachSW(this,&SPKRotaryEncoder::onPress); 00030 } 00031 00032 bool SPKRotaryEncoder::hasPressed() 00033 { 00034 bool hasPressed = m_hasPressed; 00035 m_hasPressed = false; 00036 00037 return hasPressed; 00038 } 00039 00040 int SPKRotaryEncoder::getChange() 00041 { 00042 int positionEnc = this->getPos(); 00043 00044 int positionToUse = m_hasPressed ? m_positionOnPress : positionEnc; 00045 int change = positionToUse - m_positionOld; 00046 00047 m_positionOld = positionEnc; 00048 00049 return change; 00050 } 00051 00052 int SPKRotaryEncoder::getPos() 00053 { 00054 int positionEnc = this->Get(); 00055 int positionsPerDetent = 2; 00056 00057 return positionEnc / positionsPerDetent; 00058 } 00059 00060 void SPKRotaryEncoder::onPress() 00061 { 00062 m_positionOnPress = this->getPos(); 00063 m_hasPressed = true; 00064 }
Generated on Tue Jul 12 2022 21:39:05 by 1.7.2