YAY Finally

master
Ambrose Chua 2014-06-05 22:02:57 +08:00
parent fa50e882bc
commit 408cb00b04
102 changed files with 11700 additions and 0 deletions

169
arduinowiflynodebot.ino Normal file
View File

@ -0,0 +1,169 @@
//motor A connected between A01 and A02
//motor B connected between B01 and B02
// http://opensource.org/licenses/mit-license.php
#include <WiFly.h>
#include <SPI.h>
int STBY = 10; //standby
//Motor A
int PWMA = 3; //Speed control
int AIN1 = 9; //Direction
int AIN2 = 8; //Direction
//Motor B
int PWMB = 5; //Speed control
int BIN1 = 11; //Direction
int BIN2 = 12; //Direction
int infoled = 13;
//char ssid[] = "Chua Family";
//char passphrase[] = "chua2680";
WiFlyServer server(44);
String readString = "";
String dir;
void setup(){
Serial.begin(9600);
pinMode(STBY, OUTPUT);
pinMode(PWMA, OUTPUT);
pinMode(AIN1, OUTPUT);
pinMode(AIN2, OUTPUT);
pinMode(PWMB, OUTPUT);
pinMode(BIN1, OUTPUT);
pinMode(BIN2, OUTPUT);
WiFly.setUart(&Serial);
WiFly.begin(true);
// if (!WiFly.join(ssid, passphrase)) {
if (!WiFly.createAdHocNetwork("wifly")) {
while (1) {
// Hang on failure.
digitalWrite(infoled, HIGH);
delay(300);
digitalWrite(infoled, LOW);
delay(500);
}
}
Serial.println(WiFly.ip());
server.begin();
}
void loop() {
WiFlyClient client = server.available();
if (client) {
digitalWrite(infoled, HIGH);
while (client.connected()) {
if (client.available()) {
char c = client.read();
// if (readString.length() < 100) {
// readString += c;
// }
String d = (String) c;
parseanddo(d);
// client.println("LEEEEEEL: " + d);
}
}
// give the web browser time to receive the data
// delay(200);
readString = "";
client.stop();
digitalWrite(infoled, LOW);
}
}
void parseanddo(String incar) {
if (incar == "w") {
move(1, 255, 0);
move(2, 255, 0);
}
else if (incar == "s") {
move(1, 255, 1);
move(2, 255, 1);
}
else if (incar == "a") {
move(1, 255, 0);
move(2, 0, 0);
}
else if (incar == "d") {
move(1, 0, 0);
move(2, 255, 0);
}
else if (incar == "q") {
move(1, 255, 0);
move(2, 127, 0);
}
else if (incar == "e") {
move(1, 127, 0);
move(2, 255, 0);
}
else {
stop();
}
}
//void blink() {
//
// digitalWrite(infoled, HIGH);
// delay(300);
// digitalWrite(infoled, LOW);
// delay(500);
// digitalWrite(infoled, HIGH);
// delay(300);
// digitalWrite(infoled, LOW);
// delay(500);
// digitalWrite(infoled, HIGH);
// delay(300);
// digitalWrite(infoled, LOW);
// delay(500);
// digitalWrite(infoled, HIGH);
// delay(300);
// digitalWrite(infoled, LOW);
// delay(500);
// digitalWrite(infoled, HIGH);
// delay(300);
// digitalWrite(infoled, LOW);
// delay(500);
//
//}
void move(int motor, int speed, int direction){
//Move specific motor at speed and direction
//motor: 0 for B 1 for A
//speed: 0 is off, and 255 is full speed
//direction: 0 clockwise, 1 counter-clockwise
digitalWrite(STBY, HIGH); //disable standby
boolean inPin1 = LOW;
boolean inPin2 = HIGH;
if(direction == 1){
inPin1 = HIGH;
inPin2 = LOW;
}
if(motor == 1){
digitalWrite(AIN1, inPin1);
digitalWrite(AIN2, inPin2);
analogWrite(PWMA, speed);
}
else{
digitalWrite(BIN1, inPin1);
digitalWrite(BIN2, inPin2);
analogWrite(PWMB, speed);
}
}
void stop(){
//enable standby
digitalWrite(STBY, LOW);
}

Binary file not shown.

View File

@ -0,0 +1,46 @@
<?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>BuildMachineOSBuild</key>
<string>12C3006</string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
<string>node-webkit Helper EH</string>
<key>CFBundleExecutable</key>
<string>node-webkit Helper EH</string>
<key>CFBundleIdentifier</key>
<string>com.intel.nw.helper.EH</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>node-webkit Helper EH</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>32.0.1700.107</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1700.107</string>
<key>DTSDKBuild</key>
<string>11E52</string>
<key>DTSDKName</key>
<string>macosx10.7</string>
<key>DTXcode</key>
<string>0452</string>
<key>DTXcodeBuild</key>
<string>4G2008a</string>
<key>LSFileQuarantineEnabled</key>
<true/>
<key>LSMinimumSystemVersion</key>
<string>10.6.0</string>
<key>LSUIElement</key>
<string>1</string>
<key>NSSupportsAutomaticGraphicsSwitching</key>
<true/>
<key>SCMRevision</key>
<string>239963</string>
</dict>
</plist>

View File

@ -0,0 +1 @@
APPL????

View File

@ -0,0 +1,32 @@
<?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>CFBundleDisplayName</key>
<string>crash_report_sender</string>
<key>CFBundleExecutable</key>
<string>crash_report_sender</string>
<key>CFBundleIconFile</key>
<string>crash_report_sender</string>
<key>CFBundleIdentifier</key>
<string>com.Breakpad.${PRODUCT_NAME:identifier}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>crash_report_sender</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>LSHasLocalizedDisplayName</key>
<true/>
<key>NSMainNibFile</key>
<string>MainMenu</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
</dict>
</plist>

View File

@ -0,0 +1,46 @@
<?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>BuildMachineOSBuild</key>
<string>12C3006</string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
<string>node-webkit Helper NP</string>
<key>CFBundleExecutable</key>
<string>node-webkit Helper NP</string>
<key>CFBundleIdentifier</key>
<string>com.intel.nw.helper.NP</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>node-webkit Helper NP</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>32.0.1700.107</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1700.107</string>
<key>DTSDKBuild</key>
<string>11E52</string>
<key>DTSDKName</key>
<string>macosx10.7</string>
<key>DTXcode</key>
<string>0452</string>
<key>DTXcodeBuild</key>
<string>4G2008a</string>
<key>LSFileQuarantineEnabled</key>
<true/>
<key>LSMinimumSystemVersion</key>
<string>10.6.0</string>
<key>LSUIElement</key>
<string>1</string>
<key>NSSupportsAutomaticGraphicsSwitching</key>
<true/>
<key>SCMRevision</key>
<string>239963</string>
</dict>
</plist>

View File

@ -0,0 +1 @@
APPL????

View File

@ -0,0 +1,32 @@
<?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>CFBundleDisplayName</key>
<string>crash_report_sender</string>
<key>CFBundleExecutable</key>
<string>crash_report_sender</string>
<key>CFBundleIconFile</key>
<string>crash_report_sender</string>
<key>CFBundleIdentifier</key>
<string>com.Breakpad.${PRODUCT_NAME:identifier}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>crash_report_sender</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>LSHasLocalizedDisplayName</key>
<true/>
<key>NSMainNibFile</key>
<string>MainMenu</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
</dict>
</plist>

View File

@ -0,0 +1,46 @@
<?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>BuildMachineOSBuild</key>
<string>12C3006</string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
<string>node-webkit Helper</string>
<key>CFBundleExecutable</key>
<string>node-webkit Helper</string>
<key>CFBundleIdentifier</key>
<string>com.intel.nw.helper</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>node-webkit Helper</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>32.0.1700.107</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1700.107</string>
<key>DTSDKBuild</key>
<string>11E52</string>
<key>DTSDKName</key>
<string>macosx10.7</string>
<key>DTXcode</key>
<string>0452</string>
<key>DTXcodeBuild</key>
<string>4G2008a</string>
<key>LSFileQuarantineEnabled</key>
<true/>
<key>LSMinimumSystemVersion</key>
<string>10.6.0</string>
<key>LSUIElement</key>
<string>1</string>
<key>NSSupportsAutomaticGraphicsSwitching</key>
<true/>
<key>SCMRevision</key>
<string>239963</string>
</dict>
</plist>

View File

@ -0,0 +1 @@
APPL????

View File

@ -0,0 +1,32 @@
<?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>CFBundleDisplayName</key>
<string>crash_report_sender</string>
<key>CFBundleExecutable</key>
<string>crash_report_sender</string>
<key>CFBundleIconFile</key>
<string>crash_report_sender</string>
<key>CFBundleIdentifier</key>
<string>com.Breakpad.${PRODUCT_NAME:identifier}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>crash_report_sender</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>LSHasLocalizedDisplayName</key>
<true/>
<key>NSMainNibFile</key>
<string>MainMenu</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
</dict>
</plist>

View File

@ -0,0 +1,74 @@
<?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>BuildMachineOSBuild</key>
<string>12C3006</string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
<string>node-webkit</string>
<key>CFBundleExecutable</key>
<string>node-webkit</string>
<key>CFBundleIconFile</key>
<string>nw.icns</string>
<key>CFBundleIdentifier</key>
<string>com.intel.nw</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>node-webkit</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>32.0.1700.107</string>
<key>CFBundleVersion</key>
<string>1700.107</string>
<key>DTSDKBuild</key>
<string>11E52</string>
<key>DTSDKName</key>
<string>macosx10.7</string>
<key>DTXcode</key>
<string>0452</string>
<key>DTXcodeBuild</key>
<string>4G2008a</string>
<key>LSFileQuarantineEnabled</key>
<true/>
<key>LSMinimumSystemVersion</key>
<string>10.6.0</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>NSSupportsAutomaticGraphicsSwitching</key>
<true/>
<key>SCMRevision</key>
<string>239963</string>
<key>UTExportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>com.pkware.zip-archive</string>
</array>
<key>UTTypeDescription</key>
<string>node-webkit App</string>
<key>UTTypeIconFile</key>
<string>nw.icns</string>
<key>UTTypeIdentifier</key>
<string>com.intel.nw.app</string>
<key>UTTypeReferenceURL</key>
<string>https://github.com/rogerwang/node-webkit/wiki/How-to-package-and-distribute-your-apps</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>com.apple.ostype</key>
<string>node-webkit</string>
<key>public.filename-extension</key>
<array>
<string>nw</string>
</array>
<key>public.mime-type</key>
<string>application/x-node-webkit-app</string>
</dict>
</dict>
</array>
</dict>
</plist>

Binary file not shown.

View File

@ -0,0 +1 @@
APPL????

View File

@ -0,0 +1,111 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Client</title>
<style>
* {
padding: 0;
margin: 0;
}
body {
background-color: rgb(237, 237, 237);
border-top: 1px solid rgb(105, 105, 105);
text-align: center;
}
.man {
text-align: left;
margin: 0 auto;
width: 520px;
}
</style>
</head>
<body>
<pre class="man">
____ _ _ _
Arduino / ___| (_) ___ _ __ | |_
Bot | | | | |/ _ \ '_ \| __|
| |___| | | __/ | | | |_
\____|_|_|\___|_| |_|\__|
By Ambrose Chua
Powered by NodeJS, node-webkit,
Arduino and WiFly.
Code under WTFPL.
</pre>
<script src="jquery-2.1.0.min.js"></script>
<script>
var keymap = require("./keymap.js");
var gui = require('nw.gui');
gui.Window.get().showDevTools();
var net = require("net");
var socket = new net.Socket();
socket.setEncoding("utf8");
var keymap;
var soc = socket.connect(44, "169.254.1.1", function () {
soc.on("data", function (data) {
console.log(data);
});
console.log("yay");
$(document).ready(function () {
// $.ajax({
// url: 'keymap.json',
// dataType: 'json',
// success: function (response) {
// keymap = response;
// console.log(keymap);
$(window).on("keydown", function (e) {
// TODO: Add speed control.
if (e.which == keymap.KEYCODES["w"]) {
soc.write("w");
}
else if (e.which == keymap.KEYCODES["s"]) {
soc.write("s");
}
else if (e.which == keymap.KEYCODES["a"]) {
soc.write("a");
}
else if (e.which == keymap.KEYCODES["d"]) {
soc.write("d");
}
else if (e.which == keymap.KEYCODES["q"]) {
soc.write("q");
}
else if (e.which == keymap.KEYCODES["e"]) {
soc.write("e");
}
});
$(window).on("keyup", function (e) {
if (e.which == keymap.KEYCODES["w"] || e.which == keymap.KEYCODES["s"] || e.which == keymap.KEYCODES["a"] || e.which == keymap.KEYCODES["d"] || e.which == keymap.KEYCODES["q"] || e.which == keymap.KEYCODES["e"]) {
soc.write("n");
}
// if (e.which == 71) {
// soc.write("n");
// }
// else if (e.which == 72) {
// soc.write("n");
// }
});
// }
// });
});
});
</script>
</body>
</html>

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,147 @@
module.exports = {
/**
* The most common keycodes defined by :
* @type {Object.}
* @const
*/
KEYMAP : {
STRG: 17,
CTRL: 17,
CTRLRIGHT: 18,
CTRLR: 18,
SHIFT: 16,
RETURN: 13,
ENTER: 13,
BACKSPACE: 8,
BCKSP:8,
ALT: 18,
ALTR: 17,
ALTRIGHT: 17,
SPACE: 32,
WIN: 91,
MAC: 91,
FN: null,
UP: 38,
DOWN: 40,
LEFT: 37,
RIGHT: 39,
ESC: 27,
DEL: 46,
F1: 112,
F2: 113,
F3: 114,
F4: 115,
F5: 116,
F6: 117,
F7: 118,
F8: 119,
F9: 120,
F10: 121,
F11: 122,
F12: 123
},
/**
* @type {Object.}
* @const
*/
KEYCODES : {
'backspace' : '8',
'tab' : '9',
'enter' : '13',
'shift' : '16',
'ctrl' : '17',
'alt' : '18',
'pause_break' : '19',
'caps_lock' : '20',
'escape' : '27',
'page_up' : '33',
'page down' : '34',
'end' : '35',
'home' : '36',
'left_arrow' : '37',
'up_arrow' : '38',
'right_arrow' : '39',
'down_arrow' : '40',
'insert' : '45',
'delete' : '46',
'0' : '48',
'1' : '49',
'2' : '50',
'3' : '51',
'4' : '52',
'5' : '53',
'6' : '54',
'7' : '55',
'8' : '56',
'9' : '57',
'a' : '65',
'b' : '66',
'c' : '67',
'd' : '68',
'e' : '69',
'f' : '70',
'g' : '71',
'h' : '72',
'i' : '73',
'j' : '74',
'k' : '75',
'l' : '76',
'm' : '77',
'n' : '78',
'o' : '79',
'p' : '80',
'q' : '81',
'r' : '82',
's' : '83',
't' : '84',
'u' : '85',
'v' : '86',
'w' : '87',
'x' : '88',
'y' : '89',
'z' : '90',
'left_window key' : '91',
'right_window key' : '92',
'select_key' : '93',
'numpad 0' : '96',
'numpad 1' : '97',
'numpad 2' : '98',
'numpad 3' : '99',
'numpad 4' : '100',
'numpad 5' : '101',
'numpad 6' : '102',
'numpad 7' : '103',
'numpad 8' : '104',
'numpad 9' : '105',
'multiply' : '106',
'add' : '107',
'subtract' : '109',
'decimal point' : '110',
'divide' : '111',
'f1' : '112',
'f2' : '113',
'f3' : '114',
'f4' : '115',
'f5' : '116',
'f6' : '117',
'f7' : '118',
'f8' : '119',
'f9' : '120',
'f10' : '121',
'f11' : '122',
'f12' : '123',
'num_lock' : '144',
'scroll_lock' : '145',
'semi_colon' : '186',
'equal_sign' : '187',
'comma' : '188',
'dash' : '189',
'period' : '190',
'forward_slash' : '191',
'grave_accent' : '192',
'open_bracket' : '219',
'backslash' : '220',
'closebracket' : '221',
'single_quote' : '222'
}
}

Some files were not shown because too many files have changed in this diff Show More