The Squirrel interpreter for FRDM-K64F, extended with a set of classes that provide access to the mbed functionality (currently DigitalIn, DigitalInOut, DigitalOut, InterruptIn, PwmOut, Ticker, Timeout, Timer).

Dependencies:   SQUIRREL3 mbed sqbind-0_99

The Squirrel interpreter for FRDM-K64F.

NOTE: Currently of POC quality.

See http://www.squirrel-lang.org/ for information about the Squirrel language.

Currently the following (a subset of their functionality) mbed classes are available from within Squirrel:

  • DigitalIn
  • DigitalOut
  • DigitalInOut
  • PwmOut
  • Ticker
  • Timeout
  • Timer

In addition, InterruptIn is supported, but interrupts are noted when they occur, but only delivered from the main loop of the interpreter.

See also README.txt in the root of the project.

sqmbed/src/timeout.cpp

Committer:
jhnwkmn
Date:
2014-12-16
Revision:
0:6f55c7651ccc
Child:
1:540008bb92a2

File content as of revision 0:6f55c7651ccc:

/*
  @License@
*/

#include <sqmbed/timeout.h>

template<>
struct SqBindAllocator<SqMbed::Timeout> {
    static SQBIND_INLINE SqMbed::Timeout *construct(HSQUIRRELVM vm) {
        SqMbed::Timeout* pThis = 0;

        if (SqMbed::Trigger::reserve()) {
            pThis = new SqMbed::Timeout(vm);
        } else {
            printf("Out of memory\n");
        }

        return pThis;
    }

    static SQBIND_INLINE SqMbed::Timeout *copy_construct(const SqMbed::Timeout* p_from) {
        return NULL; // make it not able to copy-construct
    }

    static SQBIND_INLINE bool assign(SqMbed::Timeout* p_val, const SqMbed::Timeout* p_from) {
        return false; // make it not able to assign
    }

    static SQBIND_INLINE void destruct(SqMbed::Timeout* p_instance) {
        delete p_instance;
    }

    static SQBIND_INLINE SqMbed::Timeout& get_empty() {
        // if someone tries to assign, this will crash.
        // however, this will likely never be called anyway.
        static SqMbed::Timeout *crashplease=NULL;
        return *crashplease;
    }
};

namespace SqMbed
{

Timeout::Timeout(HSQUIRRELVM vm)
    : Trigger(vm)
{
}

Timeout::~Timeout()
{
}

void Timeout::attach(HSQOBJECT o, float t)
{
    Trigger::attach(o);

    void (Timeout::*pTrigger)() = &Timeout::triggered;

    m_timeout.attach(this, pTrigger, t);
}

void Timeout::detach()
{
    m_timeout.detach();
}

// static
void Timeout::bind(HSQUIRRELVM vm)
{
    SqBind<Timeout>::init(vm, _SC("Timeout"));

    sqbind_method(vm, "attach", &Timeout::attach);
    sqbind_method(vm, "detach", &Timeout::detach);
}

}