Mutila: Mouse's Utilities for Arduino
Oft-used utilities: debouncing buttons, averaging samples, and so on.
ModeManager.cpp
1 #include <MutilaDebug.h>
2 #include "ModeManager.h"
3 
4 ModeManager::ModeManager() :
5  currentMode(NULL)
6 {
7 }
8 
9 void ModeManager::begin(Mode* initialMode)
10 {
11  DBLN(F("ModeManager::begin"));
12  switchMode(initialMode);
13 }
14 
16 {
17  if (currentMode != NULL) {
18  currentMode->update();
19  }
20 }
21 
22 void ModeManager::switchMode(Mode* newMode, bool force)
23 {
24  if ((newMode != currentMode) || force) {
25  if (currentMode != NULL) {
26  currentMode->stop();
27  }
28  currentMode = newMode;
29  currentMode->start();
30  }
31 }
32 
34 {
35  if (currentMode != NULL) {
36  return currentMode->isFinished();
37  } else {
38  return false;
39  }
40 }
41 
bool modeFinished()
Definition: ModeManager.cpp:33
virtual void update()
Definition: Mode.h:85
Definition: Mode.h:39
void begin(Mode *initialMode)
Definition: ModeManager.cpp:9
void stop()
Definition: Mode.h:72
void switchMode(Mode *newMode, bool force=false)
Definition: ModeManager.cpp:22
void update()
Definition: ModeManager.cpp:15
virtual bool isFinished()
Definition: Mode.h:64
void start()
Definition: Mode.h:68