Mouse code for the MacroRat

Dependencies:   ITG3200 QEI

Committer:
sahilmgandhi
Date:
Sat Jun 03 00:22:44 2017 +0000
Revision:
46:b156ef445742
Parent:
18:6a4db94011d3
Final code for internal battlebot competition.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sahilmgandhi 18:6a4db94011d3 1 /* mbed Microcontroller Library
sahilmgandhi 18:6a4db94011d3 2 * Copyright (c) 2006-2015 ARM Limited
sahilmgandhi 18:6a4db94011d3 3 *
sahilmgandhi 18:6a4db94011d3 4 * Licensed under the Apache License, Version 2.0 (the "License");
sahilmgandhi 18:6a4db94011d3 5 * you may not use this file except in compliance with the License.
sahilmgandhi 18:6a4db94011d3 6 * You may obtain a copy of the License at
sahilmgandhi 18:6a4db94011d3 7 *
sahilmgandhi 18:6a4db94011d3 8 * http://www.apache.org/licenses/LICENSE-2.0
sahilmgandhi 18:6a4db94011d3 9 *
sahilmgandhi 18:6a4db94011d3 10 * Unless required by applicable law or agreed to in writing, software
sahilmgandhi 18:6a4db94011d3 11 * distributed under the License is distributed on an "AS IS" BASIS,
sahilmgandhi 18:6a4db94011d3 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
sahilmgandhi 18:6a4db94011d3 13 * See the License for the specific language governing permissions and
sahilmgandhi 18:6a4db94011d3 14 * limitations under the License.
sahilmgandhi 18:6a4db94011d3 15 */
sahilmgandhi 18:6a4db94011d3 16 #ifndef MBED_FUNCTIONPOINTER_H
sahilmgandhi 18:6a4db94011d3 17 #define MBED_FUNCTIONPOINTER_H
sahilmgandhi 18:6a4db94011d3 18
sahilmgandhi 18:6a4db94011d3 19 #include "platform/Callback.h"
sahilmgandhi 18:6a4db94011d3 20 #include "platform/mbed_toolchain.h"
sahilmgandhi 18:6a4db94011d3 21 #include <string.h>
sahilmgandhi 18:6a4db94011d3 22 #include <stdint.h>
sahilmgandhi 18:6a4db94011d3 23
sahilmgandhi 18:6a4db94011d3 24 namespace mbed {
sahilmgandhi 18:6a4db94011d3 25 /** \addtogroup platform */
sahilmgandhi 18:6a4db94011d3 26 /** @{*/
sahilmgandhi 18:6a4db94011d3 27
sahilmgandhi 18:6a4db94011d3 28
sahilmgandhi 18:6a4db94011d3 29 // Declarations for backwards compatibility
sahilmgandhi 18:6a4db94011d3 30 // To be foward compatible, code should adopt the Callback class
sahilmgandhi 18:6a4db94011d3 31 template <typename R, typename A1>
sahilmgandhi 18:6a4db94011d3 32 class FunctionPointerArg1 : public Callback<R(A1)> {
sahilmgandhi 18:6a4db94011d3 33 public:
sahilmgandhi 18:6a4db94011d3 34 MBED_DEPRECATED_SINCE("mbed-os-5.1",
sahilmgandhi 18:6a4db94011d3 35 "FunctionPointerArg1<R, A> has been replaced by Callback<R(A)>")
sahilmgandhi 18:6a4db94011d3 36 FunctionPointerArg1(R (*function)(A1) = 0)
sahilmgandhi 18:6a4db94011d3 37 : Callback<R(A1)>(function) {}
sahilmgandhi 18:6a4db94011d3 38
sahilmgandhi 18:6a4db94011d3 39 template<typename T>
sahilmgandhi 18:6a4db94011d3 40 MBED_DEPRECATED_SINCE("mbed-os-5.1",
sahilmgandhi 18:6a4db94011d3 41 "FunctionPointerArg1<R, A> has been replaced by Callback<R(A)>")
sahilmgandhi 18:6a4db94011d3 42 FunctionPointerArg1(T *object, R (T::*member)(A1))
sahilmgandhi 18:6a4db94011d3 43 : Callback<R(A1)>(object, member) {}
sahilmgandhi 18:6a4db94011d3 44
sahilmgandhi 18:6a4db94011d3 45 R (*get_function())(A1) {
sahilmgandhi 18:6a4db94011d3 46 return *reinterpret_cast<R (**)(A1)>(this);
sahilmgandhi 18:6a4db94011d3 47 }
sahilmgandhi 18:6a4db94011d3 48
sahilmgandhi 18:6a4db94011d3 49 R call(A1 a1) const {
sahilmgandhi 18:6a4db94011d3 50 if (!Callback<R(A1)>::operator bool()) {
sahilmgandhi 18:6a4db94011d3 51 return (R)0;
sahilmgandhi 18:6a4db94011d3 52 }
sahilmgandhi 18:6a4db94011d3 53
sahilmgandhi 18:6a4db94011d3 54 return Callback<R(A1)>::call(a1);
sahilmgandhi 18:6a4db94011d3 55 }
sahilmgandhi 18:6a4db94011d3 56
sahilmgandhi 18:6a4db94011d3 57 R operator()(A1 a1) const {
sahilmgandhi 18:6a4db94011d3 58 return Callback<R(A1)>::call(a1);
sahilmgandhi 18:6a4db94011d3 59 }
sahilmgandhi 18:6a4db94011d3 60 };
sahilmgandhi 18:6a4db94011d3 61
sahilmgandhi 18:6a4db94011d3 62 template <typename R>
sahilmgandhi 18:6a4db94011d3 63 class FunctionPointerArg1<R, void> : public Callback<R()> {
sahilmgandhi 18:6a4db94011d3 64 public:
sahilmgandhi 18:6a4db94011d3 65 MBED_DEPRECATED_SINCE("mbed-os-5.1",
sahilmgandhi 18:6a4db94011d3 66 "FunctionPointer has been replaced by Callback<void()>")
sahilmgandhi 18:6a4db94011d3 67 FunctionPointerArg1(R (*function)() = 0)
sahilmgandhi 18:6a4db94011d3 68 : Callback<R()>(function) {}
sahilmgandhi 18:6a4db94011d3 69
sahilmgandhi 18:6a4db94011d3 70 template<typename T>
sahilmgandhi 18:6a4db94011d3 71 MBED_DEPRECATED_SINCE("mbed-os-5.1",
sahilmgandhi 18:6a4db94011d3 72 "FunctionPointer has been replaced by Callback<void()>")
sahilmgandhi 18:6a4db94011d3 73 FunctionPointerArg1(T *object, R (T::*member)())
sahilmgandhi 18:6a4db94011d3 74 : Callback<R()>(object, member) {}
sahilmgandhi 18:6a4db94011d3 75
sahilmgandhi 18:6a4db94011d3 76 R (*get_function())() {
sahilmgandhi 18:6a4db94011d3 77 return *reinterpret_cast<R (**)()>(this);
sahilmgandhi 18:6a4db94011d3 78 }
sahilmgandhi 18:6a4db94011d3 79
sahilmgandhi 18:6a4db94011d3 80 R call() const {
sahilmgandhi 18:6a4db94011d3 81 if (!Callback<R()>::operator bool()) {
sahilmgandhi 18:6a4db94011d3 82 return (R)0;
sahilmgandhi 18:6a4db94011d3 83 }
sahilmgandhi 18:6a4db94011d3 84
sahilmgandhi 18:6a4db94011d3 85 return Callback<R()>::call();
sahilmgandhi 18:6a4db94011d3 86 }
sahilmgandhi 18:6a4db94011d3 87
sahilmgandhi 18:6a4db94011d3 88 R operator()() const {
sahilmgandhi 18:6a4db94011d3 89 return Callback<R()>::call();
sahilmgandhi 18:6a4db94011d3 90 }
sahilmgandhi 18:6a4db94011d3 91 };
sahilmgandhi 18:6a4db94011d3 92
sahilmgandhi 18:6a4db94011d3 93 typedef FunctionPointerArg1<void, void> FunctionPointer;
sahilmgandhi 18:6a4db94011d3 94
sahilmgandhi 18:6a4db94011d3 95
sahilmgandhi 18:6a4db94011d3 96 } // namespace mbed
sahilmgandhi 18:6a4db94011d3 97
sahilmgandhi 18:6a4db94011d3 98 #endif
sahilmgandhi 18:6a4db94011d3 99
sahilmgandhi 18:6a4db94011d3 100 /** @}*/