Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
58be77e
commit 923f846
Showing
12 changed files
with
670 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
|
||
int LEDval; | ||
int ULval; | ||
int URval; | ||
int LLval; | ||
int LRval; | ||
#define UL 6 | ||
#define UR 9 | ||
#define LR 10 | ||
#define LL 11 | ||
|
||
enum { | ||
TokenIdxLeft = 0, | ||
TokenIdxRight, | ||
TokenIdxSpeed, | ||
NumTokenIdxs | ||
}; | ||
|
||
void setup() | ||
{ | ||
Serial.begin(9600); | ||
pinMode(13, OUTPUT); | ||
pinMode(UL, OUTPUT); | ||
pinMode(UR, OUTPUT); | ||
pinMode(LL, OUTPUT); | ||
pinMode(LR, OUTPUT); | ||
|
||
LEDval = LOW; | ||
ULval = 255; | ||
URval = 255; | ||
LLval = 255; | ||
LRval = 255; | ||
// establishContact(); | ||
} | ||
|
||
/* | ||
void establishContact() { | ||
while (Serial.available() <= 0) { | ||
Serial.println("!"); // send a starting message | ||
delay(300); | ||
} | ||
} | ||
*/ | ||
|
||
void loop() | ||
{ | ||
digitalWrite(13, LEDval); | ||
analogWrite(UL, ULval); | ||
analogWrite(UR, URval); | ||
analogWrite(LL, LLval); | ||
analogWrite(LR, LRval); | ||
|
||
int analogIn = analogRead(A0) / 4; | ||
|
||
if(Serial.available()){ | ||
|
||
int MAX_CHAR = 100; | ||
char readVal[MAX_CHAR]; | ||
int numChar = Serial.readBytesUntil('\n', readVal, MAX_CHAR); | ||
String inVal = String(readVal).substring(0,numChar); | ||
|
||
if(inVal.indexOf(',') != -1){ | ||
char tokens[numChar]; | ||
inVal.toCharArray(tokens, numChar); | ||
char *token; | ||
char *ts=tokens; | ||
int tkIdx=0; | ||
int tokInts[NumTokenIdxs]; | ||
while ((token = strtok_r(ts, ",", &ts)) != NULL){ | ||
|
||
if(tkIdx<NumTokenIdxs){ | ||
tokInts[tkIdx] = atol(token); | ||
} | ||
tkIdx++; | ||
} | ||
|
||
if(tkIdx == NumTokenIdxs){ | ||
|
||
if(tokInts[TokenIdxLeft] > 0){ | ||
ULval = tokInts[TokenIdxLeft]; | ||
LLval = 0; | ||
}else{ | ||
LLval = abs(tokInts[TokenIdxLeft]); | ||
ULval = 0; | ||
} | ||
|
||
|
||
if(tokInts[TokenIdxRight] > 0){ | ||
URval = tokInts[TokenIdxRight]; | ||
LRval = 0; | ||
}else{ | ||
LRval = abs(tokInts[TokenIdxRight]); | ||
URval = 0; | ||
} | ||
|
||
} | ||
|
||
}else{ | ||
|
||
if(inVal == "hotdog"){ | ||
LEDval = HIGH; | ||
}else if(inVal == "hamburger"){ | ||
LEDval = LOW; | ||
} | ||
|
||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#pragma once | ||
#include "cinder/CinderResources.h" | ||
|
||
//#define RES_MY_RES CINDER_RESOURCE( ../resources/, image_name.png, 128, IMAGE ) |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
#include "cinder/app/AppBasic.h" | ||
#include "cinder/gl/gl.h" | ||
#include "cinder/Serial.h" | ||
#include <boost/lexical_cast.hpp> | ||
|
||
using namespace ci; | ||
using namespace ci::app; | ||
using namespace std; | ||
|
||
class SerialTestApp : public AppBasic { | ||
public: | ||
void setup(); | ||
void mouseDown( MouseEvent event ); | ||
void mouseUp( MouseEvent event ); | ||
void mouseDrag( MouseEvent event ); | ||
void update(); | ||
void draw(); | ||
Serial serial; | ||
Vec2f mousePos; | ||
}; | ||
|
||
void SerialTestApp::setup() | ||
{ | ||
// print the devices | ||
const vector<Serial::Device> &devices( Serial::getDevices() ); | ||
for( vector<Serial::Device>::const_iterator deviceIt = devices.begin(); deviceIt != devices.end(); ++deviceIt ) { | ||
console() << "Device: " << deviceIt->getName() << endl; | ||
} | ||
|
||
try { | ||
Serial::Device dev = Serial::findDeviceByNameContains("tty.usbmodemfa141"); | ||
serial = Serial( dev, 9600); | ||
serial.flush(); | ||
} | ||
catch( ... ) { | ||
console() << "There was an error initializing the serial device!" << std::endl; | ||
exit( -1 ); | ||
} | ||
|
||
} | ||
|
||
void SerialTestApp::mouseDown( MouseEvent event ) | ||
{ | ||
serial.writeString("hotdog\n"); | ||
} | ||
|
||
void SerialTestApp::mouseDrag( MouseEvent event ) | ||
{ | ||
mousePos = event.getPos(); | ||
Vec2f offset = mousePos - getWindowCenter(); | ||
|
||
float speed = offset.length(); | ||
offset.normalize(); | ||
float amtLeftWheel = 0; | ||
float amtRightWheel = 0; | ||
|
||
// Always having one wheel moving forward ensures we're | ||
// driving forward. We can't drive backwards. | ||
if(offset.x < 0){ | ||
amtRightWheel = 1; | ||
amtLeftWheel = offset.y*-1; | ||
}else{ | ||
amtLeftWheel = 1; | ||
amtRightWheel = offset.y*-1; | ||
} | ||
|
||
int lw = amtLeftWheel*255; // -255..255 | ||
int rw = amtRightWheel*255; // -255..255 | ||
int sp = (int)speed; | ||
string directions = "" + boost::lexical_cast<string>((int)lw) + "," + | ||
boost::lexical_cast<string>((int)rw) + "," + | ||
boost::lexical_cast<string>((int)sp) + ",\n"; | ||
serial.writeString(directions); | ||
} | ||
|
||
void SerialTestApp::mouseUp( MouseEvent event ) | ||
{ | ||
serial.writeString("hamburger\n"); | ||
} | ||
|
||
void SerialTestApp::update() | ||
{ | ||
|
||
} | ||
|
||
void SerialTestApp::draw() | ||
{ | ||
// clear out the window with black | ||
gl::clear( Color( 0, 0, 0 ) ); | ||
gl::color(1, 1, 1); | ||
gl::drawSolidCircle(getWindowCenter(), 10); | ||
gl::color(1, 0, 0); | ||
glLineWidth(5); | ||
gl::drawLine(getWindowCenter(), mousePos); | ||
} | ||
|
||
|
||
CINDER_APP_BASIC( SerialTestApp, RendererGl ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>CFBundleDevelopmentRegion</key> | ||
<string>English</string> | ||
<key>CFBundleExecutable</key> | ||
<string>${EXECUTABLE_NAME}</string> | ||
<key>CFBundleIconFile</key> | ||
<string>CinderApp.icns</string> | ||
<key>CFBundleIdentifier</key> | ||
<string>org.libcinder.SerialTest</string> | ||
<key>CFBundleInfoDictionaryVersion</key> | ||
<string>6.0</string> | ||
<key>CFBundleName</key> | ||
<string>${PRODUCT_NAME}</string> | ||
<key>CFBundlePackageType</key> | ||
<string>APPL</string> | ||
<key>CFBundleSignature</key> | ||
<string>????</string> | ||
<key>CFBundleVersion</key> | ||
<string>1.0</string> | ||
<key>NSMainNibFile</key> | ||
<string>MainMenu</string> | ||
<key>NSPrincipalClass</key> | ||
<string>NSApplication</string> | ||
</dict> | ||
</plist> |
Oops, something went wrong.