Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added in my files

  • Loading branch information...
commit a4d1b09cce181c035541f2ff8b914c84c7aa73ea 1 parent d74f3d6
@sharadmv authored
Showing with 896 additions and 0 deletions.
  1. +11 −0 android/.classpath
  2. +33 −0 android/.project
  3. +27 −0 android/AndroidManifest.xml
  4. +27 −0 android/bin/AndroidManifest.xml
  5. BIN  android/bin/Electrify.apk
  6. BIN  android/bin/classes.dex
  7. BIN  android/bin/classes/com/sharad/electrify/BuildConfig.class
  8. BIN  android/bin/classes/com/sharad/electrify/ElectrifyActivity$1.class
  9. BIN  android/bin/classes/com/sharad/electrify/ElectrifyActivity$2.class
  10. BIN  android/bin/classes/com/sharad/electrify/ElectrifyActivity$3.class
  11. BIN  android/bin/classes/com/sharad/electrify/ElectrifyActivity$4.class
  12. BIN  android/bin/classes/com/sharad/electrify/ElectrifyActivity$5.class
  13. BIN  android/bin/classes/com/sharad/electrify/ElectrifyActivity$6.class
  14. BIN  android/bin/classes/com/sharad/electrify/ElectrifyActivity$7.class
  15. BIN  android/bin/classes/com/sharad/electrify/ElectrifyActivity$Electrify.class
  16. BIN  android/bin/classes/com/sharad/electrify/ElectrifyActivity.class
  17. BIN  android/bin/classes/com/sharad/electrify/R$attr.class
  18. BIN  android/bin/classes/com/sharad/electrify/R$dimen.class
  19. BIN  android/bin/classes/com/sharad/electrify/R$drawable.class
  20. BIN  android/bin/classes/com/sharad/electrify/R$id.class
  21. BIN  android/bin/classes/com/sharad/electrify/R$layout.class
  22. BIN  android/bin/classes/com/sharad/electrify/R$menu.class
  23. BIN  android/bin/classes/com/sharad/electrify/R$string.class
  24. BIN  android/bin/classes/com/sharad/electrify/R$style.class
  25. BIN  android/bin/classes/com/sharad/electrify/R.class
  26. BIN  android/bin/res/drawable-hdpi/ic_action_search.png
  27. BIN  android/bin/res/drawable-hdpi/ic_launcher.png
  28. BIN  android/bin/res/drawable-ldpi/ic_launcher.png
  29. BIN  android/bin/res/drawable-mdpi/ic_action_search.png
  30. BIN  android/bin/res/drawable-mdpi/ic_launcher.png
  31. BIN  android/bin/res/drawable-xhdpi/ic_action_search.png
  32. BIN  android/bin/res/drawable-xhdpi/ic_launcher.png
  33. BIN  android/bin/resources.ap_
  34. +6 −0 android/gen/com/sharad/electrify/BuildConfig.java
  35. +44 −0 android/gen/com/sharad/electrify/R.java
  36. BIN  android/ic_launcher-web.png
  37. BIN  android/libs/android-support-v4.jar
  38. BIN  android/libs/bridge-java-core-0.0.1.jar
  39. BIN  android/libs/jackson-all-1.9.2.jar
  40. BIN  android/libs/slf4j-api-1.6.4.jar
  41. +4 −0 android/lint.xml
  42. +20 −0 android/proguard-project.txt
  43. +14 −0 android/project.properties
  44. BIN  android/res/drawable-hdpi/ic_action_search.png
  45. BIN  android/res/drawable-hdpi/ic_launcher.png
  46. BIN  android/res/drawable-ldpi/ic_launcher.png
  47. BIN  android/res/drawable-mdpi/ic_action_search.png
  48. BIN  android/res/drawable-mdpi/ic_launcher.png
  49. BIN  android/res/drawable-xhdpi/ic_action_search.png
  50. BIN  android/res/drawable-xhdpi/ic_launcher.png
  51. +29 −0 android/res/layout/activity_electrify.xml
  52. +6 −0 android/res/menu/activity_electrify.xml
  53. +7 −0 android/res/values-large/dimens.xml
  54. +5 −0 android/res/values-v11/styles.xml
  55. +5 −0 android/res/values-v14/styles.xml
  56. +7 −0 android/res/values/dimens.xml
  57. +8 −0 android/res/values/strings.xml
  58. +5 −0 android/res/values/styles.xml
  59. +182 −0 android/src/com/sharad/electrify/ElectrifyActivity.java
  60. +16 −0 arduino/hub/hub.ino
  61. +136 −0 arduino/powerstrip/powerstrip.ino
  62. +109 −0 js/electrify.js
  63. +49 −0 js/filter.js
  64. BIN  js/levels.mp3
  65. +62 −0 js/main.js
  66. +8 −0 js/mp3.js
  67. +30 −0 js/router.js
  68. +46 −0 js/sound.js
  69. BIN  js/temp
View
11 android/.classpath
@@ -0,0 +1,11 @@
+<?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 kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
+ <classpathentry kind="lib" path="libs/jackson-all-1.9.2.jar"/>
+ <classpathentry kind="lib" path="libs/slf4j-api-1.6.4.jar"/>
+ <classpathentry kind="lib" path="libs/bridge-java-core-0.0.1.jar"/>
+ <classpathentry kind="output" path="bin/classes"/>
+</classpath>
View
33 android/.project
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>Electrify</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.ApkBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>com.android.ide.eclipse.adt.AndroidNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
View
27 android/AndroidManifest.xml
@@ -0,0 +1,27 @@
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.sharad.electrify"
+ android:versionCode="1"
+ android:versionName="1.0" >
+
+ <uses-sdk
+ android:minSdkVersion="8"
+ android:targetSdkVersion="15" />
+
+ <uses-permission android:name="android.permission.INTERNET" />
+
+ <application
+ android:icon="@drawable/ic_launcher"
+ android:label="@string/app_name"
+ android:theme="@style/AppTheme" >
+ <activity
+ android:name=".ElectrifyActivity"
+ android:label="@string/title_activity_electrify" >
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+ </application>
+
+</manifest>
View
27 android/bin/AndroidManifest.xml
@@ -0,0 +1,27 @@
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.sharad.electrify"
+ android:versionCode="1"
+ android:versionName="1.0" >
+
+ <uses-sdk
+ android:minSdkVersion="8"
+ android:targetSdkVersion="15" />
+
+ <uses-permission android:name="android.permission.INTERNET" />
+
+ <application
+ android:icon="@drawable/ic_launcher"
+ android:label="@string/app_name"
+ android:theme="@style/AppTheme" >
+ <activity
+ android:name=".ElectrifyActivity"
+ android:label="@string/title_activity_electrify" >
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+ </application>
+
+</manifest>
View
BIN  android/bin/Electrify.apk
Binary file not shown
View
BIN  android/bin/classes.dex
Binary file not shown
View
BIN  android/bin/classes/com/sharad/electrify/BuildConfig.class
Binary file not shown
View
BIN  android/bin/classes/com/sharad/electrify/ElectrifyActivity$1.class
Binary file not shown
View
BIN  android/bin/classes/com/sharad/electrify/ElectrifyActivity$2.class
Binary file not shown
View
BIN  android/bin/classes/com/sharad/electrify/ElectrifyActivity$3.class
Binary file not shown
View
BIN  android/bin/classes/com/sharad/electrify/ElectrifyActivity$4.class
Binary file not shown
View
BIN  android/bin/classes/com/sharad/electrify/ElectrifyActivity$5.class
Binary file not shown
View
BIN  android/bin/classes/com/sharad/electrify/ElectrifyActivity$6.class
Binary file not shown
View
BIN  android/bin/classes/com/sharad/electrify/ElectrifyActivity$7.class
Binary file not shown
View
BIN  android/bin/classes/com/sharad/electrify/ElectrifyActivity$Electrify.class
Binary file not shown
View
BIN  android/bin/classes/com/sharad/electrify/ElectrifyActivity.class
Binary file not shown
View
BIN  android/bin/classes/com/sharad/electrify/R$attr.class
Binary file not shown
View
BIN  android/bin/classes/com/sharad/electrify/R$dimen.class
Binary file not shown
View
BIN  android/bin/classes/com/sharad/electrify/R$drawable.class
Binary file not shown
View
BIN  android/bin/classes/com/sharad/electrify/R$id.class
Binary file not shown
View
BIN  android/bin/classes/com/sharad/electrify/R$layout.class
Binary file not shown
View
BIN  android/bin/classes/com/sharad/electrify/R$menu.class
Binary file not shown
View
BIN  android/bin/classes/com/sharad/electrify/R$string.class
Binary file not shown
View
BIN  android/bin/classes/com/sharad/electrify/R$style.class
Binary file not shown
View
BIN  android/bin/classes/com/sharad/electrify/R.class
Binary file not shown
View
BIN  android/bin/res/drawable-hdpi/ic_action_search.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  android/bin/res/drawable-hdpi/ic_launcher.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  android/bin/res/drawable-ldpi/ic_launcher.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  android/bin/res/drawable-mdpi/ic_action_search.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  android/bin/res/drawable-mdpi/ic_launcher.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  android/bin/res/drawable-xhdpi/ic_action_search.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  android/bin/res/drawable-xhdpi/ic_launcher.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  android/bin/resources.ap_
Binary file not shown
View
6 android/gen/com/sharad/electrify/BuildConfig.java
@@ -0,0 +1,6 @@
+/** Automatically generated file. DO NOT MODIFY */
+package com.sharad.electrify;
+
+public final class BuildConfig {
+ public final static boolean DEBUG = true;
+}
View
44 android/gen/com/sharad/electrify/R.java
@@ -0,0 +1,44 @@
+/* AUTO-GENERATED FILE. DO NOT MODIFY.
+ *
+ * This class was automatically generated by the
+ * aapt tool from the resource data it found. It
+ * should not be modified by hand.
+ */
+
+package com.sharad.electrify;
+
+public final class R {
+ public static final class attr {
+ }
+ public static final class dimen {
+ public static final int padding_large=0x7f040002;
+ public static final int padding_medium=0x7f040001;
+ public static final int padding_small=0x7f040000;
+ }
+ public static final class drawable {
+ public static final int ic_action_search=0x7f020000;
+ public static final int ic_launcher=0x7f020001;
+ }
+ public static final class id {
+ public static final int button=0x7f080000;
+ public static final int button2=0x7f080001;
+ public static final int button3=0x7f080002;
+ public static final int menu_settings=0x7f080004;
+ public static final int speech=0x7f080003;
+ }
+ public static final class layout {
+ public static final int activity_electrify=0x7f030000;
+ }
+ public static final class menu {
+ public static final int activity_electrify=0x7f070000;
+ }
+ public static final class string {
+ public static final int app_name=0x7f050000;
+ public static final int hello_world=0x7f050001;
+ public static final int menu_settings=0x7f050002;
+ public static final int title_activity_electrify=0x7f050003;
+ }
+ public static final class style {
+ public static final int AppTheme=0x7f060000;
+ }
+}
View
BIN  android/ic_launcher-web.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  android/libs/android-support-v4.jar
Binary file not shown
View
BIN  android/libs/bridge-java-core-0.0.1.jar
Binary file not shown
View
BIN  android/libs/jackson-all-1.9.2.jar
Binary file not shown
View
BIN  android/libs/slf4j-api-1.6.4.jar
Binary file not shown
View
4 android/lint.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<lint>
+ <issue id="NewApi" severity="ignore" />
+</lint>
View
20 android/proguard-project.txt
@@ -0,0 +1,20 @@
+# To enable ProGuard in your project, edit project.properties
+# to define the proguard.config property as described in that file.
+#
+# Add project specific ProGuard rules here.
+# By default, the flags in this file are appended to flags specified
+# in ${sdk.dir}/tools/proguard/proguard-android.txt
+# You can edit the include path and order by changing the ProGuard
+# include property in project.properties.
+#
+# For more details, see
+# http://developer.android.com/guide/developing/tools/proguard.html
+
+# Add any project specific keep options here:
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+# public *;
+#}
View
14 android/project.properties
@@ -0,0 +1,14 @@
+# This file is automatically generated by Android Tools.
+# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
+#
+# This file must be checked in Version Control Systems.
+#
+# To customize properties used by the Ant build system edit
+# "ant.properties", and override values to adapt the script to your
+# project structure.
+#
+# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
+#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
+
+# Project target.
+target=android-15
View
BIN  android/res/drawable-hdpi/ic_action_search.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  android/res/drawable-hdpi/ic_launcher.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  android/res/drawable-ldpi/ic_launcher.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  android/res/drawable-mdpi/ic_action_search.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  android/res/drawable-mdpi/ic_launcher.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  android/res/drawable-xhdpi/ic_action_search.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  android/res/drawable-xhdpi/ic_launcher.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
29 android/res/layout/activity_electrify.xml
@@ -0,0 +1,29 @@
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent" >
+
+ <Button
+ android:id="@+id/button"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="Toggle 1" />
+
+ <Button
+ android:id="@+id/button2"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="Toggle 2" />
+ <Button
+ android:id="@+id/button3"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="Toggle 3" />
+
+ <Button
+ android:id="@+id/speech"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="Speech" />
+
+</LinearLayout>
View
6 android/res/menu/activity_electrify.xml
@@ -0,0 +1,6 @@
+<menu xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:id="@+id/menu_settings"
+ android:title="@string/menu_settings"
+ android:orderInCategory="100"
+ android:showAsAction="never" />
+</menu>
View
7 android/res/values-large/dimens.xml
@@ -0,0 +1,7 @@
+<resources>
+
+ <dimen name="padding_small">8dp</dimen>
+ <dimen name="padding_medium">16dp</dimen>
+ <dimen name="padding_large">16dp</dimen>
+
+</resources>
View
5 android/res/values-v11/styles.xml
@@ -0,0 +1,5 @@
+<resources>
+
+ <style name="AppTheme" parent="android:Theme.Holo.Light" />
+
+</resources>
View
5 android/res/values-v14/styles.xml
@@ -0,0 +1,5 @@
+<resources>
+
+ <style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar" />
+
+</resources>
View
7 android/res/values/dimens.xml
@@ -0,0 +1,7 @@
+<resources>
+
+ <dimen name="padding_small">8dp</dimen>
+ <dimen name="padding_medium">8dp</dimen>
+ <dimen name="padding_large">16dp</dimen>
+
+</resources>
View
8 android/res/values/strings.xml
@@ -0,0 +1,8 @@
+<resources>
+
+ <string name="app_name">Electrify</string>
+ <string name="hello_world">Hello world!</string>
+ <string name="menu_settings">Settings</string>
+ <string name="title_activity_electrify">Electrify</string>
+
+</resources>
View
5 android/res/values/styles.xml
@@ -0,0 +1,5 @@
+<resources>
+
+ <style name="AppTheme" parent="android:Theme.Light" />
+
+</resources>
View
182 android/src/com/sharad/electrify/ElectrifyActivity.java
@@ -0,0 +1,182 @@
+package com.sharad.electrify;
+
+import java.io.IOException;
+import java.util.ArrayList;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.os.StrictMode;
+import android.speech.RecognizerIntent;
+import android.speech.tts.TextToSpeech;
+import android.util.Log;
+import android.view.Menu;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.Button;
+import android.widget.Toast;
+
+import com.flotype.bridge.Bridge;
+import com.flotype.bridge.BridgeRemoteObject;
+
+public class ElectrifyActivity extends Activity {
+
+ private TextToSpeech tts;
+ public static int SPEECH_REQUEST_CODE = 1;
+
+ interface Electrify extends BridgeRemoteObject {
+ public void toggle(String id);
+
+ public void on(String id);
+
+ public void off(String id);
+
+ public boolean state(String id);
+ }
+
+ Electrify electrify;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ if (android.os.Build.VERSION.SDK_INT > 9) {
+ StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
+ .permitAll().build();
+ StrictMode.setThreadPolicy(policy);
+ }
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_electrify);
+
+ Bridge bridge = new Bridge().setApiKey("245b536642b8bbe7");
+
+ Button button = (Button) findViewById(R.id.button);
+ button.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View arg0) {
+ toggle("1");
+ }
+ });
+ Button button2 = (Button) findViewById(R.id.button2);
+ button2.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View arg0) {
+ toggle("2");
+ }
+ });
+ Button button3 = (Button) findViewById(R.id.button3);
+ button3.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View arg0) {
+ toggle("3");
+ }
+ });
+ Button speech = (Button) findViewById(R.id.speech);
+ speech.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View arg0) {
+ sendRecognizeIntent();
+ }
+ });
+ try {
+ bridge.connect();
+ electrify = bridge.getService("electrify", Electrify.class);
+ } catch (IOException e) {
+ }
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ getMenuInflater().inflate(R.menu.activity_electrify, menu);
+ return true;
+ }
+
+ private void sendRecognizeIntent() {
+ Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
+ intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
+ RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
+ intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Say the magic word");
+ intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 100);
+ startActivityForResult(intent, SPEECH_REQUEST_CODE);
+ }
+
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ if (requestCode == SPEECH_REQUEST_CODE) {
+ if (resultCode == RESULT_OK) {
+ ArrayList<String> matches = data
+ .getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
+
+ if (matches.size() == 0) {
+ tts.speak("Heard nothing", TextToSpeech.QUEUE_FLUSH, null);
+ } else {
+ String mostLikelyThingHeard = matches.get(0);
+ Toast.makeText(this, mostLikelyThingHeard,
+ Toast.LENGTH_LONG).show();
+ Log.d("tts", mostLikelyThingHeard);
+ String[] chunks = mostLikelyThingHeard.split(" ");
+ if (chunks.length > 3)
+ if (chunks[0].equals("turn")) {
+ if (chunks[1].equals("off")) {
+ String id = chunks[chunks.length - 1];
+ if (id.equals("to") || id.equals("too")) {
+ id = "2";
+ }
+ off(id);
+ }
+ if (chunks[1].equals("on")) {
+ String id = chunks[chunks.length - 1];
+ if (id.equals("to") || id.equals("too")) {
+ id = "2";
+ }
+ on(id);
+ }
+ } else if (chunks[0].equals("toggle")
+ || chunks[0].equals("hogle")) {
+ String id = chunks[chunks.length - 1];
+ if (id.equals("to") || id.equals("too")) {
+ id = "2";
+ }
+ Log.d("tts", id + "");
+ toggle(id);
+ }
+ }
+ } else {
+ Log.d("tts", "result NOT ok");
+ }
+ }
+
+ super.onActivityResult(requestCode, resultCode, data);
+ }
+
+ public void toggle(final String id) {
+ Runnable r = new Runnable() {
+ @Override
+ public void run() {
+ electrify.toggle(id);
+ }
+ };
+ (new Thread(r)).start();
+
+ }
+
+ public void on(final String id) {
+ Runnable r = new Runnable() {
+ @Override
+ public void run() {
+ electrify.on(id);
+ }
+ };
+ (new Thread(r)).start();
+
+ }
+
+ public void off(final String id) {
+ Runnable r = new Runnable() {
+ @Override
+ public void run() {
+ electrify.off(id);
+ }
+ };
+ (new Thread(r)).start();
+
+ }
+}
View
16 arduino/hub/hub.ino
@@ -0,0 +1,16 @@
+#include <SoftwareSerial.h>
+SoftwareSerial mySerial(2, 3); // RX, TX
+
+void setup() {
+ Serial.begin(9600);
+ mySerial.begin(9600);
+}
+
+void loop() {
+ if (mySerial.available()) {
+ Serial.write(mySerial.read());
+ }
+ if (Serial.available()) {
+ mySerial.write(Serial.read());
+ }
+}
View
136 arduino/powerstrip/powerstrip.ino
@@ -0,0 +1,136 @@
+int pinNumber = 8;
+String id = "1";
+int lpLength = 50;
+int vals[50];
+int ind = 0;
+
+char inData[20]; // Allocate some space for the string
+char inChar=-1; // Where to store the character read
+byte index = 0; // Index into array; where to store the character
+
+void setup() {
+ pinMode(pinNumber, OUTPUT);
+ Serial.begin(9600);
+}
+
+void loop() {
+ int i = 0;
+ int x = analogRead(5);
+
+ if (Serial.available() > 0) {
+ // read theincoming byte:
+ i = Serial.read();
+ } else {
+ }
+ if (ind < lpLength) {
+ vals[ind] = x;
+ ind = ind + 1;
+ } else {
+ for (int i=0;i<lpLength-1;i++) {
+ vals[i] = vals[i+1];
+ }
+ vals[lpLength-1] = x;
+ }
+
+ String on = id+":on";
+ String off= id+":off";
+ String transmit = id+":tx";
+ if (id.equals("1") && i==97) {
+ digitalWrite(pinNumber,HIGH);
+ Serial.println(on);
+ }
+ else if (id.equals("1") && i==98) {
+ digitalWrite(pinNumber,LOW);
+ Serial.println(off);
+ }
+ else if (id.equals("1") && i==99){
+ int val = -1;
+ for (int i=0;i<lpLength;i++) {
+ if (vals[i] > val) {
+ val = vals[i];
+ }
+ }
+ float v = (val-512)*2.23296878f;
+ String str;
+ char buffer[10];
+ dtostrf(v,1,2,buffer);
+ str = String(buffer);
+ Serial.println(id+":"+str);
+ }
+
+ if (id.equals("2") && i==100) {
+ digitalWrite(pinNumber,HIGH);
+ Serial.println(on);
+ }
+ else if (id.equals("2") && i==101) {
+ digitalWrite(pinNumber,LOW);
+ Serial.println(off);
+ }
+ else if (id.equals("2") && i==102){
+ int val = -1;
+ for (int i=0;i<lpLength;i++) {
+ if (vals[i] > val) {
+ val = vals[i];
+ }
+ }
+ float v = (val-512)*2.23296878f;
+ String str;
+ char buffer[10];
+ dtostrf(v,1,2,buffer);
+ str = String(buffer);
+ Serial.println(id+":"+str);
+ }
+
+ if (id.equals("3") && i==103) {
+ digitalWrite(pinNumber,HIGH);
+ Serial.println(on);
+ }
+ else if (id.equals("3") && i==104) {
+ digitalWrite(pinNumber,LOW);
+ Serial.println(off);
+ }
+ else if (id.equals("3") && i==105){
+ int val = -1;
+ for (int i=0;i<ind;i++) {
+ if (vals[i] > val) {
+ val = vals[i];
+ }
+ }
+ float v = (val-512)*2.23296878f - 12.0f;
+ String str;
+ char buffer[10];
+ dtostrf(v,1,2,buffer);
+ str = String(buffer);
+ Serial.println(id+":"+str);
+ }
+ //}
+}
+
+char Comp(char* This){
+ while(Serial.available() > 0) // Don't read unless
+ // there you know there is data
+ {
+ if(index < 19) // One less than the size of the array
+ {
+ inChar = Serial.read(); // Read a character
+ inData[index] = inChar; // Store it
+ index++; // Increment where to write next
+ inData[index] = '\0'; // Null terminate the string
+ }
+ }
+ Serial.println(String(inData));
+
+ if(strcmp(inData,This) == 0){
+ for(int i=0;i<19;i++){
+ inData[i]=0;
+ }
+ index=0;
+ return(0);
+
+ }
+ else{
+ return(1);
+ }
+}
+
+
View
109 js/electrify.js
@@ -0,0 +1,109 @@
+var sp = require('serialport');
+var SerialPort = sp.SerialPort;
+port = "/dev/ttyACM0";
+var serialPort = new SerialPort(port,{
+ parser:sp.parsers.readline('\n')
+});
+var translate = {
+ "1:on":"a",
+ "1:off":"b",
+ "1:tx":"c",
+ "2:on":"d",
+ "2:off":"e",
+ "2:tx":"f", "3:on":"g",
+ "3:off":"h",
+ "3:tx":"i"
+}
+var Model = {
+ Powerstrip : function(id) {
+ this.state = true;
+ this.id = id;
+ this.on = function() {
+ serialPort.write(translate[id+":"+"on"]);
+ //this.state = true;
+ }
+ this.off = function() {
+ serialPort.write(translate[id+":"+"off"]);
+ }
+ this.toggle = function() {
+ if (this.state) {
+ this.off();
+ } else {
+ this.on();
+ }
+ }
+ this.set = function(val) {
+ this.state = val;
+ }
+ this.tx = function(val) {
+ serialPort.write(translate[id+":"+"tx"]);
+ }
+ }
+}
+serialPort.on('data',function(data){
+ data = data.trim();
+ var splt = data.split(":");
+ var id = splt[0];
+ var dt = splt[1];
+ if (parseFloat(dt)) {
+ for (var cb in dataCallbacks) {
+ dataCallbacks[cb](id, parseFloat(dt));
+ }
+ } else {
+ if (dt == "on") {
+ if (powerstrips[id]) {
+ powerstrips[id].set(true);
+ }
+ } else if (dt == "off") {
+ if (powerstrips[id]) {
+ powerstrips[id].set(false);
+ }
+ }
+ }
+});
+
+var powerstrips = {};
+
+var dataCallbacks = [];
+var addPowerstrip = function(id) {
+ var ps = new Model.Powerstrip(id);
+ powerstrips[id] = ps;
+}
+var interface = {
+ on : function(id) {
+ powerstrips[id].on();
+ },
+ off : function(id) {
+ powerstrips[id].off();
+ },
+ toggle : function(id) {
+ powerstrips[id].toggle();
+ },
+ state : function(id) {
+ return powerstrips[id].state;
+ },
+ tx : function(id) {
+ powerstrips[id].tx();
+ },
+ onData : function(cb) {
+ dataCallbacks.push(cb);
+ }
+}
+addPowerstrip(1);
+addPowerstrip(2);
+addPowerstrip(3);
+var getTx = function(id) {
+ (function(i){
+ setInterval(function() {
+ powerstrips[i].tx();
+ }, 1000);
+ })(id);
+};
+getTx("1");
+setTimeout(function() {
+ getTx("2");
+}, 250);
+setTimeout(function() {
+ getTx("3");
+}, 500);
+module.exports = interface;
View
49 js/filter.js
@@ -0,0 +1,49 @@
+Array.prototype.avg = function() {
+ var av = 0;
+ var cnt = 0;
+ var len = this.length;
+ for (var i = 0; i < len; i++) {
+ var e = +this[i];
+ if(!e && this[i] !== 0 && this[i] !== '0') e--;
+ if (this[i] == e) {av += e; cnt++;} }
+ return av/cnt;
+}
+Array.prototype.max = function() {
+ var max = this[0];
+ var len = this.length;
+ for (var i = 1; i < len; i++) if (this[i] > max) max = this[i];
+ return max;
+}
+Array.prototype.min = function() {
+ var min = this[0];
+ var len = this.length;
+ for (var i = 1; i < len; i++) if (this[i] < min) min = this[i];
+ return min;
+}
+var interface = {
+ AmpFilter : function(length, lowpass, poll, cb) {
+ this.length = length;
+ this.lowpass = lowpass;
+ var vals = [];
+ var amps = [];
+ var amp = 0;
+
+ this.add = function(data) {
+ if (vals.length > this.length) {
+ vals.shift();
+ }
+ vals.push(data);
+ var max = vals.max();
+ var min = vals.min();
+ amp = (max - 512)/ Math.sqrt(2);
+ if (amps.length > this.lowpass) {
+ amps.shift();
+ }
+ amps.push(amp);
+ }
+ setInterval(function() {
+ cb(amps.avg()/19*60);
+ }, poll);
+ }
+}
+module.exports = interface;
View
BIN  js/levels.mp3
Binary file not shown
View
62 js/main.js
@@ -0,0 +1,62 @@
+var express = require('express');
+var electricity = require('./electrify.js');
+var router = require('./router.js');
+var filter = require('./filter.js');
+var app = express.createServer();
+var sound = require('./sound.js');
+var Bridge = require('bridge-js');
+var bridge = new Bridge({ apiKey : "c44bcbad333664b9" });
+bridge.connect();
+var channel;
+var serviceHandler = {
+ subscribe : function(handler) {
+ bridge.joinChannel("electrify-channel", handler, true); } };
+var channelHandler = {
+ broadcast : function(id, data, state, timestamp) {
+ console.log(id, data, state);
+ }
+};
+bridge.publishService("electrify-service", serviceHandler);
+bridge.joinChannel("electrify-channel", channelHandler, true, function(c) {;
+ channel = c;
+});
+bridge.publishService("electrify", electricity);
+
+app.use(express.bodyParser());
+app.get('/api', function(req, res) {
+ var res = router.wrap(res);
+ res.json(Object.keys(filters));
+});
+app.get('/api/:id', function(req, res) {
+ var res = router.wrap(res);
+ res.json(electricity.state(req.params.id));
+});
+app.get('/api/:id/toggle', function(req, res) {
+ electricity.toggle(req.params.id);
+ res.json("success");
+});
+app.get('/api/:id/tx', function(req, res) {
+ electricity.tx(req.params.id);
+ res.json("success");
+});
+app.post('/api/:id', function(req, res) {
+ var res = router.wrap(res);
+ if (req.body.method) {
+ electricity[req.body.method](req.params.id);
+ if (req.body.method == "toggle") {
+ res.json(electricity.state(req.params.id));
+ } else {
+ res.json("success");
+ }
+ } else {
+ res.error("failure");
+ }
+});
+electricity.onData(function(id, data) {
+ channel.broadcast(id, data, electricity.state(id), (new Date()).getTime());
+});
+sound.clap(function() {
+// console.log("CLAP");
+ //electricity.toggle("1");
+});
+app.listen(8080);
View
8 js/mp3.js
@@ -0,0 +1,8 @@
+var fs = require('fs');
+var musicmetadata = require('musicmetadata');
+
+var parser = new musicmetadata(fs.createReadStream('levels.mp3'));
+
+parser.on('metadata', function(result) {
+ console.log(result);
+});
View
30 js/router.js
@@ -0,0 +1,30 @@
+var Model = {
+ Response:function(data, status, url, query, timestamp, elapsed) {
+ this.data = data;
+ this.status = status;
+ this.url = url;
+ this.query = query;
+ this.timestamp = timestamp.getTime();
+ this.elapsed = elapsed;
+ }
+};
+var interface = {
+ wrap : function(response) {
+ return new (function(res){
+ var wrapped = this;
+ this.json = function(json) {
+ var status = "success";
+ var response = new Model.Response(json, status, res.req.url, res.req.query, wrapped.timestamp, new Date()-wrapped.timestamp);
+ res.json(response);
+ }
+ this.error = function(error) {
+ var status = "error";
+ var response = new Model.Response(error, status, res.req.url, res.req.query, wrapped.timestamp, new Date()-wrapped.timestamp);
+ res.json(response);
+ }
+ this.res = res;
+ this.timestamp = new Date();
+ })(response);
+ }
+}
+module.exports = interface;
View
46 js/sound.js
@@ -0,0 +1,46 @@
+var Buffer = require('buffertools');
+var fs = require('fs');
+var curSpeak = null;
+var speaking = false;
+var sampleRate = 32000;
+var spawn = require('child_process').spawn;
+var SPEAKING_THRESHOLD = -20;
+var record = spawn('rec',['-b','16','-e','signed-integer','-c','1','-r',sampleRate,'-p']);
+var callbacks = [];
+record.stdout.on('data', function (d) {
+ fs.writeFile('temp',d);
+ var process = spawn('sox',['-b','16','-e','signed-integer','-c','1','-r',sampleRate,'-t','raw','temp','-n','stats']);
+ process.stderr.on('data',function(data){
+ var stats = data.toString('ascii').trim();
+ var spt = stats.split("\n");
+ for (var i in spt){
+ if (typeof(spt[i]) == "string") {
+ if (spt[i].indexOf("RMS lev dB")!=-1){
+ var vol = parseFloat(spt[i].match(/[-]?[0-9]+\.[0-9]+/)[0]);
+ if (vol > SPEAKING_THRESHOLD){
+ for (var i in callbacks) {
+ callbacks[i]();
+ }
+ } else {
+ }
+ }
+ }
+ }
+ });
+});
+
+record.stderr.on('data', function (data) {
+});
+
+record.on('exit', function (code) {
+ if (code !== 0) {
+ console.log('record process exited with code ' + code);
+ }
+ process.stdin.end();
+});
+var interface = {
+ clap : function(cb) {
+ callbacks.push(cb);
+ }
+}
+module.exports = interface;
View
BIN  js/temp
Binary file not shown
Please sign in to comment.
Something went wrong with that request. Please try again.