Permalink
Browse files

Initial working version with lots of cleanup and abstracting to do

  • Loading branch information...
0 parents commit 406a99a630e06d8c96cf3fadf2b1429d2fc776b2 Erik Kallen committed Feb 10, 2011
Showing with 14,218 additions and 0 deletions.
  1. +144 −0 LightController/Arduino/LightController.pde
  2. +4 −0 LightController/Rails/LightControl/.gitignore
  3. +32 −0 LightController/Rails/LightControl/Gemfile
  4. +81 −0 LightController/Rails/LightControl/Gemfile.lock
  5. +256 −0 LightController/Rails/LightControl/README
  6. +7 −0 LightController/Rails/LightControl/Rakefile
  7. +20 −0 LightController/Rails/LightControl/app/controllers/application_controller.rb
  8. +121 −0 LightController/Rails/LightControl/app/controllers/power_sockets_controller.rb
  9. +126 −0 LightController/Rails/LightControl/app/controllers/presets_controller.rb
  10. +13 −0 LightController/Rails/LightControl/app/controllers/settings_controller.rb
  11. +83 −0 LightController/Rails/LightControl/app/controllers/socket_states_controller.rb
  12. +13 −0 LightController/Rails/LightControl/app/helpers/application_helper.rb
  13. +2 −0 LightController/Rails/LightControl/app/helpers/power_sockets_helper.rb
  14. +2 −0 LightController/Rails/LightControl/app/helpers/presets_helper.rb
  15. +2 −0 LightController/Rails/LightControl/app/helpers/settings_helper.rb
  16. +2 −0 LightController/Rails/LightControl/app/helpers/socket_states_helper.rb
  17. +14 −0 LightController/Rails/LightControl/app/models/power_socket.rb
  18. +4 −0 LightController/Rails/LightControl/app/models/preset.rb
  19. +4 −0 LightController/Rails/LightControl/app/models/socket_state.rb
  20. +24 −0 LightController/Rails/LightControl/app/views/layouts/application.html.erb
  21. +31 −0 LightController/Rails/LightControl/app/views/layouts/application.mobile.erb
  22. +25 −0 LightController/Rails/LightControl/app/views/power_sockets/_form.html.erb
  23. +16 −0 LightController/Rails/LightControl/app/views/power_sockets/_form.mobile.erb
  24. +6 −0 LightController/Rails/LightControl/app/views/power_sockets/edit.html.erb
  25. +1 −0 LightController/Rails/LightControl/app/views/power_sockets/edit.mobile.erb
  26. +12 −0 LightController/Rails/LightControl/app/views/power_sockets/index.html.erb
  27. +48 −0 LightController/Rails/LightControl/app/views/power_sockets/index.mobile.erb
  28. +5 −0 LightController/Rails/LightControl/app/views/power_sockets/new.html.erb
  29. +1 −0 LightController/Rails/LightControl/app/views/power_sockets/new.mobile.erb
  30. +15 −0 LightController/Rails/LightControl/app/views/power_sockets/show.html.erb
  31. +13 −0 LightController/Rails/LightControl/app/views/power_sockets/show.mobile.erb
  32. +25 −0 LightController/Rails/LightControl/app/views/presets/_form.html.erb
  33. +6 −0 LightController/Rails/LightControl/app/views/presets/edit.html.erb
  34. +23 −0 LightController/Rails/LightControl/app/views/presets/index.html.erb
  35. +11 −0 LightController/Rails/LightControl/app/views/presets/index.mobile.erb
  36. +5 −0 LightController/Rails/LightControl/app/views/presets/new.html.erb
  37. +15 −0 LightController/Rails/LightControl/app/views/presets/show.html.erb
  38. +20 −0 LightController/Rails/LightControl/app/views/settings/index.html.erb
  39. +11 −0 LightController/Rails/LightControl/app/views/settings/index.mobile.erb
  40. +31 −0 LightController/Rails/LightControl/app/views/settings/show.html.erb
  41. +85 −0 LightController/Rails/LightControl/app/views/settings/show.mobile.erb
  42. +29 −0 LightController/Rails/LightControl/app/views/socket_states/_form.html.erb
  43. +6 −0 LightController/Rails/LightControl/app/views/socket_states/edit.html.erb
  44. +30 −0 LightController/Rails/LightControl/app/views/socket_states/index.html.erb
  45. +5 −0 LightController/Rails/LightControl/app/views/socket_states/new.html.erb
  46. +20 −0 LightController/Rails/LightControl/app/views/socket_states/show.html.erb
  47. +4 −0 LightController/Rails/LightControl/config.ru
  48. +42 −0 LightController/Rails/LightControl/config/application.rb
  49. +13 −0 LightController/Rails/LightControl/config/boot.rb
  50. +22 −0 LightController/Rails/LightControl/config/database.yml
  51. +5 −0 LightController/Rails/LightControl/config/environment.rb
  52. +22 −0 LightController/Rails/LightControl/config/environments/development.rb
  53. +49 −0 LightController/Rails/LightControl/config/environments/production.rb
  54. +35 −0 LightController/Rails/LightControl/config/environments/test.rb
  55. +7 −0 LightController/Rails/LightControl/config/initializers/backtrace_silencers.rb
  56. +10 −0 LightController/Rails/LightControl/config/initializers/inflections.rb
  57. +6 −0 LightController/Rails/LightControl/config/initializers/mime_types.rb
  58. +7 −0 LightController/Rails/LightControl/config/initializers/secret_token.rb
  59. +8 −0 LightController/Rails/LightControl/config/initializers/session_store.rb
  60. +5 −0 LightController/Rails/LightControl/config/locales/en.yml
  61. +82 −0 LightController/Rails/LightControl/config/routes.rb
  62. +14 −0 LightController/Rails/LightControl/db/migrate/20100813200041_create_power_sockets.rb
  63. +14 −0 LightController/Rails/LightControl/db/migrate/20100815131640_create_presets.rb
  64. +15 −0 LightController/Rails/LightControl/db/migrate/20100821071147_create_socket_states.rb
  65. +9 −0 LightController/Rails/LightControl/db/migrate/20100822094950_add_current_state_to_power_sockets.rb
  66. +9 −0 LightController/Rails/LightControl/db/migrate/20100822111125_add_active_to_presets.rb
  67. +39 −0 LightController/Rails/LightControl/db/schema.rb
  68. +7 −0 LightController/Rails/LightControl/db/seeds.rb
  69. +2 −0 LightController/Rails/LightControl/doc/README_FOR_APP
  70. 0 LightController/Rails/LightControl/lib/tasks/.gitkeep
  71. +26 −0 LightController/Rails/LightControl/public/404.html
  72. +26 −0 LightController/Rails/LightControl/public/422.html
  73. +26 −0 LightController/Rails/LightControl/public/500.html
  74. 0 LightController/Rails/LightControl/public/favicon.ico
  75. BIN LightController/Rails/LightControl/public/images/add.png
  76. BIN LightController/Rails/LightControl/public/images/coffee.png
  77. BIN LightController/Rails/LightControl/public/images/kast.png
  78. BIN LightController/Rails/LightControl/public/images/lightning.png
  79. BIN LightController/Rails/LightControl/public/images/moon.png
  80. BIN LightController/Rails/LightControl/public/images/off.png
  81. BIN LightController/Rails/LightControl/public/images/on.png
  82. BIN LightController/Rails/LightControl/public/images/outlet.png
  83. BIN LightController/Rails/LightControl/public/images/presets.png
  84. BIN LightController/Rails/LightControl/public/images/rails.png
  85. BIN LightController/Rails/LightControl/public/images/redToolButton.png
  86. BIN LightController/Rails/LightControl/public/images/settings.png
  87. BIN LightController/Rails/LightControl/public/images/tv.png
  88. +2 −0 LightController/Rails/LightControl/public/javascripts/application.js
  89. +965 −0 LightController/Rails/LightControl/public/javascripts/controls.js
  90. +974 −0 LightController/Rails/LightControl/public/javascripts/dragdrop.js
  91. +1,123 −0 LightController/Rails/LightControl/public/javascripts/effects.js
  92. +3 −0 LightController/Rails/LightControl/public/javascripts/mobile.js
  93. +6,001 −0 LightController/Rails/LightControl/public/javascripts/prototype.js
  94. +175 −0 LightController/Rails/LightControl/public/javascripts/rails.js
  95. +51 −0 LightController/Rails/LightControl/public/jqtouch/extensions/jqt.autotitles.js
  96. +92 −0 LightController/Rails/LightControl/public/jqtouch/extensions/jqt.floaty.js
  97. +68 −0 LightController/Rails/LightControl/public/jqtouch/extensions/jqt.location.js
  98. +97 −0 LightController/Rails/LightControl/public/jqtouch/extensions/jqt.offline.js
  99. +373 −0 LightController/Rails/LightControl/public/jqtouch/jqtouch.css
  100. +634 −0 LightController/Rails/LightControl/public/jqtouch/jqtouch.js
  101. +1 −0 LightController/Rails/LightControl/public/jqtouch/jqtouch.min.css
  102. +1 −0 LightController/Rails/LightControl/public/jqtouch/jqtouch.min.js
  103. +60 −0 LightController/Rails/LightControl/public/jqtouch/jqtouch.transitions.js
  104. +19 −0 LightController/Rails/LightControl/public/jqtouch/jquery.1.3.2.min.js
  105. BIN LightController/Rails/LightControl/public/jqtouch/themes/apple/img/backButton.png
  106. BIN LightController/Rails/LightControl/public/jqtouch/themes/apple/img/blueButton.png
  107. BIN LightController/Rails/LightControl/public/jqtouch/themes/apple/img/cancel.png
  108. BIN LightController/Rails/LightControl/public/jqtouch/themes/apple/img/chevron.png
  109. BIN LightController/Rails/LightControl/public/jqtouch/themes/apple/img/grayButton.png
  110. BIN LightController/Rails/LightControl/public/jqtouch/themes/apple/img/greenButton.png
  111. BIN LightController/Rails/LightControl/public/jqtouch/themes/apple/img/listArrowSel.png
  112. BIN LightController/Rails/LightControl/public/jqtouch/themes/apple/img/listGroup.png
  113. BIN LightController/Rails/LightControl/public/jqtouch/themes/apple/img/loading.gif
  114. BIN LightController/Rails/LightControl/public/jqtouch/themes/apple/img/on_off.png
  115. BIN LightController/Rails/LightControl/public/jqtouch/themes/apple/img/pinstripes.png
  116. BIN LightController/Rails/LightControl/public/jqtouch/themes/apple/img/redButton.png
  117. BIN LightController/Rails/LightControl/public/jqtouch/themes/apple/img/redToolButton.png
  118. BIN LightController/Rails/LightControl/public/jqtouch/themes/apple/img/selection.png
  119. BIN LightController/Rails/LightControl/public/jqtouch/themes/apple/img/thumb.png
  120. BIN LightController/Rails/LightControl/public/jqtouch/themes/apple/img/toggle.png
  121. BIN LightController/Rails/LightControl/public/jqtouch/themes/apple/img/toggleOn.png
  122. BIN LightController/Rails/LightControl/public/jqtouch/themes/apple/img/toolButton.png
  123. BIN LightController/Rails/LightControl/public/jqtouch/themes/apple/img/toolbar.png
  124. BIN LightController/Rails/LightControl/public/jqtouch/themes/apple/img/whiteButton.png
  125. +707 −0 LightController/Rails/LightControl/public/jqtouch/themes/apple/theme.css
  126. +1 −0 LightController/Rails/LightControl/public/jqtouch/themes/apple/theme.min.css
  127. BIN LightController/Rails/LightControl/public/jqtouch/themes/jqt/img/back_button.png
  128. BIN LightController/Rails/LightControl/public/jqtouch/themes/jqt/img/back_button_clicked.png
  129. BIN LightController/Rails/LightControl/public/jqtouch/themes/jqt/img/button.png
  130. BIN LightController/Rails/LightControl/public/jqtouch/themes/jqt/img/button_clicked.png
  131. BIN LightController/Rails/LightControl/public/jqtouch/themes/jqt/img/chevron.png
  132. BIN LightController/Rails/LightControl/public/jqtouch/themes/jqt/img/chevron_circle.png
  133. BIN LightController/Rails/LightControl/public/jqtouch/themes/jqt/img/grayButton.png
  134. BIN LightController/Rails/LightControl/public/jqtouch/themes/jqt/img/loading.gif
  135. BIN LightController/Rails/LightControl/public/jqtouch/themes/jqt/img/on_off.png
  136. BIN LightController/Rails/LightControl/public/jqtouch/themes/jqt/img/rowhead.png
  137. BIN LightController/Rails/LightControl/public/jqtouch/themes/jqt/img/toggle.png
  138. BIN LightController/Rails/LightControl/public/jqtouch/themes/jqt/img/toggleOn.png
  139. BIN LightController/Rails/LightControl/public/jqtouch/themes/jqt/img/toolbar.png
  140. BIN LightController/Rails/LightControl/public/jqtouch/themes/jqt/img/whiteButton.png
  141. +527 −0 LightController/Rails/LightControl/public/jqtouch/themes/jqt/theme.css
  142. +1 −0 LightController/Rails/LightControl/public/jqtouch/themes/jqt/theme.min.css
  143. +5 −0 LightController/Rails/LightControl/public/robots.txt
  144. 0 LightController/Rails/LightControl/public/stylesheets/.gitkeep
  145. +100 −0 LightController/Rails/LightControl/public/stylesheets/scaffold.css
  146. +6 −0 LightController/Rails/LightControl/script/rails
  147. +9 −0 LightController/Rails/LightControl/test/fixtures/power_sockets.yml
  148. +9 −0 LightController/Rails/LightControl/test/fixtures/presets.yml
  149. +11 −0 LightController/Rails/LightControl/test/fixtures/socket_states.yml
  150. +49 −0 LightController/Rails/LightControl/test/functional/power_sockets_controller_test.rb
  151. +49 −0 LightController/Rails/LightControl/test/functional/presets_controller_test.rb
  152. +8 −0 LightController/Rails/LightControl/test/functional/settings_controller_test.rb
  153. +49 −0 LightController/Rails/LightControl/test/functional/socket_states_controller_test.rb
  154. +9 −0 LightController/Rails/LightControl/test/performance/browsing_test.rb
  155. +13 −0 LightController/Rails/LightControl/test/test_helper.rb
  156. +4 −0 LightController/Rails/LightControl/test/unit/helpers/power_sockets_helper_test.rb
  157. +4 −0 LightController/Rails/LightControl/test/unit/helpers/presets_helper_test.rb
  158. +4 −0 LightController/Rails/LightControl/test/unit/helpers/settings_helper_test.rb
  159. +4 −0 LightController/Rails/LightControl/test/unit/helpers/socket_states_helper_test.rb
  160. +8 −0 LightController/Rails/LightControl/test/unit/power_socket_test.rb
  161. +8 −0 LightController/Rails/LightControl/test/unit/preset_test.rb
  162. +8 −0 LightController/Rails/LightControl/test/unit/socket_state_test.rb
  163. 0 LightController/Rails/LightControl/vendor/plugins/.gitkeep
  164. +31 −0 LightController/Ruby/ArduinoController.rb
  165. +2 −0 README
@@ -0,0 +1,144 @@
+/*
+* LightController - Control a remote control light switch using a arduino and a 433MHz radio
+* using a simple serial protocol
+*
+* @author Erik Kallen info@erikkallen.nl
+* @version 0.1
+*/
+#include <Messenger.h>
+
+#define rfPin 2
+#define ledPin 13
+
+#define byte1 0x2A
+#define byte2 0xAA
+
+#define S_A 0x9F // Bij de kast
+#define S_B 0xE7 // Bed
+#define S_C 0xF9 // Bank
+#define S_D 0x7F // Bureau
+#define S_E 0x9E
+
+#define S_ON 0xF3
+#define S_OFF 0xFC
+Messenger command = Messenger();
+
+// Create the callback method
+void cmdReady() {
+ // Loop through all the available elements of the message
+ while ( !command.available() );
+ char cmd = command.readChar();
+ // Strip '=' from stream
+ //char eq = command.readChar();
+ char stateChar = command.readChar();
+ byte stateByte = 0;
+ if (stateChar == '1') {
+ stateByte = S_ON;
+ } else {
+ stateByte = S_OFF;
+ }
+
+
+ switch(cmd) {
+ case 'a':
+ // Serial.println("AA");
+ sendCommand(S_A, stateByte);
+ break;
+ case 'b':
+ //Serial.println("BB");
+ sendCommand(S_B, stateByte);
+ break;
+ case 'c':
+ // Serial.println("CC");
+ sendCommand(S_C, stateByte);
+ break;
+ case 'd':
+ // Serial.println("DD");
+ sendCommand(S_D, stateByte);
+ break;
+ case 'e':
+ Serial.println("EE");
+ sendCommand(S_E, stateByte);
+ break;
+ //default:
+ // Serial.println("No match");
+ }
+
+}
+
+
+void setup() {
+ pinMode(rfPin,OUTPUT);
+ pinMode(ledPin,OUTPUT);
+// pinMode(tePin,OUTPUT);
+ digitalWrite(rfPin, LOW);
+ digitalWrite(ledPin, HIGH);
+// digitalWrite(tePin, HIGH);
+ Serial.begin(9600);
+ command.attach(cmdReady);
+ Serial.println("Arduino booted");
+}
+
+void loop() {
+ while ( Serial.available() ) command.process(Serial.read());
+}
+
+void sendCommand(int sw, int state) {
+ switch (sw) {
+ case S_A:
+ case S_B:
+ case S_C:
+ sendPacket(sw, state);
+ break;
+ case S_D:
+ sendPacket(0xFF, sw & state);
+ break;
+ case S_E:
+ sendPacket(0xFF, 0x9F & state);
+ break;
+ }
+}
+
+void sendPacket(byte firstByte, byte lastByte) {
+ for (int i=0;i<8;i++){
+ delay(4);
+ // Preamble
+ for (int i=0;i<9;i++) {
+ sendBit(0);
+ }
+
+ sendByte(byte1 & firstByte);
+ sendByte(byte2 & lastByte);
+
+ delay(4);
+ }
+}
+
+void sendByte(byte b) {
+ for (int i=0;i<8;i++) {
+ if ((b&0x80) == 0x80) {
+ sendBit(1);
+ } else {
+ sendBit(0);
+ }
+ b = b << 1;
+ }
+}
+
+void sendBit(int val) {
+ if (val) {
+ digitalWrite(ledPin, HIGH);
+ digitalWrite(rfPin, HIGH);
+ delayMicroseconds(998);
+ digitalWrite(rfPin, LOW);
+ digitalWrite(ledPin, LOW);
+ delayMicroseconds(320);
+ } else {
+ digitalWrite(ledPin, HIGH);
+ digitalWrite(rfPin, HIGH);
+ delayMicroseconds(340);
+ digitalWrite(rfPin, LOW);
+ digitalWrite(ledPin, LOW);
+ delayMicroseconds(998);
+ }
+}
@@ -0,0 +1,4 @@
+.bundle
+db/*.sqlite3
+log/*.log
+tmp/**/*
@@ -0,0 +1,32 @@
+source 'http://rubygems.org'
+
+gem 'rails', '3.0.0.rc'
+
+# Bundle edge Rails instead:
+# gem 'rails', :git => 'git://github.com/rails/rails.git'
+
+gem 'sqlite3-ruby', :require => 'sqlite3'
+#gem "mongrel"
+gem 'serialport'
+# Use unicorn as the web server
+# gem 'unicorn'
+
+# Deploy with Capistrano
+# gem 'capistrano'
+
+# To use debugger
+# gem 'ruby-debug'
+
+# Bundle the extra gems:
+# gem 'bj'
+# gem 'nokogiri', '1.4.1'
+# gem 'sqlite3-ruby', :require => 'sqlite3'
+# gem 'aws-s3', :require => 'aws/s3'
+
+# Bundle gems for the local environment. Make sure to
+# put test-only gems in this group so their generators
+# and rake tasks are available in development mode:
+group :development, :test do
+ gem "mongrel"
+# gem 'webrat'
+end
@@ -0,0 +1,81 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ abstract (1.0.0)
+ actionmailer (3.0.0.rc)
+ actionpack (= 3.0.0.rc)
+ mail (~> 2.2.5)
+ actionpack (3.0.0.rc)
+ activemodel (= 3.0.0.rc)
+ activesupport (= 3.0.0.rc)
+ builder (~> 2.1.2)
+ erubis (~> 2.6.6)
+ i18n (~> 0.4.1)
+ rack (~> 1.2.1)
+ rack-mount (~> 0.6.9)
+ rack-test (~> 0.5.4)
+ tzinfo (~> 0.3.22)
+ activemodel (3.0.0.rc)
+ activesupport (= 3.0.0.rc)
+ builder (~> 2.1.2)
+ i18n (~> 0.4.1)
+ activerecord (3.0.0.rc)
+ activemodel (= 3.0.0.rc)
+ activesupport (= 3.0.0.rc)
+ arel (~> 0.4.0)
+ tzinfo (~> 0.3.22)
+ activeresource (3.0.0.rc)
+ activemodel (= 3.0.0.rc)
+ activesupport (= 3.0.0.rc)
+ activesupport (3.0.0.rc)
+ arel (0.4.0)
+ activesupport (>= 3.0.0.beta)
+ builder (2.1.2)
+ daemons (1.0.10)
+ erubis (2.6.6)
+ abstract (>= 1.0.0)
+ gem_plugin (0.2.3)
+ i18n (0.4.1)
+ mail (2.2.5)
+ activesupport (>= 2.3.6)
+ mime-types
+ treetop (>= 1.4.5)
+ mime-types (1.16)
+ mongrel (1.2.0.pre2)
+ daemons (~> 1.0.10)
+ gem_plugin (~> 0.2.3)
+ polyglot (0.3.1)
+ rack (1.2.1)
+ rack-mount (0.6.9)
+ rack (>= 1.0.0)
+ rack-test (0.5.4)
+ rack (>= 1.0)
+ rails (3.0.0.rc)
+ actionmailer (= 3.0.0.rc)
+ actionpack (= 3.0.0.rc)
+ activerecord (= 3.0.0.rc)
+ activeresource (= 3.0.0.rc)
+ activesupport (= 3.0.0.rc)
+ bundler (>= 1.0.0.rc.1)
+ railties (= 3.0.0.rc)
+ railties (3.0.0.rc)
+ actionpack (= 3.0.0.rc)
+ activesupport (= 3.0.0.rc)
+ rake (>= 0.8.3)
+ thor (~> 0.14.0)
+ rake (0.8.7)
+ serialport (1.0.4)
+ sqlite3-ruby (1.3.1)
+ thor (0.14.0)
+ treetop (1.4.8)
+ polyglot (>= 0.3.1)
+ tzinfo (0.3.22)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ mongrel
+ rails (= 3.0.0.rc)
+ serialport
+ sqlite3-ruby
Oops, something went wrong.

0 comments on commit 406a99a

Please sign in to comment.