Ryo Od / ExioController
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ExioMcp23s17RotaryEncoder.h Source File

ExioMcp23s17RotaryEncoder.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 /*
00028  * 2016.11.02 Customized for MCP23S17 by rood
00029  */
00030  
00031 #ifndef EXIOMCP23S17ROTARY_ENCODER_H
00032 #define EXIOMCP23S17ROTARY_ENCODER_H
00033 
00034 #include "mbed.h"
00035 #include "ExioMcp23s17DigitalIn.h"
00036 
00037 /**
00038  */
00039 class ExioMcp23s17RotaryEncoder
00040 {
00041 public:
00042     /**
00043      * Create rotary encoder.
00044      * @param device
00045      * @param port
00046      * @param pin1
00047      * @param pin2
00048      * @param min Minimum value.
00049      * @param max Maximum value.
00050      * @param val Default value.
00051      */
00052      
00053     //RotaryEncoder(PinName pin1_name, PinName pin2_name, int min = 0, int max = 100, int val = 50);
00054     ExioMcp23s17RotaryEncoder(
00055         ExioMcp23s17* pDevice, ExioPort port, int pin1_n, int pin2_n,
00056         int min = 0, int max = 100, int val = 50
00057     );
00058 
00059     /**
00060      * Dispose.
00061      */
00062     ~ExioMcp23s17RotaryEncoder();
00063 
00064     /**
00065      * Get the minimum value.
00066      *
00067      * @return The minimum value.
00068      */
00069     int getMin() const {
00070         return min;
00071     }
00072 
00073     /**
00074      * Get the maximum value.
00075      *
00076      * @return The maximum value.
00077      */
00078     int getMax() const {
00079         return max;
00080     }
00081 
00082     /**
00083      * Get the value.
00084      *
00085      * @return The value.
00086      */
00087     int getVal() const {
00088         return val;
00089     }
00090 
00091     /**
00092      * Set the value.
00093      *
00094      * @param The value.
00095      */
00096     void setVal(int _val) {
00097         if (min <= _val && _val <= max) {
00098             val = _val;
00099         }
00100     }
00101     
00102     /**
00103     * Set the ticker interval.
00104     *
00105     * @param The interval in microseconds.
00106     */
00107     void setInterval(timestamp_t t) {
00108         ticker.attach_us(this, &ExioMcp23s17RotaryEncoder::func_ticker, t);
00109     }
00110 
00111 private:
00112     ExioMcp23s17DigitalIn* in1;
00113     ExioMcp23s17DigitalIn* in2;
00114     const int min;
00115     const int max;
00116     int val;
00117     Ticker ticker;
00118 
00119     uint8_t code;
00120 
00121     /**
00122      * Internal tick function.
00123      */
00124     void func_ticker();
00125 };
00126 
00127 #endif