Rotary encoder library. Add: void setInterval(timestamp_t t) for Nucleo F401RE
Fork of RotaryEncoder by
RotaryEncoder.h
00001 /** 00002 * ============================================================================= 00003 * Rotary Encoder class (Version 0.0.1) 00004 * ============================================================================= 00005 * Copyright (c) 2010 Shinichiro Nakamura (CuBeatSystems) 00006 * 00007 * Permission is hereby granted, free of charge, to any person obtaining a copy 00008 * of this software and associated documentation files (the "Software"), to deal 00009 * in the Software without restriction, including without limitation the rights 00010 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00011 * copies of the Software, and to permit persons to whom the Software is 00012 * furnished to do so, subject to the following conditions: 00013 * 00014 * The above copyright notice and this permission notice shall be included in 00015 * all copies or substantial portions of the Software. 00016 * 00017 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00018 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00019 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00020 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00021 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00022 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00023 * THE SOFTWARE. 00024 * ============================================================================= 00025 */ 00026 00027 #ifndef ROTARY_ENCODER_H 00028 #define ROTARY_ENCODER_H 00029 00030 #include "mbed.h" 00031 00032 /** 00033 */ 00034 class RotaryEncoder 00035 { 00036 public: 00037 /** 00038 * Create rotary encoder. 00039 * 00040 * @param pin1_name 00041 * @param pin2_name 00042 * @param min Minimum value. 00043 * @param max Maximum value. 00044 * @param val Default value. 00045 */ 00046 RotaryEncoder(PinName pin1_name, PinName pin2_name, int min = 0, int max = 100, int val = 50); 00047 00048 /** 00049 * Dispose. 00050 */ 00051 ~RotaryEncoder(); 00052 00053 /** 00054 * Get the minimum value. 00055 * 00056 * @return The minimum value. 00057 */ 00058 int getMin() const { 00059 return min; 00060 } 00061 00062 /** 00063 * Get the maximum value. 00064 * 00065 * @return The maximum value. 00066 */ 00067 int getMax() const { 00068 return max; 00069 } 00070 00071 /** 00072 * Get the value. 00073 * 00074 * @return The value. 00075 */ 00076 int getVal() const { 00077 return val; 00078 } 00079 00080 /** 00081 * Set the value. 00082 * 00083 * @param The value. 00084 */ 00085 void setVal(int _val) { 00086 if (min <= _val && _val <= max) { 00087 val = _val; 00088 } 00089 } 00090 00091 /** 00092 * Set the ticker interval. 00093 * 00094 * @param The interval in microseconds. 00095 */ 00096 void setInterval(us_timestamp_t t) { 00097 interval = t; 00098 ticker.attach_us(callback(this, &RotaryEncoder::func_ticker), t); 00099 } 00100 00101 /** 00102 * Get the ticker interval. 00103 * 00104 * @return the ticker interval. 00105 */ 00106 us_timestamp_t getInterval() const { 00107 return interval; 00108 } 00109 00110 private: 00111 DigitalIn pin1; 00112 DigitalIn pin2; 00113 const int min; 00114 const int max; 00115 int val; 00116 us_timestamp_t interval; 00117 Ticker ticker; 00118 00119 uint8_t code; 00120 00121 /** 00122 * Internal tick function. 00123 */ 00124 void func_ticker(); 00125 }; 00126 00127 #endif
Generated on Sun Jul 24 2022 19:48:10 by 1.7.2