Skip to content
Snippets Groups Projects
Behaviours.hpp 1.5 KiB
Newer Older
Matthew's avatar
Matthew committed
#ifndef BEHAVIOUR_h
#define BEHAVIOUR_h

class Behaviour {
protected:
  boolean _interruptable = true;
  boolean _temp = false;
  boolean _priority = false;
  boolean _running = false;
  boolean _background = false;
  String _name = "name";

public:
  Behaviour(String name);
  ~Behaviour();
Matthew's avatar
Matthew committed

  //Can this behaviour be interruped
  virtual boolean is_interruptable();
  //Can this behaviour be run quickly without stopping what's going on (e.g. comms, debug)
  virtual boolean is_temp();
  //Should this behaviour override others
  virtual boolean is_priority();
  //Is the behaviour running
  virtual boolean is_running();
  //What's the name of this behaviour
  virtual boolean is_background();
  //What's the name of this behaviour
  virtual String name();
  //What arguments does the behaviour take? Override this to document your behaviour
  virtual char* args();
  //Start the behaviour, with arguments (don't know why this can't be virtual?)
  virtual String start(String args);
  //Update the behaviour periodically
  virtual void update();
  //Start the behaviour, with arguments (don't know why this can't be virtual?)
  virtual void stop();
};

/*
 * Example way to make a simple behaviour
 */
class TestBehaviour : public Behaviour {
public:
  TestBehaviour(String n);
  String start(String args);
};


class BehaviourTable
{
  Behaviour* behaviours[40];

public:
  int num = 0;

  BehaviourTable();

  void add(Behaviour *b) ;
  Behaviour* get(String n);
  Behaviour* get_by_num(int n);

  int get_num_behaviours();
};

#endif