a
Dependencies: 4DGL-uLCD-SE LSM9DS1_Library_cal SDFileSystem mbed-rtos mbed wave_player
Revision 0:2b0c527942db, committed 2016-11-02
- Comitter:
- rmaran6
- Date:
- Wed Nov 02 02:02:03 2016 +0000
- Commit message:
- a
Changed in this revision
diff -r 000000000000 -r 2b0c527942db 4DGL-uLCD-SE.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/4DGL-uLCD-SE.lib Wed Nov 02 02:02:03 2016 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/4180_1/code/4DGL-uLCD-SE/#2cb1845d7681
diff -r 000000000000 -r 2b0c527942db Callback.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Callback.h Wed Nov 02 02:02:03 2016 +0000 @@ -0,0 +1,883 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2015 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef MBED_CALLBACK_H +#define MBED_CALLBACK_H + +#include <string.h> +#include <stdint.h> + +namespace mbed { + + +/** Callback class based on template specialization + * + * @Note Synchronization level: Not protected + */ +template <typename F> +class Callback; + +/** Templated function class + */ +template <typename R, typename A0, typename A1, typename A2, typename A3, typename A4> +class Callback<R(A0, A1, A2, A3, A4)> { +public: + /** Create a Callback with a static function + * @param func Static function to attach + */ + Callback(R (*func)(A0, A1, A2, A3, A4) = 0) { + attach(func); + } + + /** Create a Callback with a static function and bound pointer + * @param obj Pointer to object to bind to function + * @param func Static function to attach + */ + template<typename T> + Callback(T *obj, R (*func)(T*, A0, A1, A2, A3, A4)) { + attach(obj, func); + } + + /** Create a Callback with a member function + * @param obj Pointer to object to invoke member function on + * @param func Member function to attach + */ + template<typename T> + Callback(T *obj, R (T::*func)(A0, A1, A2, A3, A4)) { + attach(obj, func); + } + + /** Create a Callback with another Callback + * @param func Callback to attach + */ + Callback(const Callback<R(A0, A1, A2, A3, A4)> &func) { + attach(func); + } + + /** Attach a static function + * @param func Static function to attach + */ + void attach(R (*func)(A0, A1, A2, A3, A4)) { + memcpy(&_func, &func, sizeof func); + _thunk = func ? &Callback::_staticthunk : 0; + } + + /** Attach a static function with a bound pointer + * @param obj Pointer to object to bind to function + * @param func Static function to attach + */ + template <typename T> + void attach(T *obj, R (*func)(T*, A0, A1, A2, A3, A4)) { + _obj = (void*)obj; + memcpy(&_func, &func, sizeof func); + _thunk = &Callback::_boundthunk<T>; + } + + /** Attach a member function + * @param obj Pointer to object to invoke member function on + * @param func Member function to attach + */ + template<typename T> + void attach(T *obj, R (T::*func)(A0, A1, A2, A3, A4)) { + _obj = static_cast<void*>(obj); + memcpy(&_func, &func, sizeof func); + _thunk = &Callback::_methodthunk<T>; + } + + /** Attach a Callback + * @param func The Callback to attach + */ + void attach(const Callback<R(A0, A1, A2, A3, A4)> &func) { + _obj = func._obj; + memcpy(&_func, &func._func, sizeof _func); + _thunk = func._thunk; + } + + /** Call the attached function + */ + R call(A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) { + if (!_thunk) { + return (R)0; + } + return _thunk(_obj, &_func, a0, a1, a2, a3, a4); + } + + /** Call the attached function + */ + R operator()(A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) { + return call(a0, a1, a2, a3, a4); + } + + /** Test if function has been attached + */ + operator bool() const { + return _thunk; + } + + /** Static thunk for passing as C-style function + * @param func Callback to call passed as void pointer + */ + static R thunk(void *func, A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) { + return static_cast<Callback<R(A0, A1, A2, A3, A4)>*>(func) + ->call(a0, a1, a2, a3, a4); + } + +private: + // Internal thunks for various function types + static R _staticthunk(void*, void *func, A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) { + return (*reinterpret_cast<R (**)(A0, A1, A2, A3, A4)>(func)) + (a0, a1, a2, a3, a4); + } + + template<typename T> + static R _boundthunk(void *obj, void *func, A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) { + return (*reinterpret_cast<R (**)(T*, A0, A1, A2, A3, A4)>(func)) + (static_cast<T*>(obj), a0, a1, a2, a3, a4); + } + + template<typename T> + static R _methodthunk(void *obj, void *func, A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) { + return (static_cast<T*>(obj)->* + (*reinterpret_cast<R (T::**)(A0, A1, A2, A3, A4)>(func))) + (a0, a1, a2, a3, a4); + } + + // Stored as pointer to function and pointer to optional object + // Function pointer is stored as union of possible function types + // to garuntee proper size and alignment + struct _class; + union { + void (*_staticfunc)(); + void (*_boundfunc)(_class *); + void (_class::*_methodfunc)(); + } _func; + + void *_obj; + + // Thunk registered on attach to dispatch calls + R (*_thunk)(void*, void*, A0, A1, A2, A3, A4); +}; + +/** Templated function class + */ +template <typename R, typename A0, typename A1, typename A2, typename A3> +class Callback<R(A0, A1, A2, A3)> { +public: + /** Create a Callback with a static function + * @param func Static function to attach + */ + Callback(R (*func)(A0, A1, A2, A3) = 0) { + attach(func); + } + + /** Create a Callback with a static function and bound pointer + * @param obj Pointer to object to bind to function + * @param func Static function to attach + */ + template<typename T> + Callback(T *obj, R (*func)(T*, A0, A1, A2, A3)) { + attach(obj, func); + } + + /** Create a Callback with a member function + * @param obj Pointer to object to invoke member function on + * @param func Member function to attach + */ + template<typename T> + Callback(T *obj, R (T::*func)(A0, A1, A2, A3)) { + attach(obj, func); + } + + /** Create a Callback with another Callback + * @param func Callback to attach + */ + Callback(const Callback<R(A0, A1, A2, A3)> &func) { + attach(func); + } + + /** Attach a static function + * @param func Static function to attach + */ + void attach(R (*func)(A0, A1, A2, A3)) { + memcpy(&_func, &func, sizeof func); + _thunk = func ? &Callback::_staticthunk : 0; + } + + /** Attach a static function with a bound pointer + * @param obj Pointer to object to bind to function + * @param func Static function to attach + */ + template <typename T> + void attach(T *obj, R (*func)(T*, A0, A1, A2, A3)) { + _obj = (void*)obj; + memcpy(&_func, &func, sizeof func); + _thunk = &Callback::_boundthunk<T>; + } + + /** Attach a member function + * @param obj Pointer to object to invoke member function on + * @param func Member function to attach + */ + template<typename T> + void attach(T *obj, R (T::*func)(A0, A1, A2, A3)) { + _obj = static_cast<void*>(obj); + memcpy(&_func, &func, sizeof func); + _thunk = &Callback::_methodthunk<T>; + } + + /** Attach a Callback + * @param func The Callback to attach + */ + void attach(const Callback<R(A0, A1, A2, A3)> &func) { + _obj = func._obj; + memcpy(&_func, &func._func, sizeof _func); + _thunk = func._thunk; + } + + /** Call the attached function + */ + R call(A0 a0, A1 a1, A2 a2, A3 a3) { + if (!_thunk) { + return (R)0; + } + return _thunk(_obj, &_func, a0, a1, a2, a3); + } + + /** Call the attached function + */ + R operator()(A0 a0, A1 a1, A2 a2, A3 a3) { + return call(a0, a1, a2, a3); + } + + /** Test if function has been attached + */ + operator bool() const { + return _thunk; + } + + /** Static thunk for passing as C-style function + * @param func Callback to call passed as void pointer + */ + static R thunk(void *func, A0 a0, A1 a1, A2 a2, A3 a3) { + return static_cast<Callback<R(A0, A1, A2, A3)>*>(func) + ->call(a0, a1, a2, a3); + } + +private: + // Internal thunks for various function types + static R _staticthunk(void*, void *func, A0 a0, A1 a1, A2 a2, A3 a3) { + return (*reinterpret_cast<R (**)(A0, A1, A2, A3)>(func)) + (a0, a1, a2, a3); + } + + template<typename T> + static R _boundthunk(void *obj, void *func, A0 a0, A1 a1, A2 a2, A3 a3) { + return (*reinterpret_cast<R (**)(T*, A0, A1, A2, A3)>(func)) + (static_cast<T*>(obj), a0, a1, a2, a3); + } + + template<typename T> + static R _methodthunk(void *obj, void *func, A0 a0, A1 a1, A2 a2, A3 a3) { + return (static_cast<T*>(obj)->* + (*reinterpret_cast<R (T::**)(A0, A1, A2, A3)>(func))) + (a0, a1, a2, a3); + } + + // Stored as pointer to function and pointer to optional object + // Function pointer is stored as union of possible function types + // to garuntee proper size and alignment + struct _class; + union { + void (*_staticfunc)(); + void (*_boundfunc)(_class *); + void (_class::*_methodfunc)(); + } _func; + + void *_obj; + + // Thunk registered on attach to dispatch calls + R (*_thunk)(void*, void*, A0, A1, A2, A3); +}; + +/** Templated function class + */ +template <typename R, typename A0, typename A1, typename A2> +class Callback<R(A0, A1, A2)> { +public: + /** Create a Callback with a static function + * @param func Static function to attach + */ + Callback(R (*func)(A0, A1, A2) = 0) { + attach(func); + } + + /** Create a Callback with a static function and bound pointer + * @param obj Pointer to object to bind to function + * @param func Static function to attach + */ + template<typename T> + Callback(T *obj, R (*func)(T*, A0, A1, A2)) { + attach(obj, func); + } + + /** Create a Callback with a member function + * @param obj Pointer to object to invoke member function on + * @param func Member function to attach + */ + template<typename T> + Callback(T *obj, R (T::*func)(A0, A1, A2)) { + attach(obj, func); + } + + /** Create a Callback with another Callback + * @param func Callback to attach + */ + Callback(const Callback<R(A0, A1, A2)> &func) { + attach(func); + } + + /** Attach a static function + * @param func Static function to attach + */ + void attach(R (*func)(A0, A1, A2)) { + memcpy(&_func, &func, sizeof func); + _thunk = func ? &Callback::_staticthunk : 0; + } + + /** Attach a static function with a bound pointer + * @param obj Pointer to object to bind to function + * @param func Static function to attach + */ + template <typename T> + void attach(T *obj, R (*func)(T*, A0, A1, A2)) { + _obj = (void*)obj; + memcpy(&_func, &func, sizeof func); + _thunk = &Callback::_boundthunk<T>; + } + + /** Attach a member function + * @param obj Pointer to object to invoke member function on + * @param func Member function to attach + */ + template<typename T> + void attach(T *obj, R (T::*func)(A0, A1, A2)) { + _obj = static_cast<void*>(obj); + memcpy(&_func, &func, sizeof func); + _thunk = &Callback::_methodthunk<T>; + } + + /** Attach a Callback + * @param func The Callback to attach + */ + void attach(const Callback<R(A0, A1, A2)> &func) { + _obj = func._obj; + memcpy(&_func, &func._func, sizeof _func); + _thunk = func._thunk; + } + + /** Call the attached function + */ + R call(A0 a0, A1 a1, A2 a2) { + if (!_thunk) { + return (R)0; + } + return _thunk(_obj, &_func, a0, a1, a2); + } + + /** Call the attached function + */ + R operator()(A0 a0, A1 a1, A2 a2) { + return call(a0, a1, a2); + } + + /** Test if function has been attached + */ + operator bool() const { + return _thunk; + } + + /** Static thunk for passing as C-style function + * @param func Callback to call passed as void pointer + */ + static R thunk(void *func, A0 a0, A1 a1, A2 a2) { + return static_cast<Callback<R(A0, A1, A2)>*>(func) + ->call(a0, a1, a2); + } + +private: + // Internal thunks for various function types + static R _staticthunk(void*, void *func, A0 a0, A1 a1, A2 a2) { + return (*reinterpret_cast<R (**)(A0, A1, A2)>(func)) + (a0, a1, a2); + } + + template<typename T> + static R _boundthunk(void *obj, void *func, A0 a0, A1 a1, A2 a2) { + return (*reinterpret_cast<R (**)(T*, A0, A1, A2)>(func)) + (static_cast<T*>(obj), a0, a1, a2); + } + + template<typename T> + static R _methodthunk(void *obj, void *func, A0 a0, A1 a1, A2 a2) { + return (static_cast<T*>(obj)->* + (*reinterpret_cast<R (T::**)(A0, A1, A2)>(func))) + (a0, a1, a2); + } + + // Stored as pointer to function and pointer to optional object + // Function pointer is stored as union of possible function types + // to garuntee proper size and alignment + struct _class; + union { + void (*_staticfunc)(); + void (*_boundfunc)(_class *); + void (_class::*_methodfunc)(); + } _func; + + void *_obj; + + // Thunk registered on attach to dispatch calls + R (*_thunk)(void*, void*, A0, A1, A2); +}; + +/** Templated function class + */ +template <typename R, typename A0, typename A1> +class Callback<R(A0, A1)> { +public: + /** Create a Callback with a static function + * @param func Static function to attach + */ + Callback(R (*func)(A0, A1) = 0) { + attach(func); + } + + /** Create a Callback with a static function and bound pointer + * @param obj Pointer to object to bind to function + * @param func Static function to attach + */ + template<typename T> + Callback(T *obj, R (*func)(T*, A0, A1)) { + attach(obj, func); + } + + /** Create a Callback with a member function + * @param obj Pointer to object to invoke member function on + * @param func Member function to attach + */ + template<typename T> + Callback(T *obj, R (T::*func)(A0, A1)) { + attach(obj, func); + } + + /** Create a Callback with another Callback + * @param func Callback to attach + */ + Callback(const Callback<R(A0, A1)> &func) { + attach(func); + } + + /** Attach a static function + * @param func Static function to attach + */ + void attach(R (*func)(A0, A1)) { + memcpy(&_func, &func, sizeof func); + _thunk = func ? &Callback::_staticthunk : 0; + } + + /** Attach a static function with a bound pointer + * @param obj Pointer to object to bind to function + * @param func Static function to attach + */ + template <typename T> + void attach(T *obj, R (*func)(T*, A0, A1)) { + _obj = (void*)obj; + memcpy(&_func, &func, sizeof func); + _thunk = &Callback::_boundthunk<T>; + } + + /** Attach a member function + * @param obj Pointer to object to invoke member function on + * @param func Member function to attach + */ + template<typename T> + void attach(T *obj, R (T::*func)(A0, A1)) { + _obj = static_cast<void*>(obj); + memcpy(&_func, &func, sizeof func); + _thunk = &Callback::_methodthunk<T>; + } + + /** Attach a Callback + * @param func The Callback to attach + */ + void attach(const Callback<R(A0, A1)> &func) { + _obj = func._obj; + memcpy(&_func, &func._func, sizeof _func); + _thunk = func._thunk; + } + + /** Call the attached function + */ + R call(A0 a0, A1 a1) { + if (!_thunk) { + return (R)0; + } + return _thunk(_obj, &_func, a0, a1); + } + + /** Call the attached function + */ + R operator()(A0 a0, A1 a1) { + return call(a0, a1); + } + + /** Test if function has been attached + */ + operator bool() const { + return _thunk; + } + + /** Static thunk for passing as C-style function + * @param func Callback to call passed as void pointer + */ + static R thunk(void *func, A0 a0, A1 a1) { + return static_cast<Callback<R(A0, A1)>*>(func) + ->call(a0, a1); + } + +private: + // Internal thunks for various function types + static R _staticthunk(void*, void *func, A0 a0, A1 a1) { + return (*reinterpret_cast<R (**)(A0, A1)>(func)) + (a0, a1); + } + + template<typename T> + static R _boundthunk(void *obj, void *func, A0 a0, A1 a1) { + return (*reinterpret_cast<R (**)(T*, A0, A1)>(func)) + (static_cast<T*>(obj), a0, a1); + } + + template<typename T> + static R _methodthunk(void *obj, void *func, A0 a0, A1 a1) { + return (static_cast<T*>(obj)->* + (*reinterpret_cast<R (T::**)(A0, A1)>(func))) + (a0, a1); + } + + // Stored as pointer to function and pointer to optional object + // Function pointer is stored as union of possible function types + // to garuntee proper size and alignment + struct _class; + union { + void (*_staticfunc)(); + void (*_boundfunc)(_class *); + void (_class::*_methodfunc)(); + } _func; + + void *_obj; + + // Thunk registered on attach to dispatch calls + R (*_thunk)(void*, void*, A0, A1); +}; + +/** Templated function class + */ +template <typename R, typename A0> +class Callback<R(A0)> { +public: + /** Create a Callback with a static function + * @param func Static function to attach + */ + Callback(R (*func)(A0) = 0) { + attach(func); + } + + /** Create a Callback with a static function and bound pointer + * @param obj Pointer to object to bind to function + * @param func Static function to attach + */ + template<typename T> + Callback(T *obj, R (*func)(T*, A0)) { + attach(obj, func); + } + + /** Create a Callback with a member function + * @param obj Pointer to object to invoke member function on + * @param func Member function to attach + */ + template<typename T> + Callback(T *obj, R (T::*func)(A0)) { + attach(obj, func); + } + + /** Create a Callback with another Callback + * @param func Callback to attach + */ + Callback(const Callback<R(A0)> &func) { + attach(func); + } + + /** Attach a static function + * @param func Static function to attach + */ + void attach(R (*func)(A0)) { + memcpy(&_func, &func, sizeof func); + _thunk = func ? &Callback::_staticthunk : 0; + } + + /** Attach a static function with a bound pointer + * @param obj Pointer to object to bind to function + * @param func Static function to attach + */ + template <typename T> + void attach(T *obj, R (*func)(T*, A0)) { + _obj = (void*)obj; + memcpy(&_func, &func, sizeof func); + _thunk = &Callback::_boundthunk<T>; + } + + /** Attach a member function + * @param obj Pointer to object to invoke member function on + * @param func Member function to attach + */ + template<typename T> + void attach(T *obj, R (T::*func)(A0)) { + _obj = static_cast<void*>(obj); + memcpy(&_func, &func, sizeof func); + _thunk = &Callback::_methodthunk<T>; + } + + /** Attach a Callback + * @param func The Callback to attach + */ + void attach(const Callback<R(A0)> &func) { + _obj = func._obj; + memcpy(&_func, &func._func, sizeof _func); + _thunk = func._thunk; + } + + /** Call the attached function + */ + R call(A0 a0) { + if (!_thunk) { + return (R)0; + } + return _thunk(_obj, &_func, a0); + } + + /** Call the attached function + */ + R operator()(A0 a0) { + return call(a0); + } + + /** Test if function has been attached + */ + operator bool() const { + return _thunk; + } + + /** Static thunk for passing as C-style function + * @param func Callback to call passed as void pointer + */ + static R thunk(void *func, A0 a0) { + return static_cast<Callback<R(A0)>*>(func) + ->call(a0); + } + +private: + // Internal thunks for various function types + static R _staticthunk(void*, void *func, A0 a0) { + return (*reinterpret_cast<R (**)(A0)>(func)) + (a0); + } + + template<typename T> + static R _boundthunk(void *obj, void *func, A0 a0) { + return (*reinterpret_cast<R (**)(T*, A0)>(func)) + (static_cast<T*>(obj), a0); + } + + template<typename T> + static R _methodthunk(void *obj, void *func, A0 a0) { + return (static_cast<T*>(obj)->* + (*reinterpret_cast<R (T::**)(A0)>(func))) + (a0); + } + + // Stored as pointer to function and pointer to optional object + // Function pointer is stored as union of possible function types + // to garuntee proper size and alignment + struct _class; + union { + void (*_staticfunc)(); + void (*_boundfunc)(_class *); + void (_class::*_methodfunc)(); + } _func; + + void *_obj; + + // Thunk registered on attach to dispatch calls + R (*_thunk)(void*, void*, A0); +}; + +/** Templated function class + */ +template <typename R> +class Callback<R()> { +public: + /** Create a Callback with a static function + * @param func Static function to attach + */ + Callback(R (*func)() = 0) { + attach(func); + } + + /** Create a Callback with a static function and bound pointer + * @param obj Pointer to object to bind to function + * @param func Static function to attach + */ + template<typename T> + Callback(T *obj, R (*func)(T*)) { + attach(obj, func); + } + + /** Create a Callback with a member function + * @param obj Pointer to object to invoke member function on + * @param func Member function to attach + */ + template<typename T> + Callback(T *obj, R (T::*func)()) { + attach(obj, func); + } + + /** Create a Callback with another Callback + * @param func Callback to attach + */ + Callback(const Callback<R()> &func) { + attach(func); + } + + /** Attach a static function + * @param func Static function to attach + */ + void attach(R (*func)()) { + memcpy(&_func, &func, sizeof func); + _thunk = func ? &Callback::_staticthunk : 0; + } + + /** Attach a static function with a bound pointer + * @param obj Pointer to object to bind to function + * @param func Static function to attach + */ + template <typename T> + void attach(T *obj, R (*func)(T*)) { + _obj = (void*)obj; + memcpy(&_func, &func, sizeof func); + _thunk = &Callback::_boundthunk<T>; + } + + /** Attach a member function + * @param obj Pointer to object to invoke member function on + * @param func Member function to attach + */ + template<typename T> + void attach(T *obj, R (T::*func)()) { + _obj = static_cast<void*>(obj); + memcpy(&_func, &func, sizeof func); + _thunk = &Callback::_methodthunk<T>; + } + + /** Attach a Callback + * @param func The Callback to attach + */ + void attach(const Callback<R()> &func) { + _obj = func._obj; + memcpy(&_func, &func._func, sizeof _func); + _thunk = func._thunk; + } + + /** Call the attached function + */ + R call() { + if (!_thunk) { + return (R)0; + } + return _thunk(_obj, &_func); + } + + /** Call the attached function + */ + R operator()() { + return call(); + } + + /** Test if function has been attached + */ + operator bool() const { + return _thunk; + } + + /** Static thunk for passing as C-style function + * @param func Callback to call passed as void pointer + */ + static R thunk(void *func) { + return static_cast<Callback<R()>*>(func) + ->call(); + } + +private: + // Internal thunks for various function types + static R _staticthunk(void*, void *func) { + return (*reinterpret_cast<R (**)()>(func)) + (); + } + + template<typename T> + static R _boundthunk(void *obj, void *func) { + return (*reinterpret_cast<R (**)(T*)>(func)) + (static_cast<T*>(obj)); + } + + template<typename T> + static R _methodthunk(void *obj, void *func) { + return (static_cast<T*>(obj)->* + (*reinterpret_cast<R (T::**)()>(func))) + (); + } + + // Stored as pointer to function and pointer to optional object + // Function pointer is stored as union of possible function types + // to garuntee proper size and alignment + struct _class; + union { + void (*_staticfunc)(); + void (*_boundfunc)(_class *); + void (_class::*_methodfunc)(); + } _func; + + void *_obj; + + // Thunk registered on attach to dispatch calls + R (*_thunk)(void*, void*); +}; + + typedef Callback<void(int)> event_callback_t; + + +} // namespace mbed + +#endif \ No newline at end of file
diff -r 000000000000 -r 2b0c527942db LSM9DS1_Library_cal.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LSM9DS1_Library_cal.lib Wed Nov 02 02:02:03 2016 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/users/4180_1/code/LSM9DS1_Library_cal/#36abf8e18ade
diff -r 000000000000 -r 2b0c527942db SDFileSystem.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SDFileSystem.lib Wed Nov 02 02:02:03 2016 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/users/rmaran6/code/SDFileSystem/#ff02963119fd
diff -r 000000000000 -r 2b0c527942db Sound/playSound.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Sound/playSound.cpp Wed Nov 02 02:02:03 2016 +0000 @@ -0,0 +1,26 @@ +#include "playSound.h" +#include "uLCD_4DGL.h" +#include "SDFileSystem.h" +#include "wave_player.h" + +extern uLCD_4DGL uLCD; +extern wave_player player; + +// Given the filename of a .wav file in the SD card, play the file over the speaker. +void playSound(char * wav) +{ + // open wav file + FILE *wave_file; + wave_file=fopen(wav,"r"); + + if(wave_file == NULL){ + uLCD.locate(0,4); + uLCD.printf("Error in SD"); + return; + } + // play wav file + player.play(wave_file); + + // close wav file + fclose(wave_file); +} \ No newline at end of file
diff -r 000000000000 -r 2b0c527942db Sound/playSound.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Sound/playSound.h Wed Nov 02 02:02:03 2016 +0000 @@ -0,0 +1,6 @@ +#ifndef PLAYSOUND_H__ +#define PLAYSOUND_H__ + +void playSound(char * wav); + +#endif //PLAYSOUND_H__ \ No newline at end of file
diff -r 000000000000 -r 2b0c527942db Wifi.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Wifi.cpp Wed Nov 02 02:02:03 2016 +0000 @@ -0,0 +1,214 @@ +#include "Wifi.h" + +Wifi::Wifi(PinName tx, PinName rx, PinName rst) + : esp(tx, rx), reset(rst), led1(LED1), led2(LED2), led3(LED3), led4(LED4) { + ssid = "GTother"; // enter WiFi router ssid inside the quotes + pwd = "GeorgeP@1927"; // enter WiFi router password inside the quotes +} +void dev_recv() +{ + led1 = !led1; + while(esp.readable()) { + pc.putc(esp.getc()); + } +} + +void pc_recv() +{ + led4 = !led4; + while(pc.readable()) { + esp.putc(pc.getc()); + } +} +void Wifi::ESPsetbaudrate() { + strcpy(snd, "AT+CIOBAUD=115200\r\n"); // change the numeric value to the required baudrate + SendCMD(); +} +void Wifi::ESPconfig() { + wait(5); + pc.printf("\f---------- Starting ESP Config ----------\r\n\n"); + strcpy(snd,".\r\n.\r\n"); + SendCMD(); + wait(1); + pc.printf("---------- Reset & get Firmware ----------\r\n"); + strcpy(snd,"node.restart()\r\n"); + SendCMD(); + timeout=5; + getreply(); + pc.printf(buf); + + wait(2); + + pc.printf("\n---------- Get Version ----------\r\n"); + strcpy(snd,"print(node.info())\r\n"); + SendCMD(); + timeout=4; + getreply(); + pc.printf(buf); + + wait(3); + + // set CWMODE to 1=Station,2=AP,3=BOTH, default mode 1 (Station) + pc.printf("\n---------- Setting Mode ----------\r\n"); + strcpy(snd, "wifi.setmode(wifi.STATION)\r\n"); + SendCMD(); + timeout=4; + getreply(); + pc.printf(buf); + + wait(2); + + + + pc.printf("\n---------- Listing Access Points ----------\r\n"); + strcpy(snd, "function listap(t)\r\n"); + SendCMD(); + wait(1); + strcpy(snd, "for k,v in pairs(t) do\r\n"); + SendCMD(); + wait(1); + strcpy(snd, "print(k..\" : \"..v)\r\n"); + SendCMD(); + wait(1); + strcpy(snd, "end\r\n"); + SendCMD(); + wait(1); + strcpy(snd, "end\r\n"); + SendCMD(); + wait(1); + strcpy(snd, "wifi.sta.getap(listap)\r\n"); + SendCMD(); + wait(1); + timeout=15; + getreply(); + pc.printf(buf); + + wait(2); + + pc.printf("\n---------- Connecting to AP ----------\r\n"); + pc.printf("ssid = %s pwd = %s\r\n",ssid,pwd); + strcpy(snd, "wifi.sta.config(\""); + strcat(snd, ssid); + strcat(snd, "\",\""); + strcat(snd, pwd); + strcat(snd, "\")\r\n"); + SendCMD(); + timeout=10; + getreply(); + pc.printf(buf); + + wait(5); + + pc.printf("\n---------- Get IP's ----------\r\n"); + strcpy(snd, "print(wifi.sta.getip())\r\n"); + SendCMD(); + timeout=3; + getreply(); + pc.printf(buf); + + wait(1); + + pc.printf("\n---------- Get Connection Status ----------\r\n"); + strcpy(snd, "print(wifi.sta.status())\r\n"); + SendCMD(); + timeout=5; + getreply(); + pc.printf(buf); + + pc.printf("\n\n\n If you get a valid (non zero) IP, ESP8266 has been set up.\r\n"); + pc.printf(" Run this if you want to reconfig the ESP8266 at any time.\r\n"); + pc.printf(" It saves the SSID and password settings internally\r\n"); + wait(10); + + + pc.printf("\n---------- Setting up http server ----------\r\n"); + strcpy(snd, "srv=net.createServer(net.TCP)\r\n"); + SendCMD(); + wait(1); + strcpy(snd, "srv:listen(80,function(conn)\r\n"); + SendCMD(); + wait(1); + strcpy(snd, "conn:on(\"receive\",function(conn,payload)\r\n"); + SendCMD(); + wait(1); + strcpy(snd, "print(payload)\r\n"); + SendCMD(); + wait(1); + + strcpy(snd, "conn:send(\"<!DOCTYPE html>\")\r\n"); + SendCMD(); + wait(1); + + strcpy(snd, "conn:send(\"<html>\")\r\n"); + SendCMD(); + wait(1); + + strcpy(snd, "conn:send(\"<h1> Hi James, NodeMcu.</h1>\")\r\n"); + SendCMD(); + wait(1); + + strcpy(snd, "conn:send(\"<h2> test</h2>\")\r\n"); + SendCMD(); + wait(1); + + strcpy(snd, "conn:send(\"</html>\")\r\n"); + SendCMD(); + wait(1); + + strcpy(snd, "end)\r\n"); + SendCMD(); + wait(1); + + strcpy(snd, "conn:on(\"sent\",function(conn) conn:close() end)\r\n"); + SendCMD(); + wait(1); + strcpy(snd, "end)\r\n"); + SendCMD(); + wait(1); + timeout=17; + getreply(); + pc.printf(buf); + pc.printf("\r\nDONE"); +} +void Wifi::SendCMD() { + esp.printf("%s", snd); +} +void Wifi::getreply() { + memset(buf, '\0', sizeof(buf)); + t.start(); + ended=0; + count=0; + while(!ended) { + if(esp.readable()) { + buf[count] = esp.getc(); + count++; + } + if(t.read() > timeout) { + ended = 1; + t.stop(); + t.reset(); + } + } +} + +void Wifi::setupPage() { + reset=0; //hardware reset for 8266 + pc.baud(9600); // set what you want here depending on your terminal program speed + pc.printf("\f\n\r-------------ESP8266 Hardware Reset-------------\n\r"); + wait(0.5); + reset=1; + timeout=2; + getreply(); + + esp.baud(9600); // change this to the new ESP8266 baudrate if it is changed at any time. + + //ESPsetbaudrate(); //****************** include this routine to set a different ESP8266 baudrate ****************** + + ESPconfig(); //****************** include Config to set the ESP8266 configuration *********************** + + pc.attach(&pc_recv, Serial::RxIrq); + esp.attach(&dev_recv, Serial::RxIrq); + + // continuosly get AP list and IP +} +
diff -r 000000000000 -r 2b0c527942db Wifi.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Wifi.h Wed Nov 02 02:02:03 2016 +0000 @@ -0,0 +1,26 @@ +#include "mbed.h" + +class Wifi { + public: + Wifi(PinName tx, PinName rx, PinName rst) + void ESPsetbaudrate(); + void ESPconfig(); + void SendCMD(); + void getreply(); + void setupPage(); + public: + int count,ended,timeout; + char buf[2024]; + char snd[1024]; + char ssid[32];// = "GTother"; // enter WiFi router ssid inside the quotes + char pwd [32];// = "GeorgeP@1927"; // enter WiFi router password inside the quotes + protected: + Serial esp; + Timer t; + DigitalOut reset; + DigitalOut led1; + DigitalOut led2; + DigitalOut led3; + DigitalOut led4; +} +
diff -r 000000000000 -r 2b0c527942db main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed Nov 02 02:02:03 2016 +0000 @@ -0,0 +1,39 @@ +#include "mbed.h" +#include "Wifi.h" +#include "LSM9DS1.h" +#include "uLCD_4DGL.h" +#include "playSound.h" +#include "SDFileSystem.h" +#include "wave_player.h" +#define PI 3.14159 +#define DECLINATION -4.94 // Declination (degrees) in Atlanta,GA. +//DigitalIn pb1(p29); +//DigitalIn pb2(p30); + +Serial pc(USBTX, USBRX); +PwmOut red(p22); +PwmOut green(p23); +PwmOut blue(p24); +SDFileSystem sd(p5, p6, p7, p8, "sd"); +Wifi fi(p28, p27, p26); +LSM9DS1 IMU(p9, p10, 0xD6, 0x3C); +AnalogOut DACout(p18); +wave_player player(&DACout); +//playSound("/sd/wavfiles/BUZZER.wav"); + +int main() { + fi.setupPage(); + IMU.begin(); + if (!IMU.begin()) { + pc.printf("Failed to communicate with LSM9DS1.\n"); + } + IMU.calibrate(1); + IMU.calibrateMag(0); + while(1) { + while(!IMU.gyroAvailable()); + IMU.readGyro(); + pc.printf("mag: %9f %9f %9f in gauss\n\r", IMU.calcMag(IMU.mx), IMU.calcMag(IMU.my), IMU.calcMag(IMU.mz)); + } + + +}
diff -r 000000000000 -r 2b0c527942db mbed-rtos.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-rtos.lib Wed Nov 02 02:02:03 2016 +0000 @@ -0,0 +1,1 @@ +https://mbed.org/users/mbed_official/code/mbed-rtos/#3da5f554d8bf
diff -r 000000000000 -r 2b0c527942db mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed Nov 02 02:02:03 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/9bcdf88f62b0 \ No newline at end of file
diff -r 000000000000 -r 2b0c527942db mpr121.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mpr121.cpp Wed Nov 02 02:02:03 2016 +0000 @@ -0,0 +1,221 @@ +/* +Copyright (c) 2011 Anthony Buckton (abuckton [at] blackink [dot} net {dot} au) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +#include <mbed.h> +#include <sstream> +#include <string> +#include <list> + +#include <mpr121.h> + +Mpr121::Mpr121(I2C *i2c, Address i2cAddress) +{ + this->i2c = i2c; + + address = i2cAddress; + + // Configure the MPR121 settings to default + this->configureSettings(); +} + + +void Mpr121::configureSettings() +{ + // Put the MPR into setup mode + this->write(ELE_CFG,0x00); + + // Electrode filters for when data is > baseline + unsigned char gtBaseline[] = { + 0x01, //MHD_R + 0x01, //NHD_R + 0x00, //NCL_R + 0x00 //FDL_R + }; + + writeMany(MHD_R,gtBaseline,4); + + // Electrode filters for when data is < baseline + unsigned char ltBaseline[] = { + 0x01, //MHD_F + 0x01, //NHD_F + 0xFF, //NCL_F + 0x02 //FDL_F + }; + + writeMany(MHD_F,ltBaseline,4); + + // Electrode touch and release thresholds + unsigned char electrodeThresholds[] = { + E_THR_T, // Touch Threshhold + E_THR_R // Release Threshold + }; + + for(int i=0; i<12; i++){ + int result = writeMany((ELE0_T+(i*2)),electrodeThresholds,2); + } + + // Proximity Settings + unsigned char proximitySettings[] = { + 0xff, //MHD_Prox_R + 0xff, //NHD_Prox_R + 0x00, //NCL_Prox_R + 0x00, //FDL_Prox_R + 0x01, //MHD_Prox_F + 0x01, //NHD_Prox_F + 0xFF, //NCL_Prox_F + 0xff, //FDL_Prox_F + 0x00, //NHD_Prox_T + 0x00, //NCL_Prox_T + 0x00 //NFD_Prox_T + }; + writeMany(MHDPROXR,proximitySettings,11); + + unsigned char proxThresh[] = { + PROX_THR_T, // Touch Threshold + PROX_THR_R // Release Threshold + }; + writeMany(EPROXTTH,proxThresh,2); + + this->write(FIL_CFG,0x04); + + // Set the electrode config to transition to active mode + this->write(ELE_CFG,0x0c); +} + +void Mpr121::setElectrodeThreshold(int electrode, unsigned char touch, unsigned char release){ + + if(electrode > 11) return; + + // Get the current mode + unsigned char mode = this->read(ELE_CFG); + + // Put the MPR into setup mode + this->write(ELE_CFG,0x00); + + // Write the new threshold + this->write((ELE0_T+(electrode*2)), touch); + this->write((ELE0_T+(electrode*2)+1), release); + + //Restore the operating mode + this->write(ELE_CFG, mode); +} + + +unsigned char Mpr121::read(int key){ + + unsigned char data[2]; + + //Start the command + i2c->start(); + + // Address the target (Write mode) + int ack1= i2c->write(address); + + // Set the register key to read + int ack2 = i2c->write(key); + + // Re-start for read of data + i2c->start(); + + // Re-send the target address in read mode + int ack3 = i2c->write(address+1); + + // Read in the result + data[0] = i2c->read(0); + + // Reset the bus + i2c->stop(); + + return data[0]; +} + + +int Mpr121::write(int key, unsigned char value){ + + //Start the command + i2c->start(); + + // Address the target (Write mode) + int ack1= i2c->write(address); + + // Set the register key to write + int ack2 = i2c->write(key); + + // Read in the result + int ack3 = i2c->write(value); + + // Reset the bus + i2c->stop(); + + return (ack1+ack2+ack3)-3; +} + + +int Mpr121::writeMany(int start, unsigned char* dataSet, int length){ + //Start the command + i2c->start(); + + // Address the target (Write mode) + int ack= i2c->write(address); + if(ack!=1){ + return -1; + } + + // Set the register key to write + ack = i2c->write(start); + if(ack!=1){ + return -1; + } + + // Write the date set + int count = 0; + while(ack==1 && (count < length)){ + ack = i2c->write(dataSet[count]); + count++; + } + // Stop the cmd + i2c->stop(); + + return count; +} + + +bool Mpr121::getProximityMode(){ + if(this->read(ELE_CFG) > 0x0c) + return true; + else + return false; +} + +void Mpr121::setProximityMode(bool mode){ + this->write(ELE_CFG,0x00); + if(mode){ + this->write(ELE_CFG,0x30); //Sense proximity from ALL pads + } else { + this->write(ELE_CFG,0x0c); //Sense touch, all 12 pads active. + } +} + + +int Mpr121::readTouchData(){ + return this->read(0x00); +} \ No newline at end of file
diff -r 000000000000 -r 2b0c527942db mpr121.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mpr121.h Wed Nov 02 02:02:03 2016 +0000 @@ -0,0 +1,157 @@ +/* +Copyright (c) 2011 Anthony Buckton (abuckton [at] blackink [dot} net {dot} au) + + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + + Parts written by Jim Lindblom of Sparkfun + Ported to mbed by A.Buckton, Feb 2011 +*/ + +#ifndef MPR121_H +#define MPR121_H + +//using namespace std; + +class Mpr121 +{ + +public: + // i2c Addresses, bit-shifted + enum Address { ADD_VSS = 0xb4,// ADD->VSS = 0x5a <-wiring on Sparkfun board + ADD_VDD = 0xb6,// ADD->VDD = 0x5b + ADD_SCL = 0xb8,// ADD->SDA = 0x5c + ADD_SDA = 0xba // ADD->SCL = 0x5d + }; + + // Real initialiser, takes the i2c address of the device. + Mpr121(I2C *i2c, Address i2cAddress); + + bool getProximityMode(); + + void setProximityMode(bool mode); + + int readTouchData(); + + unsigned char read(int key); + + int write(int address, unsigned char value); + int writeMany(int start, unsigned char* dataSet, int length); + + void setElectrodeThreshold(int electrodeId, unsigned char touchThreshold, unsigned char releaseThreshold); + +protected: + // Configures the MPR with standard settings. This is permitted to be overwritten by sub-classes. + void configureSettings(); + +private: + // The I2C bus instance. + I2C *i2c; + + // i2c address of this mpr121 + Address address; +}; + + +// MPR121 Register Defines +#define MHD_R 0x2B +#define NHD_R 0x2C +#define NCL_R 0x2D +#define FDL_R 0x2E +#define MHD_F 0x2F +#define NHD_F 0x30 +#define NCL_F 0x31 +#define FDL_F 0x32 +#define NHDT 0x33 +#define NCLT 0x34 +#define FDLT 0x35 +// Proximity sensing controls +#define MHDPROXR 0x36 +#define NHDPROXR 0x37 +#define NCLPROXR 0x38 +#define FDLPROXR 0x39 +#define MHDPROXF 0x3A +#define NHDPROXF 0x3B +#define NCLPROXF 0x3C +#define FDLPROXF 0x3D +#define NHDPROXT 0x3E +#define NCLPROXT 0x3F +#define FDLPROXT 0x40 +// Electrode Touch/Release thresholds +#define ELE0_T 0x41 +#define ELE0_R 0x42 +#define ELE1_T 0x43 +#define ELE1_R 0x44 +#define ELE2_T 0x45 +#define ELE2_R 0x46 +#define ELE3_T 0x47 +#define ELE3_R 0x48 +#define ELE4_T 0x49 +#define ELE4_R 0x4A +#define ELE5_T 0x4B +#define ELE5_R 0x4C +#define ELE6_T 0x4D +#define ELE6_R 0x4E +#define ELE7_T 0x4F +#define ELE7_R 0x50 +#define ELE8_T 0x51 +#define ELE8_R 0x52 +#define ELE9_T 0x53 +#define ELE9_R 0x54 +#define ELE10_T 0x55 +#define ELE10_R 0x56 +#define ELE11_T 0x57 +#define ELE11_R 0x58 +// Proximity Touch/Release thresholds +#define EPROXTTH 0x59 +#define EPROXRTH 0x5A +// Debounce configuration +#define DEB_CFG 0x5B +// AFE- Analogue Front End configuration +#define AFE_CFG 0x5C +// Filter configuration +#define FIL_CFG 0x5D +// Electrode configuration - transistions to "active mode" +#define ELE_CFG 0x5E + +#define GPIO_CTRL0 0x73 +#define GPIO_CTRL1 0x74 +#define GPIO_DATA 0x75 +#define GPIO_DIR 0x76 +#define GPIO_EN 0x77 +#define GPIO_SET 0x78 +#define GPIO_CLEAR 0x79 +#define GPIO_TOGGLE 0x7A +// Auto configration registers +#define AUTO_CFG_0 0x7B +#define AUTO_CFG_U 0x7D +#define AUTO_CFG_L 0x7E +#define AUTO_CFG_T 0x7F + +// Threshold defaults +// Electrode touch threshold +#define E_THR_T 0x0F +// Electrode release threshold +#define E_THR_R 0x0A +// Prox touch threshold +#define PROX_THR_T 0x02 +// Prox release threshold +#define PROX_THR_R 0x02 + +#endif
diff -r 000000000000 -r 2b0c527942db wave_player.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/wave_player.lib Wed Nov 02 02:02:03 2016 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/sravet/code/wave_player/#acc3e18e77ad