PokittoLib is the library needed for programming the Pokitto DIY game console (www.pokitto.com)

Dependents:   YATTT sd_map_test cPong SnowDemo ... more

PokittoLib

Library for programming Pokitto hardware

How to Use

  1. Import this library to online compiler (see button "import" on the right hand side
  2. DO NOT import mbed-src anymore, a better version is now included inside PokittoLib
  3. Change My_settings.h according to your project
  4. Start coding!
Committer:
Pokitto
Date:
Wed Dec 25 23:59:52 2019 +0000
Revision:
71:531419862202
Parent:
5:ea7377f3d1af
Changed Mode2 C++ refresh code (graphical errors)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Pokitto 5:ea7377f3d1af 1 #include "CallChain.h"
Pokitto 5:ea7377f3d1af 2 #include "cmsis.h"
Pokitto 5:ea7377f3d1af 3
Pokitto 5:ea7377f3d1af 4 namespace mbed {
Pokitto 5:ea7377f3d1af 5
Pokitto 5:ea7377f3d1af 6 CallChain::CallChain(int size) : _chain(), _size(size), _elements(0) {
Pokitto 5:ea7377f3d1af 7 _chain = new pFunctionPointer_t[size]();
Pokitto 5:ea7377f3d1af 8 }
Pokitto 5:ea7377f3d1af 9
Pokitto 5:ea7377f3d1af 10 CallChain::~CallChain() {
Pokitto 5:ea7377f3d1af 11 clear();
Pokitto 5:ea7377f3d1af 12 delete _chain;
Pokitto 5:ea7377f3d1af 13 }
Pokitto 5:ea7377f3d1af 14
Pokitto 5:ea7377f3d1af 15 pFunctionPointer_t CallChain::add(void (*function)(void)) {
Pokitto 5:ea7377f3d1af 16 return common_add(new FunctionPointer(function));
Pokitto 5:ea7377f3d1af 17 }
Pokitto 5:ea7377f3d1af 18
Pokitto 5:ea7377f3d1af 19 pFunctionPointer_t CallChain::add_front(void (*function)(void)) {
Pokitto 5:ea7377f3d1af 20 return common_add_front(new FunctionPointer(function));
Pokitto 5:ea7377f3d1af 21 }
Pokitto 5:ea7377f3d1af 22
Pokitto 5:ea7377f3d1af 23 int CallChain::size() const {
Pokitto 5:ea7377f3d1af 24 return _elements;
Pokitto 5:ea7377f3d1af 25 }
Pokitto 5:ea7377f3d1af 26
Pokitto 5:ea7377f3d1af 27 pFunctionPointer_t CallChain::get(int i) const {
Pokitto 5:ea7377f3d1af 28 if (i < 0 || i >= _elements)
Pokitto 5:ea7377f3d1af 29 return NULL;
Pokitto 5:ea7377f3d1af 30 return _chain[i];
Pokitto 5:ea7377f3d1af 31 }
Pokitto 5:ea7377f3d1af 32
Pokitto 5:ea7377f3d1af 33 int CallChain::find(pFunctionPointer_t f) const {
Pokitto 5:ea7377f3d1af 34 for (int i = 0; i < _elements; i++)
Pokitto 5:ea7377f3d1af 35 if (f == _chain[i])
Pokitto 5:ea7377f3d1af 36 return i;
Pokitto 5:ea7377f3d1af 37 return -1;
Pokitto 5:ea7377f3d1af 38 }
Pokitto 5:ea7377f3d1af 39
Pokitto 5:ea7377f3d1af 40 void CallChain::clear() {
Pokitto 5:ea7377f3d1af 41 for(int i = 0; i < _elements; i ++) {
Pokitto 5:ea7377f3d1af 42 delete _chain[i];
Pokitto 5:ea7377f3d1af 43 _chain[i] = NULL;
Pokitto 5:ea7377f3d1af 44 }
Pokitto 5:ea7377f3d1af 45 _elements = 0;
Pokitto 5:ea7377f3d1af 46 }
Pokitto 5:ea7377f3d1af 47
Pokitto 5:ea7377f3d1af 48 bool CallChain::remove(pFunctionPointer_t f) {
Pokitto 5:ea7377f3d1af 49 int i;
Pokitto 5:ea7377f3d1af 50
Pokitto 5:ea7377f3d1af 51 if ((i = find(f)) == -1)
Pokitto 5:ea7377f3d1af 52 return false;
Pokitto 5:ea7377f3d1af 53 if (i != _elements - 1)
Pokitto 5:ea7377f3d1af 54 memmove(_chain + i, _chain + i + 1, (_elements - i - 1) * sizeof(pFunctionPointer_t));
Pokitto 5:ea7377f3d1af 55 delete f;
Pokitto 5:ea7377f3d1af 56 _elements --;
Pokitto 5:ea7377f3d1af 57 return true;
Pokitto 5:ea7377f3d1af 58 }
Pokitto 5:ea7377f3d1af 59
Pokitto 5:ea7377f3d1af 60 void CallChain::call() {
Pokitto 5:ea7377f3d1af 61 for(int i = 0; i < _elements; i++)
Pokitto 5:ea7377f3d1af 62 _chain[i]->call();
Pokitto 5:ea7377f3d1af 63 }
Pokitto 5:ea7377f3d1af 64
Pokitto 5:ea7377f3d1af 65 void CallChain::_check_size() {
Pokitto 5:ea7377f3d1af 66 if (_elements < _size)
Pokitto 5:ea7377f3d1af 67 return;
Pokitto 5:ea7377f3d1af 68 _size = (_size < 4) ? 4 : _size + 4;
Pokitto 5:ea7377f3d1af 69 pFunctionPointer_t* new_chain = new pFunctionPointer_t[_size]();
Pokitto 5:ea7377f3d1af 70 memcpy(new_chain, _chain, _elements * sizeof(pFunctionPointer_t));
Pokitto 5:ea7377f3d1af 71 delete _chain;
Pokitto 5:ea7377f3d1af 72 _chain = new_chain;
Pokitto 5:ea7377f3d1af 73 }
Pokitto 5:ea7377f3d1af 74
Pokitto 5:ea7377f3d1af 75 pFunctionPointer_t CallChain::common_add(pFunctionPointer_t pf) {
Pokitto 5:ea7377f3d1af 76 _check_size();
Pokitto 5:ea7377f3d1af 77 _chain[_elements] = pf;
Pokitto 5:ea7377f3d1af 78 _elements ++;
Pokitto 5:ea7377f3d1af 79 return pf;
Pokitto 5:ea7377f3d1af 80 }
Pokitto 5:ea7377f3d1af 81
Pokitto 5:ea7377f3d1af 82 pFunctionPointer_t CallChain::common_add_front(pFunctionPointer_t pf) {
Pokitto 5:ea7377f3d1af 83 _check_size();
Pokitto 5:ea7377f3d1af 84 memmove(_chain + 1, _chain, _elements * sizeof(pFunctionPointer_t));
Pokitto 5:ea7377f3d1af 85 _chain[0] = pf;
Pokitto 5:ea7377f3d1af 86 _elements ++;
Pokitto 5:ea7377f3d1af 87 return pf;
Pokitto 5:ea7377f3d1af 88 }
Pokitto 5:ea7377f3d1af 89
Pokitto 5:ea7377f3d1af 90 } // namespace mbed