Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
CommandPool.cpp
- Committer:
- Xiaofei
- Date:
- 2015-11-28
- Revision:
- 6:88382274a161
- Parent:
- 5:7fa548878fac
- Child:
- 7:bfbded2b0e8c
File content as of revision 6:88382274a161:
#pragma once
#include "CommandPool.h"
#include <iterator>
#include <utility>
#include "mbed.h"
CommandPool:: ~CommandPool()
{
mapIterator map_it;
for(map_it = _pool.begin(); map_it != _pool.end(); map_it++)
{
if(map_it->second)
{
delete map_it->second; // free command*
}
}
}
void CommandPool::init()
{
/* Allocate commands in heap to avoid push/pop to/from the stack */
_pool[LED] = new LedCommand();
_pool[TURN_LEFT] = new TurnLeftCommand();
_pool[TURN_RIGHT] = new TurnRightCommand();
_pool[STOP] = new StopCommand();
}
Command* CommandPool::getCommand(const char& cmdstr)
{
static char cmd = '\0';
static int8_t is_negative = 0;
static int8_t sp = 0;
cmd = cmdstr & 0x07;
is_negative = (cmdstr & 0x08) >> 3;
sp = (cmdstr & 0xF0) >> 4;
_pool[cmd]->setSpeed(sp,is_negative);
return _pool[cmd];
}