Simple framework to allow for mini-programs, or Sketchlets, to be executed on a single SoC. Distributed under the MIT license.

Arduino version of this library can be found at https://github.com/murrellrr/arduino_sketchlet.

Example Usage:

Inside your man.cpp file.

#include "main.h"

using namespace com::aerialspecs::mbed::sketchlet;

void setup() {
    controller = new Controller(MAX_SKETCHLET_SIZE);
    controller->setup();
}

bool loop() {
    return controller->loop();
}

void shutdown() {
    delete controller;
}

/**
 * 
 */
int main() {
    setup();
    while(loop()) {}
    shutdown();
}

Creating a Sketchlet:

A sample of a Sketchlet. DefaultSketchlet.h and DefaultSketchlet.cpp

// In your header file.

#define LED_PIN                  13
#define BLINK_TIMEOUT     1000

#include "Sketchlet.h"

using namespace com::aerialspecs::mbed::sketchlet;

class DefaultSketchlet : public Sketchlet {
public:
	DefaultSketchlet();

	virtual void initialize();

	virtual bool loop();

	virtual void terminate();

	virtual ~DefaultSketchlet();

private:
	uint32_t lastTime;
};

// Inside CPP file.

#include "DefaultSketchlet.h"

using namespace com::aerialspecs::mbed::sketchlet;

DefaultSketchlet::DefaultSketchlet() : public Sketchlet() {
	this->lastTime = millis();
}

void DefaultSketchlet::initialize() {
	// initialize your led
}

bool DefaultSketchlet::loop() {
	uint32_t currentTime = millis();

	if((currentTime - this->lastTime) >= BLINK_TIMEOUT) {
		// toggle your led
		this->lastTime = currentTime;
	}

	return true;
}

void DefaultSketchlet::terminate() {
	// release the LED, if required by your platform.
}

DefaultSketchlet::~DefaultSketchlet() {
	// cleanup anything...
}

Using your sketchlet:

Using your sketchlet

#include "main.h"
 
using namespace com::aerialspecs::mbed::sketchlet;
 
void setup() {
    controller = new Controller(MAX_SKETCHLET_SIZE);
    sketchlet  = new DefaultSketchlet();

    controller->append(sketchlet);
    controller->setup();
}

You can append multiple sketchlets up to the number defined in the Controller constructor. The controller will run the sketchlets in the order they are registered under normal conditions. Returning false from a sketchlet will cause the controller to invoke the terminate life-cycle of the current sketchlet, load the next one as current, and execute the initialize life-cycle.

If you need to execute a sketchlet out of order you may execute the Controller::gotoSketchlet(uint8_t at) function to go to a specific sketchlet. Please note, in the current version, the "GOTO" does not update the iterator so completing the sketchlet you "GOTO" will cause the controller to go to the next sketchlet from the first time "GOTO" was invoked, NOT from the current sketchlet.

ENJOY!!!

Files at this revision

API Documentation at this revision

Comitter:
aerialspecs
Date:
Fri Jan 20 15:10:27 2017 +0000
Parent:
2:82fa1c7a259f
Commit message:
Removed default constructor from ArrayList. Embedded environment is too constrained to allow for arbitrary sizing.

Changed in this revision

ArrayList.h Show annotated file Show diff for this revision Revisions of this file
ArrayList.hpp Show annotated file Show diff for this revision Revisions of this file
--- a/ArrayList.h	Fri Jan 20 15:07:53 2017 +0000
+++ b/ArrayList.h	Fri Jan 20 15:10:27 2017 +0000
@@ -41,11 +41,6 @@
 class ArrayList {
 public:
     /**
-     * \brief Default Constructor. Creates an ArrayList with an array size of 4.
-     */
-    ArrayList();
-
-    /**
      * \brief Creates a new ArrayList with an array size specified by usize.
      *
      * \param usize An unsigned byte specifying the array size, or the maximum number
--- a/ArrayList.hpp	Fri Jan 20 15:07:53 2017 +0000
+++ b/ArrayList.hpp	Fri Jan 20 15:10:27 2017 +0000
@@ -27,12 +27,6 @@
 namespace mbed {
 namespace sketchlet {
 
-template <class T> ArrayList<T>::ArrayList() {
-    this->usize     = ARRAYLIST_DEFAULT_SIZE;
-    this->elements  = new T[this->usize];
-    this->index     = 0;
-}
-
 template <class T> ArrayList<T>::ArrayList(uint8_t usize) {
     this->usize     = usize;
     this->elements  = new T[this->usize];