PokittoLib with changes to lcd refresh etc.

Dependents:   Pokittris

Fork of Pokitto by Pokitto Community Team

This is a fork by user @Spinal, and is used in Pokittris for testing. Do not import this to your own program.

Committer:
spinal
Date:
Sun Oct 15 18:03:02 2017 +0000
Revision:
11:02ad9c807a21
Parent:
5:7e5c566b1760
fixed 4color refreshRegion code

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Pokitto 5:7e5c566b1760 1 /* mbed Microcontroller Library
Pokitto 5:7e5c566b1760 2 * Copyright (c) 2006-2013 ARM Limited
Pokitto 5:7e5c566b1760 3 *
Pokitto 5:7e5c566b1760 4 * Licensed under the Apache License, Version 2.0 (the "License");
Pokitto 5:7e5c566b1760 5 * you may not use this file except in compliance with the License.
Pokitto 5:7e5c566b1760 6 * You may obtain a copy of the License at
Pokitto 5:7e5c566b1760 7 *
Pokitto 5:7e5c566b1760 8 * http://www.apache.org/licenses/LICENSE-2.0
Pokitto 5:7e5c566b1760 9 *
Pokitto 5:7e5c566b1760 10 * Unless required by applicable law or agreed to in writing, software
Pokitto 5:7e5c566b1760 11 * distributed under the License is distributed on an "AS IS" BASIS,
Pokitto 5:7e5c566b1760 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Pokitto 5:7e5c566b1760 13 * See the License for the specific language governing permissions and
Pokitto 5:7e5c566b1760 14 * limitations under the License.
Pokitto 5:7e5c566b1760 15 */
Pokitto 5:7e5c566b1760 16 #ifndef MBED_CALLCHAIN_H
Pokitto 5:7e5c566b1760 17 #define MBED_CALLCHAIN_H
Pokitto 5:7e5c566b1760 18
Pokitto 5:7e5c566b1760 19 #include "FunctionPointer.h"
Pokitto 5:7e5c566b1760 20 #include <string.h>
Pokitto 5:7e5c566b1760 21
Pokitto 5:7e5c566b1760 22 namespace mbed {
Pokitto 5:7e5c566b1760 23
Pokitto 5:7e5c566b1760 24 /** Group one or more functions in an instance of a CallChain, then call them in
Pokitto 5:7e5c566b1760 25 * sequence using CallChain::call(). Used mostly by the interrupt chaining code,
Pokitto 5:7e5c566b1760 26 * but can be used for other purposes.
Pokitto 5:7e5c566b1760 27 *
Pokitto 5:7e5c566b1760 28 * Example:
Pokitto 5:7e5c566b1760 29 * @code
Pokitto 5:7e5c566b1760 30 * #include "mbed.h"
Pokitto 5:7e5c566b1760 31 *
Pokitto 5:7e5c566b1760 32 * CallChain chain;
Pokitto 5:7e5c566b1760 33 *
Pokitto 5:7e5c566b1760 34 * void first(void) {
Pokitto 5:7e5c566b1760 35 * printf("'first' function.\n");
Pokitto 5:7e5c566b1760 36 * }
Pokitto 5:7e5c566b1760 37 *
Pokitto 5:7e5c566b1760 38 * void second(void) {
Pokitto 5:7e5c566b1760 39 * printf("'second' function.\n");
Pokitto 5:7e5c566b1760 40 * }
Pokitto 5:7e5c566b1760 41 *
Pokitto 5:7e5c566b1760 42 * class Test {
Pokitto 5:7e5c566b1760 43 * public:
Pokitto 5:7e5c566b1760 44 * void f(void) {
Pokitto 5:7e5c566b1760 45 * printf("A::f (class member).\n");
Pokitto 5:7e5c566b1760 46 * }
Pokitto 5:7e5c566b1760 47 * };
Pokitto 5:7e5c566b1760 48 *
Pokitto 5:7e5c566b1760 49 * int main() {
Pokitto 5:7e5c566b1760 50 * Test test;
Pokitto 5:7e5c566b1760 51 *
Pokitto 5:7e5c566b1760 52 * chain.add(second);
Pokitto 5:7e5c566b1760 53 * chain.add_front(first);
Pokitto 5:7e5c566b1760 54 * chain.add(&test, &Test::f);
Pokitto 5:7e5c566b1760 55 * chain.call();
Pokitto 5:7e5c566b1760 56 * }
Pokitto 5:7e5c566b1760 57 * @endcode
Pokitto 5:7e5c566b1760 58 */
Pokitto 5:7e5c566b1760 59
Pokitto 5:7e5c566b1760 60 typedef FunctionPointer* pFunctionPointer_t;
Pokitto 5:7e5c566b1760 61
Pokitto 5:7e5c566b1760 62 class CallChain {
Pokitto 5:7e5c566b1760 63 public:
Pokitto 5:7e5c566b1760 64 /** Create an empty chain
Pokitto 5:7e5c566b1760 65 *
Pokitto 5:7e5c566b1760 66 * @param size (optional) Initial size of the chain
Pokitto 5:7e5c566b1760 67 */
Pokitto 5:7e5c566b1760 68 CallChain(int size = 4);
Pokitto 5:7e5c566b1760 69 virtual ~CallChain();
Pokitto 5:7e5c566b1760 70
Pokitto 5:7e5c566b1760 71 /** Add a function at the end of the chain
Pokitto 5:7e5c566b1760 72 *
Pokitto 5:7e5c566b1760 73 * @param function A pointer to a void function
Pokitto 5:7e5c566b1760 74 *
Pokitto 5:7e5c566b1760 75 * @returns
Pokitto 5:7e5c566b1760 76 * The function object created for 'function'
Pokitto 5:7e5c566b1760 77 */
Pokitto 5:7e5c566b1760 78 pFunctionPointer_t add(void (*function)(void));
Pokitto 5:7e5c566b1760 79
Pokitto 5:7e5c566b1760 80 /** Add a function at the end of the chain
Pokitto 5:7e5c566b1760 81 *
Pokitto 5:7e5c566b1760 82 * @param tptr pointer to the object to call the member function on
Pokitto 5:7e5c566b1760 83 * @param mptr pointer to the member function to be called
Pokitto 5:7e5c566b1760 84 *
Pokitto 5:7e5c566b1760 85 * @returns
Pokitto 5:7e5c566b1760 86 * The function object created for 'tptr' and 'mptr'
Pokitto 5:7e5c566b1760 87 */
Pokitto 5:7e5c566b1760 88 template<typename T>
Pokitto 5:7e5c566b1760 89 pFunctionPointer_t add(T *tptr, void (T::*mptr)(void)) {
Pokitto 5:7e5c566b1760 90 return common_add(new FunctionPointer(tptr, mptr));
Pokitto 5:7e5c566b1760 91 }
Pokitto 5:7e5c566b1760 92
Pokitto 5:7e5c566b1760 93 /** Add a function at the beginning of the chain
Pokitto 5:7e5c566b1760 94 *
Pokitto 5:7e5c566b1760 95 * @param function A pointer to a void function
Pokitto 5:7e5c566b1760 96 *
Pokitto 5:7e5c566b1760 97 * @returns
Pokitto 5:7e5c566b1760 98 * The function object created for 'function'
Pokitto 5:7e5c566b1760 99 */
Pokitto 5:7e5c566b1760 100 pFunctionPointer_t add_front(void (*function)(void));
Pokitto 5:7e5c566b1760 101
Pokitto 5:7e5c566b1760 102 /** Add a function at the beginning of the chain
Pokitto 5:7e5c566b1760 103 *
Pokitto 5:7e5c566b1760 104 * @param tptr pointer to the object to call the member function on
Pokitto 5:7e5c566b1760 105 * @param mptr pointer to the member function to be called
Pokitto 5:7e5c566b1760 106 *
Pokitto 5:7e5c566b1760 107 * @returns
Pokitto 5:7e5c566b1760 108 * The function object created for 'tptr' and 'mptr'
Pokitto 5:7e5c566b1760 109 */
Pokitto 5:7e5c566b1760 110 template<typename T>
Pokitto 5:7e5c566b1760 111 pFunctionPointer_t add_front(T *tptr, void (T::*mptr)(void)) {
Pokitto 5:7e5c566b1760 112 return common_add_front(new FunctionPointer(tptr, mptr));
Pokitto 5:7e5c566b1760 113 }
Pokitto 5:7e5c566b1760 114
Pokitto 5:7e5c566b1760 115 /** Get the number of functions in the chain
Pokitto 5:7e5c566b1760 116 */
Pokitto 5:7e5c566b1760 117 int size() const;
Pokitto 5:7e5c566b1760 118
Pokitto 5:7e5c566b1760 119 /** Get a function object from the chain
Pokitto 5:7e5c566b1760 120 *
Pokitto 5:7e5c566b1760 121 * @param i function object index
Pokitto 5:7e5c566b1760 122 *
Pokitto 5:7e5c566b1760 123 * @returns
Pokitto 5:7e5c566b1760 124 * The function object at position 'i' in the chain
Pokitto 5:7e5c566b1760 125 */
Pokitto 5:7e5c566b1760 126 pFunctionPointer_t get(int i) const;
Pokitto 5:7e5c566b1760 127
Pokitto 5:7e5c566b1760 128 /** Look for a function object in the call chain
Pokitto 5:7e5c566b1760 129 *
Pokitto 5:7e5c566b1760 130 * @param f the function object to search
Pokitto 5:7e5c566b1760 131 *
Pokitto 5:7e5c566b1760 132 * @returns
Pokitto 5:7e5c566b1760 133 * The index of the function object if found, -1 otherwise.
Pokitto 5:7e5c566b1760 134 */
Pokitto 5:7e5c566b1760 135 int find(pFunctionPointer_t f) const;
Pokitto 5:7e5c566b1760 136
Pokitto 5:7e5c566b1760 137 /** Clear the call chain (remove all functions in the chain).
Pokitto 5:7e5c566b1760 138 */
Pokitto 5:7e5c566b1760 139 void clear();
Pokitto 5:7e5c566b1760 140
Pokitto 5:7e5c566b1760 141 /** Remove a function object from the chain
Pokitto 5:7e5c566b1760 142 *
Pokitto 5:7e5c566b1760 143 * @arg f the function object to remove
Pokitto 5:7e5c566b1760 144 *
Pokitto 5:7e5c566b1760 145 * @returns
Pokitto 5:7e5c566b1760 146 * true if the function object was found and removed, false otherwise.
Pokitto 5:7e5c566b1760 147 */
Pokitto 5:7e5c566b1760 148 bool remove(pFunctionPointer_t f);
Pokitto 5:7e5c566b1760 149
Pokitto 5:7e5c566b1760 150 /** Call all the functions in the chain in sequence
Pokitto 5:7e5c566b1760 151 */
Pokitto 5:7e5c566b1760 152 void call();
Pokitto 5:7e5c566b1760 153
Pokitto 5:7e5c566b1760 154 #ifdef MBED_OPERATORS
Pokitto 5:7e5c566b1760 155 void operator ()(void) {
Pokitto 5:7e5c566b1760 156 call();
Pokitto 5:7e5c566b1760 157 }
Pokitto 5:7e5c566b1760 158 pFunctionPointer_t operator [](int i) const {
Pokitto 5:7e5c566b1760 159 return get(i);
Pokitto 5:7e5c566b1760 160 }
Pokitto 5:7e5c566b1760 161 #endif
Pokitto 5:7e5c566b1760 162
Pokitto 5:7e5c566b1760 163 private:
Pokitto 5:7e5c566b1760 164 void _check_size();
Pokitto 5:7e5c566b1760 165 pFunctionPointer_t common_add(pFunctionPointer_t pf);
Pokitto 5:7e5c566b1760 166 pFunctionPointer_t common_add_front(pFunctionPointer_t pf);
Pokitto 5:7e5c566b1760 167
Pokitto 5:7e5c566b1760 168 pFunctionPointer_t* _chain;
Pokitto 5:7e5c566b1760 169 int _size;
Pokitto 5:7e5c566b1760 170 int _elements;
Pokitto 5:7e5c566b1760 171
Pokitto 5:7e5c566b1760 172 /* disallow copy constructor and assignment operators */
Pokitto 5:7e5c566b1760 173 private:
Pokitto 5:7e5c566b1760 174 CallChain(const CallChain&);
Pokitto 5:7e5c566b1760 175 CallChain & operator = (const CallChain&);
Pokitto 5:7e5c566b1760 176 };
Pokitto 5:7e5c566b1760 177
Pokitto 5:7e5c566b1760 178 } // namespace mbed
Pokitto 5:7e5c566b1760 179
Pokitto 5:7e5c566b1760 180 #endif
Pokitto 5:7e5c566b1760 181