Skip to content

Commit

Permalink
compiles !
Browse files Browse the repository at this point in the history
  • Loading branch information
supertick committed Nov 6, 2016
1 parent 14ed8c8 commit 0674d42
Show file tree
Hide file tree
Showing 19 changed files with 547 additions and 26 deletions.
3 changes: 2 additions & 1 deletion MrlCmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,5 @@ unsigned char MrlCmd::getIoCmd(int pos){

int MrlCmd::getMsgSize(){
return msgSize;
}
}

22 changes: 11 additions & 11 deletions MrlComm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,17 +395,17 @@ void MrlComm::setPWMFrequency(int address, int prescalar) {
// sets frequency of pwm of analog
// FIXME - us ifdef appropriate uC which
// support these clocks TCCR0B
int clearBits = 0x07;
if (address == 0x25) {
TCCR0B &= ~clearBits;
TCCR0B |= prescalar;
} else if (address == 0x2E) {
TCCR1B &= ~clearBits;
TCCR1B |= prescalar;
} else if (address == 0xA1) {
TCCR2B &= ~clearBits;
TCCR2B |= prescalar;
}
// int clearBits = 0x07;
// if (address == 0x25) {
// TCCR0B &= ~clearBits;
// TCCR0B |= prescalar;
// } else if (address == 0x2E) {
// TCCR1B &= ~clearBits;
// TCCR1B |= prescalar;
// } else if (address == 0xA1) {
// TCCR2B &= ~clearBits;
// TCCR2B |= prescalar;
// }
}

// SET_SERIAL_RATE
Expand Down
2 changes: 1 addition & 1 deletion MrlComm.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,4 @@ class MrlComm{
int getCustomMsgSize();
};

#endif
#endif
2 changes: 1 addition & 1 deletion MrlI2cBus.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ class MrlI2CBus : public Device {
void update();
};

#endif
#endif
2 changes: 1 addition & 1 deletion MrlIo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,4 @@ void MrlIo::flush() {
serial->flush();
}



2 changes: 1 addition & 1 deletion MrlIo.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ class MrlIo {
void test();
};

#endif
#endif
11 changes: 9 additions & 2 deletions MrlNeopixel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ bool MrlNeopixel::deviceAttach(unsigned char config[], int configSize) {
}

inline void MrlNeopixel::sendBitB(bool bitVal) {
#ifndef VIRTUAL_ARDUINO_H
uint8_t bit = bitmask;
if (bitVal) { // 0 bit
PORTB |= bit;
Expand Down Expand Up @@ -104,9 +105,12 @@ inline void MrlNeopixel::sendBitB(bool bitVal) {
sei();
//activate interrupts
}

#endif
}

inline void MrlNeopixel::sendBitC(bool bitVal) {
#ifndef VIRTUAL_ARDUINO_H
uint8_t bit = bitmask;
if (bitVal) { // 0 bit
PORTC |= bit;
Expand Down Expand Up @@ -153,6 +157,8 @@ inline void MrlNeopixel::sendBitC(bool bitVal) {
// Note that the inter-bit gap can be as long as you want as long as it doesn't exceed the 5us reset timeout (which is A long time)
// Here I have been generous and not tried to squeeze the gap tight but instead erred on the side of lots of extra time.
// This has thenice side effect of avoid glitches on very long strings becuase

#endif
}
#if defined(ARDUINO_AVR_MEGA2560) || defined(ARDUINO_AVR_ADK)

Expand Down Expand Up @@ -515,6 +521,7 @@ inline void MrlNeopixel::sendBitA(bool bitVal) {
#endif

inline void MrlNeopixel::sendBitD(bool bitVal) {
#ifndef VIRTUAL_ARDUINO_H
uint8_t bit = bitmask;
if (bitVal) { // 0 bit
PORTD |= bit;
Expand Down Expand Up @@ -558,7 +565,7 @@ inline void MrlNeopixel::sendBitD(bool bitVal) {
sei();
//activate interrupts
}

#endif
}

inline void MrlNeopixel::sendByte(unsigned char byte) {
Expand Down Expand Up @@ -839,4 +846,4 @@ void MrlNeopixel::animationIronman() {
else lastShow = millis();
newData = true;
}


20 changes: 20 additions & 0 deletions virtual/Arduino.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "Arduino.h"

unsigned long micros(){return 0;}
unsigned long millis(){return 0;}
void digitalWrite(int pin, int value){};
void analogWrite(int pin, int value){};
void pinMode(int pin, int value){};
int digitalRead(int pin){return 0;};
int analogRead(int pin){return 0;};
void delay(int){};

uint8_t digitalPinToBitMask(int){return 0;};

void cli(){};
void sei(){};
bool bitRead(unsigned char, unsigned char){return 0;};
unsigned int random(unsigned int){return 0;};

int __brkval=0;
int __heap_start=0;
30 changes: 27 additions & 3 deletions virtual/Arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,21 @@
#define TCCR0B 0
#define TCCR1B 0
#define TCCR2B 0
#define HIGH 0x1
#define LOW 0x0

#define INPUT 0x0
#define OUTPUT 0x1
#define INPUT_PULLUP 0x2

typedef unsigned char byte;
typedef unsigned char uint8_t;

#include "Serial.h"
//#include "Serial.h"
#include <iostream>
#include "Servo.h"
#include "HardwareSerial.h"
#include "WString.h"
#include "String.h"

unsigned long micros();
unsigned long millis();
Expand All @@ -21,6 +29,22 @@ void analogWrite(int pin, int value);
void pinMode(int pin, int value);
int digitalRead(int pin);
int analogRead(int pin);
void delay(int);

uint8_t digitalPinToBitMask(int);

#define PORTB 0
#define PORTC 0
#define PORTD 0
#define F_CPU 1


void cli();
void sei();
bool bitRead(unsigned char, unsigned char);
unsigned int random(unsigned int);



#endif VIRTUAL_ARDUINO_H
#endif /*VIRTUAL_ARDUINO_H*/

109 changes: 109 additions & 0 deletions virtual/Emulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,112 @@ Emulator::~Emulator() {
// TODO Auto-generated destructor stub
}



/**
* MRLComm.c
* -----------------
* This file is part of MyRobotLab.
* (myrobotlab.org)
*
* Enjoy !
* @authors
* GroG
* Kwatters
* Mats
* calamity
* and many others...
*
* MRL Protocol definition
* -----------------
* MAGIC_NUMBER|NUM_BYTES|FUNCTION|DATA0|DATA1|....|DATA(N)
* NUM_BYTES - is the number of bytes after NUM_BYTES to the end
*
* more info - http://myrobotlab.org/content/myrobotlab-api
*
* General Concept
* -----------------
* Arduino is a slave process to MyRobotLab Arduino Service - this file receives
* commands and sends back data.
* Refactoring has made MRLComm.c far more general
* there are only 2 "types" of things - controllers and pins - or writers and readers
* each now will have sub-types
*
* Controllers
* -----------------
* digital pins, pwm, pwm/dir dc motors, pwm/pwm dc motors
*
* Sensors
* -----------------
* digital polling pins, analog polling pins, range pins, oscope, trigger events
*
* Combination
* -----------------
* pingdar, non-blocking pulsin
*
* Requirements: MyRobotLab running on a computer & a serial connection
*
* TODO - need a method to identify type of board http://forum.arduino.cc/index.php?topic=100557.0
* TODO - getBoardInfo() - returns board info !
* TODO - getPinInfo() - returns pin info !
* TODO - implement with std::vector vs linked list - https://github.com/maniacbug/StandardCplusplus/blob/master/README.md
* TODO - make MRLComm a c++ library
*/


// Included as a 3rd party arduino library from here: https://github.com/ivanseidel/LinkedList/
#include "../LinkedList.h"
#include "../MrlComm.h"
//#include <stdlib.h>
#include <iostream>

/***********************************************************************
* GLOBAL VARIABLES
* TODO - work on reducing globals and pass as parameters
*/
MrlComm mrlComm;
/***********************************************************************
* STANDARD ARDUINO BEGIN
* setup() is called when the serial port is opened unless you hack the
* serial port on your arduino
*
* Here we default out serial port to 115.2kbps.
*/
void setup() {
// TODO: the arduino service might get a few garbage bytes before we're able
// to run, we should consider some additional logic here like a "publishReset"
// publish version on startup so it's immediately available for mrl.
// TODO: see if we can purge the current serial port buffers
mrlComm.publishVersion();
// publish the board type (uno/mega)
mrlComm.publishBoardInfo();

}

/**
* STANDARD ARDUINO LOOP BEGIN
* This method will be called over and over again by the arduino, it is the
* main loop any arduino sketch runs
*/
void loop() {
// increment how many times we've run
// TODO: handle overflow here after 32k runs, i suspect this might blow up?
mrlComm.loopCount++;
// get a command and process it from the serial port (if available.)
mrlComm.readCommand();
// update devices
mrlComm.updateDevices();
// send back load time and memory
mrlComm.publishBoardStatus();
} // end of big loop

int main() {
setup();
for (int i = 0; i < 100; i++){
loop();
// printf("Worky!!!\n");
std::cout << "Hello World!";
}

return 0;
}
4 changes: 4 additions & 0 deletions virtual/HardwareSerial.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include "HardwareSerial.h"


HardwareSerial Serial;
27 changes: 27 additions & 0 deletions virtual/HardwareSerial.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* HardwareSerial_h.h
*
* Created on: Nov 3, 2016
* Author: gperry
*/

#ifndef VIRTUAL_HARDWARE_SERIAL_H_
#define VIRTUAL_HARDWARE_SERIAL_H_

class HardwareSerial {
public:
HardwareSerial(){};
virtual ~HardwareSerial(){};
void begin(int){};
void write(unsigned char){};
void write(unsigned char*, int){};
unsigned char read(){return 0;};
int available(){return 0;};
void end(){};
void flush(){};
};


extern HardwareSerial Serial;

#endif /* VIRTUAL_HARDWARE_SERIAL_H_ */
8 changes: 5 additions & 3 deletions virtual/Serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
#ifndef VIRTUAL_SERIAL_H_
#define VIRTUAL_SERIAL_H_

class Serial {
class VSerial {
public:
Serial();
virtual ~Serial();
VSerial();
virtual ~VSerial();
};

extern VSerial Serial;

#endif /* VIRTUAL_SERIAL_H_ */
8 changes: 6 additions & 2 deletions virtual/Servo.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@

class Servo {
public:
Servo();
virtual ~Servo();
Servo(){};
virtual ~Servo(){};
void detach(){};
void write(int){};
void attach(int){};
void writeMicroseconds(int){};
};

#endif /* VIRTUAL_SERVO_H_ */
Empty file added virtual/Stream.h
Empty file.
Loading

0 comments on commit 0674d42

Please sign in to comment.