From: acevest Date: Thu, 28 May 2015 01:39:49 +0000 (+0800) Subject: ... X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/zpipe.c?a=commitdiff_plain;h=13879015e04ad98f81734b39276e5f8a05cba52e;p=acecode.git ... --- diff --git a/arduino/Sensors/Sensors.ino b/arduino/Sensors/Sensors.ino index 10df6a8..7db9b3f 100644 --- a/arduino/Sensors/Sensors.ino +++ b/arduino/Sensors/Sensors.ino @@ -1,12 +1,25 @@ +#include +SoftwareSerial BTSerial(10, 11); // RX | TX + + int cnt = 0; const int ledPin = 12; void setup() { - Serial.begin(9600); + //Serial.begin(9600); + BTSerial.begin(9600); // HC-06 current bound rate (default 9600) pinMode(ledPin, OUTPUT); pinMode(0, INPUT); pinMode(1, INPUT); pinMode(2, INPUT); + pinMode(3, INPUT); +} + +char* itos(int n) +{ + static char buf[16]; + sprintf(buf, "%d", n); + return buf; } void loop() { @@ -18,21 +31,25 @@ void loop() { int hb = analogRead(2); // Human Body + int hv = analogRead(3); // humidity + if(hb < 100) { hb = 0; } digitalWrite(ledPin, hb > 0 ? HIGH : LOW); - - delay(100); - if(cnt % 10 == 0) + + delay(10); + + if(cnt % 100 == 0) { float temperature; - float resistance = (float)(1023-tv)*10000/tv; + float resistance = (float)(1023.0-tv)*10000.0/tv; temperature = 1.00000/(log(resistance/10000)/3975+1/298.15) - 273.15; + /* Serial.print("Light Sensor Value: "); Serial.println(lv); @@ -41,14 +58,28 @@ void loop() { Serial.print("Body: "); Serial.println(hb); - + */ + /* Serial.print(">"); Serial.print(lv); Serial.print(":"); Serial.print(temperature); Serial.print(":"); Serial.print(hb); - Serial.println(" "); + Serial.print(":"); + Serial.print(hv); + Serial.println(" ");*/ + + BTSerial.write(">"); + BTSerial.write(itos(lv)); + BTSerial.write(":"); + BTSerial.write(itos(temperature)); + BTSerial.write(":"); + BTSerial.write(itos(hb)); + BTSerial.write(":"); + BTSerial.write(itos(hv)); + BTSerial.write("\n"); + } } diff --git a/arduino/bluetoothinit/bluetoothinit.ino b/arduino/bluetoothinit/bluetoothinit.ino new file mode 100644 index 0000000..31d492d --- /dev/null +++ b/arduino/bluetoothinit/bluetoothinit.ino @@ -0,0 +1,17 @@ +#include +SoftwareSerial BTSerial(10, 11); // RX | TX +void setup() +{ + Serial.begin(9600); + Serial.println("Enter AT commands:"); + BTSerial.begin(9600); // HC-06 current bound rate (default 9600) +} +void loop() +{ + // Keep reading from HC-06 and send to Arduino Serial Monitor + if (BTSerial.available()) + Serial.write(BTSerial.read()); + // Keep reading from Arduino Serial Monitor and send to HC-06 + if (Serial.available()) + BTSerial.write(Serial.read()); +} diff --git a/learn/doc/mac b/learn/doc/mac new file mode 100644 index 0000000..78854b3 --- /dev/null +++ b/learn/doc/mac @@ -0,0 +1,13 @@ +iterm2 + +curl -L https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh | sh + +git clone git://github.com/supermarin/powerline-fonts.git +安装 Monaco fo Powerline.otf + +iterm2 设置字体为以上 + + + +git clone git://github.com/jeremyFreeAgent/oh-my-zsh-powerline-theme +cp oh-my-zsh-powerline-theme/powerline.zsh-them ~/.oh-my-zsh/theme/ diff --git a/learn/test/socket.performance/.c.txt.swp b/learn/test/socket.performance/.c.txt.swp new file mode 100644 index 0000000..fb154d8 Binary files /dev/null and b/learn/test/socket.performance/.c.txt.swp differ diff --git a/learn/test/socket.performance/shell.c b/learn/test/socket.performance/shell.c new file mode 100644 index 0000000..2b41fcd --- /dev/null +++ b/learn/test/socket.performance/shell.c @@ -0,0 +1,90 @@ +/* + * ------------------------------------------------------------------------ + * File Name: shell.c + * Author: Zhao Yanbai + * Fri Apr 10 11:14:22 2015 + * Description: none + * ------------------------------------------------------------------------ + */ +#include +#include +#include +#include +#include +#include +#include + + +#define PORT 6666 + +void do_child(int fd) +{ + printf("new connection: %d\n", fd); + + close(STDIN_FILENO); + dup(fd); + + close(STDOUT_FILENO); + dup(fd); + + close(STDERR_FILENO); + dup(fd); + + + execvp("/bin/bash", 0); +} + +int main() +{ + int sock; + struct sockaddr_in serv; + + sock = socket(AF_INET, SOCK_STREAM, 0); + if(sock == -1) + { + perror("socket failed"); + exit(1); + } + + + int flags; + setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &flags, sizeof(flags)); + + + serv.sin_family = AF_INET; + serv.sin_addr.s_addr = htonl(INADDR_ANY); + serv.sin_port = htons(PORT); + if(bind(sock, (struct sockaddr*)&serv, sizeof(serv)) == -1) + { + perror("bind failed"); + exit(1); + } + + + if(listen(sock, SOMAXCONN) == -1) + { + perror("listen failed"); + exit(1); + } + + + while(1) + { + int nfd; + struct sockaddr_in client; + socklen_t len = sizeof(client); + nfd = accept(sock, (struct sockaddr *)&client, &len); + + pid_t pid = fork(); + + if(pid ==0) + { + do_child(nfd); + exit(0); + } + } + + close(sock); + + return 0; +} diff --git a/tools/AceBox/.DS_Store b/tools/AceBox/.DS_Store index e25c09b..6ff7f15 100644 Binary files a/tools/AceBox/.DS_Store and b/tools/AceBox/.DS_Store differ diff --git a/tools/AceBox/AceBox.xcodeproj/project.xcworkspace/xcshareddata/AceBox.xccheckout b/tools/AceBox/AceBox.xcodeproj/project.xcworkspace/xcshareddata/AceBox.xccheckout index 97be529..7a2852c 100644 --- a/tools/AceBox/AceBox.xcodeproj/project.xcworkspace/xcshareddata/AceBox.xccheckout +++ b/tools/AceBox/AceBox.xcodeproj/project.xcworkspace/xcshareddata/AceBox.xccheckout @@ -7,21 +7,21 @@ IDESourceControlProjectIdentifier A1372EDB-125D-4A73-9AE8-955FA3D42EAE IDESourceControlProjectName - project + AceBox IDESourceControlProjectOriginsDictionary BA634633803B1A00DDD2BCDEF5C645E5844F56E6 - https://github.com/acevest/acecode.git + https://github.com/acevest/acecode IDESourceControlProjectPath - tools/AceBox/AceBox.xcodeproj/project.xcworkspace + tools/AceBox/AceBox.xcodeproj IDESourceControlProjectRelativeInstallPathDictionary BA634633803B1A00DDD2BCDEF5C645E5844F56E6 ../../../.. IDESourceControlProjectURL - https://github.com/acevest/acecode.git + https://github.com/acevest/acecode IDESourceControlProjectVersion 111 IDESourceControlProjectWCCIdentifier diff --git a/tools/AceBox/AceBox.xcodeproj/project.xcworkspace/xcuserdata/Ace.xcuserdatad/UserInterfaceState.xcuserstate b/tools/AceBox/AceBox.xcodeproj/project.xcworkspace/xcuserdata/Ace.xcuserdatad/UserInterfaceState.xcuserstate index fe87912..286c512 100644 Binary files a/tools/AceBox/AceBox.xcodeproj/project.xcworkspace/xcuserdata/Ace.xcuserdatad/UserInterfaceState.xcuserstate and b/tools/AceBox/AceBox.xcodeproj/project.xcworkspace/xcuserdata/Ace.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/tools/AceBox/AceBox/Base.lproj/Main.storyboard b/tools/AceBox/AceBox/Base.lproj/Main.storyboard index 64f32e1..8f5b4fa 100644 --- a/tools/AceBox/AceBox/Base.lproj/Main.storyboard +++ b/tools/AceBox/AceBox/Base.lproj/Main.storyboard @@ -1,7 +1,7 @@ - + - + @@ -20,18 +20,15 @@ - + - - - @@ -63,13 +60,13 @@ - + @@ -91,7 +88,7 @@ - + @@ -100,32 +97,12 @@ - - - - - - - - - - - - - - - - - - - -