Skip to content
Snippets Groups Projects
Commit 9fa037e0 authored by Joe Revans's avatar Joe Revans
Browse files

commit

parent d852bb1d
No related branches found
No related tags found
3 merge requests!4Joe merge,!2Docs,!1Pactman/VizBlocks Merge
......@@ -81,20 +81,4 @@ public:
}
};
#endif
......@@ -10,7 +10,10 @@ class NameDictionary {
keyValuePair data[50] = {
{"1a6b16", "joe"},
{"2b7c27", "cat"}
{"30d6ed", "fin"},
{"30d00b", "jim"},
{"30ce48", "sam"},
{"30db8b", "tim"},
};
int _arraySize;
......
......@@ -43,8 +43,7 @@ public:
Serial.println(data);
}
void set_wifi(boolean v ) { _wifi = v; }
void set_wifi(boolean v) { _wifi = v; }
/*
* Set up the WallVis node - WiFi, MQTT
......@@ -79,6 +78,7 @@ public:
_client = new WiFiClient();
_mqtt = new Adafruit_MQTT_Client(_client, _server, _port, "" /* mqttt username */, "" /* mqtt pass*/);
_device_subscription = new Adafruit_MQTT_Subscribe(_mqtt, _id);
_announce = new Adafruit_MQTT_Publish(_mqtt, "announce");
_my_announce_channel = String("announce/") + String(_id);
_my_announce = new Adafruit_MQTT_Publish(_mqtt, _my_announce_channel.c_str());
......@@ -95,15 +95,11 @@ public:
MQTT_connect();
}
input_publish(String("This is ") + String(_id) + String("'s input channel. Hello!"));
announce_capabilities();
Serial.println("Init finished");
}
/*
* Add a behaviour to the list of possible behaviours
*/
......@@ -160,7 +156,7 @@ public:
/*
* Process a command. This means:
* - split the command name from the arguments
* - call process_comman with the separated command and argument string
* - call process_command with the separated command and argument string
*/
String process(String input) {
int index = input.indexOf(" ");
......@@ -182,7 +178,7 @@ public:
/*
* Process a command and its arguments. This means:
* - look for a Behaiour with the right name
* - look for a Behaviour with the right name
* - if found, then call that behaviour with the arguments (which are still a single string)
*/
String process_command(String command, String args) {
......
#include "NameDictionary.h"
#include <Servo.h>
#include <WallVis.h>
//Get device name
const String device_id = String(ESP.getChipId(), HEX);
NameDictionary d;
const String name = d.get(device_id);
char _name[10];
// Set up the servo we will use
Servo s1 = Servo();
// Set up LEDs as well
#define LED_COUNT 12
#define LED_PIN D2
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
WallVis node(
"null", // Our ID
"NodeRedServer", //Wifi Access Point
"NodeR3dAP", //WiFi Password
"192.168.4.1",//IP address of Node RED server
1883 //Port for Node RED server
);
void setup()
{
// Attach the servo to the right pin on the board
s1.attach(D3);
// Start the LED library
strip.begin();
strip.fill(strip.Color(30,255,80));
strip.show();
delay(100);
strip.fill(0);
strip.show();
//Get the serial port ready
Serial.begin(115200);
Serial.println("Serial started!");
delay(500);
//Print device name
if (name == device_id) {
Serial.println("!!! This device doesn't have a name yet. Let's call it: " + name);
} else {
Serial.println("Device name: " + name);
}
name.toCharArray(_name, 10);
node.setID(_name);
//Add in a test behaviour that responds to the command 'hello'
node.add(new TestBehaviour("hello") );
//Add in three different versions of the servo wiggling, with different speed parameters
node.add(new ServoWiggle(s1, "wiggle") );
node.add(new ServoWiggle(s1, "slow_wiggle", 10) );
node.add(new ServoWiggle(s1, "fast_wiggle", 1) );
//Add in a behaviour that just goes to a certain angle, with the default name 'goto'
node.add(new ServoGoto(s1) );
//Add in a behaviour that rotates from 0 to 180 and back again (e.g. dropping a ball trustball style)
node.add(new RotateReturn(s1,"drop",1,500, 3, 175) );
//A few useful LED behaviours
node.add(new NumLEDs(&strip, "green_leds", strip.Color(10, 255, 15) ) );
node.add(new NumLEDs(&strip, "red_leds", strip.Color(255, 30, 40) ));
node.add(new NumLEDs(&strip, "leds"));
node.add(new BrightnessLEDs(&strip, "red", 0, 255 ));
node.add(new BrightnessLEDs(&strip, "green", 120, 255 ));
node.add(new BreathingLEDs(&strip, "breathe", 120, 0 ));
node.add(new BreathingLEDs(&strip, "breathe_blue", 170, 255 ));
//Initialise the whole infrastructure
node.set_wifi(true);
node.init();
delay(500);
Serial.println("PactVis Outputs Test:");
}
void loop()
{
//Should be all we have to do
node.vis_loop();
}
......@@ -50,7 +50,7 @@ void setup() {
Serial.begin(115200);
Serial.println("Serial started!");
//Pass event handlers into button
//Pass event handlers into button
b.initInterrupts(bISR);
b.setEventHandler(bCB);
......@@ -60,7 +60,7 @@ void setup() {
//Pass event handlers into rotary encoder
re.initInterrupts(reISR);
re.setEventHandler(reCB);
delay(500);
//Print device name
......@@ -74,6 +74,7 @@ void setup() {
node.setID(_name);
//Node behaviours:
// node.add(new SendCapabilities(&node) );
node.add(new ButtonClicked(&node, "ButtonClicked") );
node.add(new ButtonHeld(&node, "ButtonHeld") );
node.add(new ButtonTick(&node, "ButtonTick") );
......@@ -87,7 +88,7 @@ void setup() {
node.init();
delay(500);
Serial.println("PactVis Inputs Test:");
}
......@@ -103,7 +104,7 @@ void bCB(Button* button, uint8_t eventType, bool state) {
/*
* Button event handler that triggers WallVis behaviours
*/
String idString = String(button->getId());
Serial.println("Button ID: " + idString + " Event Type: " + String(eventType) + " State: " + String(state));
......@@ -112,7 +113,7 @@ void bCB(Button* button, uint8_t eventType, bool state) {
case Button::kEventPressed:
//Do something
break;
case Button::kEventReleased:
//Do something else
node.input_event("ButtonReleased " + idString);
......@@ -139,7 +140,7 @@ void pCB(Potentiometer* potentiometer, uint8_t eventType, uint8_t sensorValue) {
/*
* Potentiometer Event Handler that triggers WallVis behaviours
*/
String idString = String(potentiometer->getId());
Serial.println("Slider ID: " + idString + " Event Type: " + String(eventType) + " Sensor Value: " + String(sensorValue));
......@@ -149,7 +150,7 @@ void pCB(Potentiometer* potentiometer, uint8_t eventType, uint8_t sensorValue) {
//Do something
node.input_event("PotentiometerUpdated " + idString + " " + String(sensorValue));
break;
case Potentiometer::kEventUnstableUpdate:
//Do something else
break;
......@@ -160,7 +161,7 @@ void reCB(RotaryEncoder* rotaryEncoder, uint8_t eventType, int position) {
/*
* Rotary Encoder event handler that triggers WallVis behaviours
*/
String idString = String(rotaryEncoder->getId());
Serial.println("Encoder ID: " + idString + " Event Type: " + String(eventType) + " Position: " + String(position));
......@@ -170,7 +171,7 @@ void reCB(RotaryEncoder* rotaryEncoder, uint8_t eventType, int position) {
//Do something
node.input_event("RotaryEncoderUpdated " + idString + " " + String(position));
break;
case RotaryEncoder::kEventUnstableUpdate:
//Do something else
break;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment