Skip to content
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
2 changes: 2 additions & 0 deletions WebContent/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
<li>finch/in/accelerationX</li>
<li>finch/in/accelerationY</li>
<li>finch/in/accelerationZ</li>
<li>finch/in/lastTappedTime</li>
<li>finch/in/lastShakenTime</li>
<li>finch/in/temperature</li>
<li>finch/in/motor (provides current value of motor speeds)</li>
<li>finch/in/led (provides current RGB color intensities of LED)</li>
Expand Down
8 changes: 8 additions & 0 deletions src/birdbrain/finchandHummingbirdServer/FinchServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public void setConnectionState(boolean state) {
* in/accelerationY
* in/accelerationZ
* in/temperature
* in/lastTappedTime
* in/lastShakenTime
*
*/

Expand Down Expand Up @@ -217,6 +219,12 @@ else if(urlPath.substring(4).equals("temperature")) {
response.getWriter().print(Math.floor(finch.getTemperature()*100)/100);

}
else if(urlPath.substring(4).equals("lastTappedTime")) {
response.getWriter().print(finch.getLastTappedTime());
}
else if(urlPath.substring(4).equals("lastShakenTime")) {
response.getWriter().print(finch.getLastShakenTime());
}
// If the Finch is active and you wrote "in" but the remainder is garbage, send an error message
else {
response.getWriter().print("Wrong sensor request");
Expand Down
21 changes: 19 additions & 2 deletions src/birdbrain/finchandHummingbirdServer/FinchServletWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public class FinchServletWrapper {
private Double temperature;
private boolean[] obstacles;
private int[] lights;
// The time when the last tapped and shaken events were recorded
private long lastTappedTime = 0;
private long lastShakenTime = 0;

// We poll sensors in a separate thread to minimize the timer doGet has to wait
private Thread sensorLoop;
Expand All @@ -29,6 +32,12 @@ public void run() {
{
try {
// Each finch.get takes 8 ms, then sleep to allow other things to happen
if (finch.isTapped())
lastTappedTime = System.currentTimeMillis();
Thread.sleep(12);
if (finch.isShaken())
lastShakenTime = System.currentTimeMillis();
Thread.sleep(12);
accelerations = finch.getAccelerations();
Thread.sleep(12);
temperature = finch.getTemperature();
Expand Down Expand Up @@ -144,8 +153,16 @@ public boolean[] getObstacle() {

}



public long getLastTappedTime() {
return lastTappedTime;
}

public long getLastShakenTime() {
return lastShakenTime;
}



// Parses the Finch output string and sets it
public boolean setOutput(String setter)
{
Expand Down