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

wrong values #1

Open
wants to merge 16 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
4 changes: 2 additions & 2 deletions .classpath
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>
39 changes: 24 additions & 15 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,27 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.jwetherell.heart_rate_monitor"
android:versionCode="1"
android:versionName="1.0">
package="com.vanderbie.heart_rate_monitor"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="7"/>
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="7" />

<uses-feature android:name="android.hardware.camera"/>
<uses-feature android:name="android.hardware.camera.flash"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.flash" />

<application android:icon="@drawable/icon"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
<activity android:name=".HeartRateMonitor"
android:configChanges="keyboardHidden|orientation"
android:screenOrientation="landscape">
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
<activity
android:name="com.vanderbie.heart_rate_monitor.HeartRateMonitor"
android:configChanges="keyboardHidden|orientation"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
</manifest>
94 changes: 94 additions & 0 deletions Processing/HeartRate_udp/HeartRate_udp.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/**
* (./) udp.pde - how to use UDP library as unicast connection
* (cc) 2006, Cousot stephane for The Atelier Hypermedia
* (->) http://hypermedia.loeil.org/processing/
http://ubaa.net/shared/processing/udp/
*
* Extended by Joey van der Bie to display heart rate value send by Android phone
* https://github.com/joeyvanderbie/android-heart-rate-monitor
*/

// import UDP library
import hypermedia.net.*;


UDP udp; // define the UDP object
int listenport = 6000;// this should be the same as the port in the Android app

int textSize = 180;
/**
* init
*/
void setup() {
size(600,600);
// create a new datagram connection on port 6000
// and wait for incomming message
udp = new UDP( this, listenport );
//udp.log( true ); // <-- printout the connection activity
udp.listen( true );


//Draw blank text
textSize(textSize);
background(255,0,0);
fill(255);
text("--", (width-textSize)/2, (height+textSize)/2);
}

//process events
void draw() {;
}

void displayHeartRate(int heart_rate){
//display heart rate
background(255,0,0);
fill(255);
text(""+heart_rate, (width-textSize)/2, (height+textSize)/2);
}

/**
* To perform any action on datagram reception, you need to implement this
* handler in your code. This method will be automatically called by the UDP
* object each time he receive a nonnull message.
* By default, this method have just one argument (the received message as
* byte[] array), but in addition, two arguments (representing in order the
* sender IP address and his port) can be set like below.
*/
// void receive( byte[] data ) { // <-- default handler
void receive( byte[] data, String ip, int port ) { // <-- extended handler


// get the "real" message =
// forget the ";\n" at the end <-- !!! only for a communication with Pd !!!
data = subset(data, 0, data.length-2);
String message = new String( data );

// print the result
println( "receive: \""+message+"\" from "+ip+" on port "+port );


String heartrate[] = split(message, ",");
displayHeartRate(int(heartrate[0]));

}

/**
* on key pressed event:
* send the current key value over the network
*/
void keyPressed() {

String message = str( key ); // the message to send
String ip = "localhost"; // the remote IP address
int port = 6100; // the destination port

// formats the message for Pd
message = message+";\n";
// send the message
udp.send( message, ip, port );
}





30 changes: 30 additions & 0 deletions Processing/HeartRate_udp/udp.pd
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#N canvas 103 333 764 337 10;
#X obj 36 28 cnv 15 690 190 empty empty empty 20 12 0 12 -237178 -212212
0;
#X obj 36 221 cnv 15 690 70 empty empty empty 20 12 0 14 -146177 -66577
0;
#X obj 45 256 print receive;
#X text 177 233 <-- Opens a socket for UDP network reception on port
6100 and prints the received message.;
#X obj 47 116 netsend 1;
#X msg 47 94 disconnect;
#X floatatom 47 164 5 0 0 0 - - -;
#X text 95 164 <-- Reports whether the connection is open or not (0=close
\, nonzero otherwise).;
#X obj 242 70 cnv 15 480 60 empty empty empty 20 12 0 14 -259904 -66577
0;
#X msg 249 100 send \$1;
#X floatatom 249 82 5 0 0 0 - - -;
#X obj 45 234 netreceive 6100 1;
#X msg 47 72 connect localhost 6000;
#X text 314 81 [2] Send the current number to the remote machine (change
the value by dragging the number box or type directly the new value).
;
#X text 47 40 [1] Connect to 'localhost' on port 6000 for sending UDP
messages.;
#X connect 4 0 6 0;
#X connect 5 0 4 0;
#X connect 9 0 4 0;
#X connect 10 0 9 0;
#X connect 11 0 2 0;
#X connect 12 0 4 0;
30 changes: 30 additions & 0 deletions Processing/udp/examples/udp/udp.pd
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#N canvas 103 333 764 337 10;
#X obj 36 28 cnv 15 690 190 empty empty empty 20 12 0 12 -237178 -212212
0;
#X obj 36 221 cnv 15 690 70 empty empty empty 20 12 0 14 -146177 -66577
0;
#X obj 45 256 print receive;
#X text 177 233 <-- Opens a socket for UDP network reception on port
6100 and prints the received message.;
#X obj 47 116 netsend 1;
#X msg 47 94 disconnect;
#X floatatom 47 164 5 0 0 0 - - -;
#X text 95 164 <-- Reports whether the connection is open or not (0=close
\, nonzero otherwise).;
#X obj 242 70 cnv 15 480 60 empty empty empty 20 12 0 14 -259904 -66577
0;
#X msg 249 100 send \$1;
#X floatatom 249 82 5 0 0 0 - - -;
#X obj 45 234 netreceive 6100 1;
#X msg 47 72 connect localhost 6000;
#X text 314 81 [2] Send the current number to the remote machine (change
the value by dragging the number box or type directly the new value).
;
#X text 47 40 [1] Connect to 'localhost' on port 6000 for sending UDP
messages.;
#X connect 4 0 6 0;
#X connect 5 0 4 0;
#X connect 9 0 4 0;
#X connect 10 0 9 0;
#X connect 11 0 2 0;
#X connect 12 0 4 0;
73 changes: 73 additions & 0 deletions Processing/udp/examples/udp/udp.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/**
* (./) udp.pde - how to use UDP library as unicast connection
* (cc) 2006, Cousot stephane for The Atelier Hypermedia
* (->) http://hypermedia.loeil.org/processing/
*
* Create a communication between Processing<->Pure Data @ http://puredata.info/
* This program also requires to run a small program on Pd to exchange data
* (hum!!! for a complete experimentation), you can find the related Pd patch
* at http://hypermedia.loeil.org/processing/udp.pd
*
* -- note that all Pd input/output messages are completed with the characters
* ";\n". Don't refer to this notation for a normal use. --
*/

// import UDP library
import hypermedia.net.*;


UDP udp; // define the UDP object
int listenport = 6000;// this should be the same as the port in the Android app
/**
* init
*/
void setup() {

// create a new datagram connection on port 6000
// and wait for incomming message
udp = new UDP( this, listenport );
//udp.log( true ); // <-- printout the connection activity
udp.listen( true );
}

//process events
void draw() {;}

/**
* on key pressed event:
* send the current key value over the network
*/
void keyPressed() {

String message = str( key ); // the message to send
String ip = "localhost"; // the remote IP address
int port = 6100; // the destination port

// formats the message for Pd
message = message+";\n";
// send the message
udp.send( message, ip, port );

}

/**
* To perform any action on datagram reception, you need to implement this
* handler in your code. This method will be automatically called by the UDP
* object each time he receive a nonnull message.
* By default, this method have just one argument (the received message as
* byte[] array), but in addition, two arguments (representing in order the
* sender IP address and his port) can be set like below.
*/
// void receive( byte[] data ) { // <-- default handler
void receive( byte[] data, String ip, int port ) { // <-- extended handler


// get the "real" message =
// forget the ";\n" at the end <-- !!! only for a communication with Pd !!!
data = subset(data, 0, data.length-2);
String message = new String( data );

// print the result
println( "receive: \""+message+"\" from "+ip+" on port "+port );
}

100 changes: 100 additions & 0 deletions Processing/udp/examples/udp_multicast/udp_multicast.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/**
* (./) udp_multicast.pde - how to use UDP library as multicast connection
* (cc) 2006, Cousot stephane for The Atelier Hypermedia
* (->) http://hypermedia.loeil.org/processing/
*
* Pass the mouse coordinates over the network to draw an "multi-user picture".
*
* --
*
* about multicasting:
* The only difference between unicast/broadcast and multicast address is that
* all interfaces identified by that address receive the same data. Multicasting
* provide additional options in the UDP object (see the documentation for
* more informations), but the usage is commonly the same: simply add the
* multicast group address in his initialization to reflect a multicast
* connection.
*
* (note: currently applets are not allowed to use multicast sockets)
*/

// import UDP library
import hypermedia.net.*;


UDP udp; // the UDP object


/**
* init the frame and the UDP object.
*/
void setup() {

// to simplify the program, we use a byte[] array to pass the previous and
// the current mouse coordinates. The PApplet size must be defined with
// values <=255
size( 255, 255 );
background( 0 );

// create a multicast connection on port 6000
// and join the group at the address "224.0.0.1"
udp = new UDP( this, 6000, "224.0.0.1" );
// wait constantly for incomming data
udp.listen( true );
// ... well, just verifies if it's really a multicast socket and blablabla
println( "init as multicast socket ... "+udp.isMulticast() );
println( "joins a multicast group ... "+udp.isJoined() );

}

// process events
void draw() {
}


/**
* on mouse move :
* send the mouse positions over the network
*/
void mouseMoved() {

byte[] data = new byte[4]; // the data to be send

// add the mouse positions
data[0] = byte(mouseX);
data[1] = byte(mouseY);
data[2] = byte(pmouseX);
data[3] = byte(pmouseY);

// by default if the ip address and the port number are not specified, UDP
// send the message to the joined group address and the current socket port.
udp.send( data ); // = send( data, group_ip, port );

// note: by creating a multicast program, you can also send a message to a
// specific address (i.e. send( "the messsage", "192.168.0.2", 7010 ); )
}

/**
* This is the program receive handler. To perform any action on datagram
* reception, you need to implement this method in your code. She will be
* automatically called by the UDP object each time he receive a nonnull
* message.
*/
void receive( byte[] data ) {

// retrieve the mouse coordonates
int x = int( data[0] );
int y = int( data[1] );
int px = int( data[2] );
int py = int( data[3] );

// slowly, clears the previous lines
noStroke();
fill( 0, 0, 0, 7 );
rect( 0, 0, width, height);

// and draw a single line with the given mouse positions
stroke( 255 );
line( x, y, px, py );

}
Loading