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_TICKER_H
Pokitto 5:7e5c566b1760 17 #define MBED_TICKER_H
Pokitto 5:7e5c566b1760 18
Pokitto 5:7e5c566b1760 19 #include "TimerEvent.h"
Pokitto 5:7e5c566b1760 20 #include "FunctionPointer.h"
Pokitto 5:7e5c566b1760 21
Pokitto 5:7e5c566b1760 22 namespace mbed {
Pokitto 5:7e5c566b1760 23
Pokitto 5:7e5c566b1760 24 /** A Ticker is used to call a function at a recurring interval
Pokitto 5:7e5c566b1760 25 *
Pokitto 5:7e5c566b1760 26 * You can use as many seperate Ticker objects as you require.
Pokitto 5:7e5c566b1760 27 *
Pokitto 5:7e5c566b1760 28 * Example:
Pokitto 5:7e5c566b1760 29 * @code
Pokitto 5:7e5c566b1760 30 * // Toggle the blinking led after 5 seconds
Pokitto 5:7e5c566b1760 31 *
Pokitto 5:7e5c566b1760 32 * #include "mbed.h"
Pokitto 5:7e5c566b1760 33 *
Pokitto 5:7e5c566b1760 34 * Ticker timer;
Pokitto 5:7e5c566b1760 35 * DigitalOut led1(LED1);
Pokitto 5:7e5c566b1760 36 * DigitalOut led2(LED2);
Pokitto 5:7e5c566b1760 37 *
Pokitto 5:7e5c566b1760 38 * int flip = 0;
Pokitto 5:7e5c566b1760 39 *
Pokitto 5:7e5c566b1760 40 * void attime() {
Pokitto 5:7e5c566b1760 41 * flip = !flip;
Pokitto 5:7e5c566b1760 42 * }
Pokitto 5:7e5c566b1760 43 *
Pokitto 5:7e5c566b1760 44 * int main() {
Pokitto 5:7e5c566b1760 45 * timer.attach(&attime, 5);
Pokitto 5:7e5c566b1760 46 * while(1) {
Pokitto 5:7e5c566b1760 47 * if(flip == 0) {
Pokitto 5:7e5c566b1760 48 * led1 = !led1;
Pokitto 5:7e5c566b1760 49 * } else {
Pokitto 5:7e5c566b1760 50 * led2 = !led2;
Pokitto 5:7e5c566b1760 51 * }
Pokitto 5:7e5c566b1760 52 * wait(0.2);
Pokitto 5:7e5c566b1760 53 * }
Pokitto 5:7e5c566b1760 54 * }
Pokitto 5:7e5c566b1760 55 * @endcode
Pokitto 5:7e5c566b1760 56 */
Pokitto 5:7e5c566b1760 57 class Ticker : public TimerEvent {
Pokitto 5:7e5c566b1760 58
Pokitto 5:7e5c566b1760 59 public:
Pokitto 5:7e5c566b1760 60 Ticker() : TimerEvent() {
Pokitto 5:7e5c566b1760 61 }
Pokitto 5:7e5c566b1760 62
Pokitto 5:7e5c566b1760 63 Ticker(const ticker_data_t *data) : TimerEvent(data) {
Pokitto 5:7e5c566b1760 64 }
Pokitto 5:7e5c566b1760 65
Pokitto 5:7e5c566b1760 66 /** Attach a function to be called by the Ticker, specifiying the interval in seconds
Pokitto 5:7e5c566b1760 67 *
Pokitto 5:7e5c566b1760 68 * @param fptr pointer to the function to be called
Pokitto 5:7e5c566b1760 69 * @param t the time between calls in seconds
Pokitto 5:7e5c566b1760 70 */
Pokitto 5:7e5c566b1760 71 void attach(void (*fptr)(void), float t) {
Pokitto 5:7e5c566b1760 72 attach_us(fptr, t * 1000000.0f);
Pokitto 5:7e5c566b1760 73 }
Pokitto 5:7e5c566b1760 74
Pokitto 5:7e5c566b1760 75 /** Attach a member function to be called by the Ticker, specifiying the interval in seconds
Pokitto 5:7e5c566b1760 76 *
Pokitto 5:7e5c566b1760 77 * @param tptr pointer to the object to call the member function on
Pokitto 5:7e5c566b1760 78 * @param mptr pointer to the member function to be called
Pokitto 5:7e5c566b1760 79 * @param t the time between calls in seconds
Pokitto 5:7e5c566b1760 80 */
Pokitto 5:7e5c566b1760 81 template<typename T>
Pokitto 5:7e5c566b1760 82 void attach(T* tptr, void (T::*mptr)(void), float t) {
Pokitto 5:7e5c566b1760 83 attach_us(tptr, mptr, t * 1000000.0f);
Pokitto 5:7e5c566b1760 84 }
Pokitto 5:7e5c566b1760 85
Pokitto 5:7e5c566b1760 86 /** Attach a function to be called by the Ticker, specifiying the interval in micro-seconds
Pokitto 5:7e5c566b1760 87 *
Pokitto 5:7e5c566b1760 88 * @param fptr pointer to the function to be called
Pokitto 5:7e5c566b1760 89 * @param t the time between calls in micro-seconds
Pokitto 5:7e5c566b1760 90 */
Pokitto 5:7e5c566b1760 91 void attach_us(void (*fptr)(void), timestamp_t t) {
Pokitto 5:7e5c566b1760 92 _function.attach(fptr);
Pokitto 5:7e5c566b1760 93 setup(t);
Pokitto 5:7e5c566b1760 94 }
Pokitto 5:7e5c566b1760 95
Pokitto 5:7e5c566b1760 96 /** Attach a member function to be called by the Ticker, specifiying the interval in micro-seconds
Pokitto 5:7e5c566b1760 97 *
Pokitto 5:7e5c566b1760 98 * @param tptr pointer to the object to call the member function on
Pokitto 5:7e5c566b1760 99 * @param mptr pointer to the member function to be called
Pokitto 5:7e5c566b1760 100 * @param t the time between calls in micro-seconds
Pokitto 5:7e5c566b1760 101 */
Pokitto 5:7e5c566b1760 102 template<typename T>
Pokitto 5:7e5c566b1760 103 void attach_us(T* tptr, void (T::*mptr)(void), timestamp_t t) {
Pokitto 5:7e5c566b1760 104 _function.attach(tptr, mptr);
Pokitto 5:7e5c566b1760 105 setup(t);
Pokitto 5:7e5c566b1760 106 }
Pokitto 5:7e5c566b1760 107
Pokitto 5:7e5c566b1760 108 virtual ~Ticker() {
Pokitto 5:7e5c566b1760 109 detach();
Pokitto 5:7e5c566b1760 110 }
Pokitto 5:7e5c566b1760 111
Pokitto 5:7e5c566b1760 112 /** Detach the function
Pokitto 5:7e5c566b1760 113 */
Pokitto 5:7e5c566b1760 114 void detach();
Pokitto 5:7e5c566b1760 115
Pokitto 5:7e5c566b1760 116 protected:
Pokitto 5:7e5c566b1760 117 void setup(timestamp_t t);
Pokitto 5:7e5c566b1760 118 virtual void handler();
Pokitto 5:7e5c566b1760 119
Pokitto 5:7e5c566b1760 120 protected:
Pokitto 5:7e5c566b1760 121 timestamp_t _delay; /**< Time delay (in microseconds) for re-setting the multi-shot callback. */
Pokitto 5:7e5c566b1760 122 FunctionPointer _function; /**< Callback. */
Pokitto 5:7e5c566b1760 123 };
Pokitto 5:7e5c566b1760 124
Pokitto 5:7e5c566b1760 125 } // namespace mbed
Pokitto 5:7e5c566b1760 126
Pokitto 5:7e5c566b1760 127 #endif