Skip to content

Commit

Permalink
started workin on EEG animation mode (behind a #define so people can …
Browse files Browse the repository at this point in the history
…still compile this without)
  • Loading branch information
rambo committed Jun 25, 2013
1 parent d3b7e6e commit 8d2c4d6
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
36 changes: 36 additions & 0 deletions software/arduino/partyhatwork/brain_tasks.h
@@ -0,0 +1,36 @@
#ifndef BRAIN_TASKS_H
#ifndef BRAIN_SERIAL
#error "BRAIN_SERIAL not defined"
#endif
#define BRAIN_TASKS_H

#include "animation_tasks.h"

class EEGAnimation : public AnimationRunner
{
};

class EEGReader : public Task
{
public:
EEGReader();
virtual void run(uint32_t now);
virtual bool canRun(uint32_t now);
};

EEGReader::EEGReader()
: Task()
{
}

bool EEGReader::canRun(uint32_t now)
{
return (boolean)BRAIN_SERIAL.available();
}

void EEGReader::run(uint32_t now)
{

}

#endif
16 changes: 16 additions & 0 deletions software/arduino/partyhatwork/partyhatwork.ino
Expand Up @@ -32,6 +32,9 @@ SERIAL_DEFINE(Serial3, E, 0); -> PE2/PE3 == 2/3
*
*/

// If you have EEG module connected, connect it here.
#define BRAIN_SERIAL Serial1

// Get this library from http://code.google.com/p/xbee-arduino/
#include <XBee.h>

Expand Down Expand Up @@ -60,6 +63,13 @@ SERIAL_DEFINE(Serial3, E, 0); -> PE2/PE3 == 2/3
#include "animations.h"
AnimationRunner anim_runner;

#ifdef BRAIN_SERIAL
#include "brain_tasks.h"
EEGReader eeg_reader;
EEGAnimation eeg_anim;
#endif



void load_nth_animation(uint8_t n)
{
Expand Down Expand Up @@ -242,12 +252,18 @@ void loop()
blinker.on_time = 250;

// Start a "demo mode"
#ifndef BRAIN_SERIAL
anim_switcher.start_cycle();
#endif BRAIN_SERIAL


// Tasks are in priority order, only one task is run per tick, be sure to keep sleeper as last task if you use it.
//Task *tasks[] = { &xbeereader, &batterymonitor };
#ifdef BRAIN_SERIAL
Task *tasks[] = { &xbeereader, &eeg_reader, &eeg_anim, &anim_switcher, &anim_runner, &blinker, &batterymonitor, &sleeper };
#else
Task *tasks[] = { &xbeereader, &anim_switcher, &anim_runner, &blinker, &batterymonitor, &sleeper };
#endif
TaskScheduler sched(tasks, NUM_TASKS(tasks));

// Run the scheduler - never returns.
Expand Down
4 changes: 4 additions & 0 deletions software/arduino/partyhatwork/xbee_tasks.h
Expand Up @@ -7,6 +7,7 @@
#include <Task.h>
#include <XBee.h>

// Reminder, XBee uses by defaul the first Serial object ("Serial")

XBee xbee = XBee();
XBeeResponse response = XBeeResponse();
Expand Down Expand Up @@ -55,8 +56,11 @@ XBeeRead::XBeeRead()
// We can't just return true since then no other task could ever run (since we have the priority)
bool XBeeRead::canRun(uint32_t now)
{
return (boolean)Serial.available();
/*
yield_counter++;
return ((yield_counter % XBEE_READ_YIELD_TICKS) == 1);
*/
}

void XBeeRead::run(uint32_t now)
Expand Down

0 comments on commit 8d2c4d6

Please sign in to comment.