Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Electron Shell #223

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/Bootstrap/Bootstrap.ino
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <Wire.h>
#include <Scout.h>
#include <GS.h>
#include <electron.h>
#include <bitlash.h>
#include <lwm.h>
#include <js0n.h>
Expand Down
37 changes: 37 additions & 0 deletions examples/Electron/Electron.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**************************************************************************\
* Pinoccio Library *
* https://github.com/Pinoccio/library-pinoccio *
* Copyright (c) 2014, Pinoccio Inc. All rights reserved. *
* ------------------------------------------------------------------------ *
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the MIT License as described in license.txt. *
\**************************************************************************/
#include <SPI.h>
#include <Wire.h>
#include <Scout.h>
#include <GS.h>
#include <bitlash.h>
#include <lwm.h>
#include <js0n.h>
#include <electron.h>

#include "version.h"

void *e_debug(const char *file, int line, const char *function, const char * format, ...)
{
Serial.print(file);
Serial.print(" ");
Serial.println(line);
}

void setup() {
Scout.setup(SKETCH_NAME, SKETCH_REVISION, SKETCH_BUILD);
// Add custom setup code here
e_t e = e_val(NULL,"foo bar, boo baz, \"biz\":424242",0);
Serial.println(e_count(e));
}

void loop() {
Scout.loop();
// Add custom loop code here
}
3 changes: 3 additions & 0 deletions examples/Electron/version.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#define SKETCH_NAME "Custom"
#define SKETCH_BUILD -1
#define SKETCH_REVISION "unknown"
4 changes: 4 additions & 0 deletions src/Scout.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
#ifndef LIB_PINOCCIO_SCOUT_H_
#define LIB_PINOCCIO_SCOUT_H_

#include <bitlash.h>
#include <src/bitlash.h>

#include <Pinoccio.h>
#include <Shell.h>
#include <ScoutHandler.h>
Expand All @@ -24,6 +27,7 @@
#include "peripherals/halFuelGauge.h"
#include "peripherals/halRgbLed.h"


// This is a temporary hack to check the result of snprintf and print an
// error
/*
Expand Down
4 changes: 2 additions & 2 deletions src/ScoutHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
* under the terms of the BSD License as described in license.txt. *
\**************************************************************************/
#include <Arduino.h>
#include <Shell.h>
#include <Scout.h>
#include <Shell.h>
#include "SleepHandler.h"
#include "backpack-bus/PBBP.h"
#include "util/StringBuffer.h"
Expand Down Expand Up @@ -554,7 +554,7 @@ void leadIncoming(const char *packet, size_t len, unsigned short *index) {

if (strcmp(type, "online") == 0) {
// fire the online event for everyone
Shell.eval(F("command.all(\"hq.online\",2)"));
// Shell.eval(F("command.all(\"hq.online\",2)"));
}

if (strcmp(type, "command") == 0) {
Expand Down
10 changes: 8 additions & 2 deletions src/Shell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
#include "hq/HqHandler.h"
#include "backpacks/Backpacks.h"
#include "backpacks/wifi/WifiModule.h"
#include "bitlash.h"
#include "src/bitlash.h"
#include <electron.h>
#include "util/String.h"
#include "util/PrintToString.h"
#include "modules/ModuleHandler.h"
Expand All @@ -32,6 +31,13 @@ static bool isMeshVerbose = 0;
* HELPER FUNCTIONS *
\****************************/

void *e_debug(const char *file, int line, const char *function, const char * format, ...)
{
Serial.print(file);
Serial.print(" ");
Serial.println(line);
}

static void printSpaces(int8_t number) {
while (number-- > 0)
Serial.write(' ');
Expand Down
27 changes: 6 additions & 21 deletions src/Shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#ifndef LIB_PINOCCIO_SHELL_H_
#define LIB_PINOCCIO_SHELL_H_

#include "bitlash.h"
#include "src/bitlash.h"
#include <electron.h>
#include "Scout.h"

#include "lwm/sys/sysConfig.h"
#include "lwm/phy/phy.h"
Expand Down Expand Up @@ -167,30 +167,15 @@ static void evalPrint(uint8_t c) {
evalOutput->write(c);
}

static e_t ele_stack = NULL;
inline numvar PinoccioShell::eval(Print *out, const String &cmd) {
if (isVerbose) {
Serial.print(F("running eval of: "));
Serial.println((char*)cmd.c_str());
}

if (out) {
evalOutput = out;
setOutputHandler(evalPrint);
}else if(isMuted){
// print nowhere
evalOutput = NULL;
setOutputHandler(evalPrint);
}
ele_stack = e_val(ele_stack, (char*)cmd.c_str(), 0);
out->write(e_vchar(ele_stack),e_vlen(ele_stack));

numvar ret = doCommand((char*)cmd.c_str());

if (out || isMuted)
resetOutputHandler();

// important, if we eval'd a new function update our cache
if(cmd.startsWith("function ")) refresh();

return ret;
return 0;
}

#endif