-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpatch.diff
More file actions
3698 lines (3683 loc) · 176 KB
/
patch.diff
File metadata and controls
3698 lines (3683 loc) · 176 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
From f988f99b6b3316b64d7d21c14b478d8bd0bf09ee Mon Sep 17 00:00:00 2001
From: Jose Maria Rodriguez Saez <fox2002@gmail.com>
Date: Fri, 22 Jan 2016 19:10:10 +0000
Subject: [PATCH] Initial release. Al function working so far. Following the
app will be simplified.
---
.gitignore | 8 +
.idea/.name | 1 +
.idea/compiler.xml | 22 +++
.idea/copyright/profiles_settings.xml | 3 +
.idea/encodings.xml | 6 +
.idea/gradle.xml | 19 ++
.idea/misc.xml | 46 +++++
.idea/modules.xml | 9 +
.idea/runConfigurations.xml | 12 ++
.idea/vcs.xml | 6 +
app/.gitignore | 1 +
app/build.gradle | 30 +++
app/proguard-rules.pro | 17 ++
.../es/jmrs/pablossmartlight/ApplicationTest.java | 13 ++
app/src/main/AndroidManifest.xml | 27 +++
.../java/es/jmrs/pablossmartlight/LEDConfig.java | 52 ++++++
.../es/jmrs/pablossmartlight/MainActivity.java | 203 ++++++++++++++++++++
.../java/es/jmrs/pablossmartlight/PSLControl.java | 208 +++++++++++++++++++++
.../es/jmrs/pablossmartlight/SensorsFragment.java | 113 +++++++++++
.../jmrs/pablossmartlight/SensorsInformation.java | 61 ++++++
app/src/main/java/layout/ColorsFragment.java | 177 ++++++++++++++++++
app/src/main/res/layout/activity_main.xml | 47 +++++
app/src/main/res/layout/fragment_colors.xml | 153 +++++++++++++++
.../main/res/layout/fragment_debug_and_test.xml | 56 ++++++
app/src/main/res/layout/fragment_main.xml | 56 ++++++
app/src/main/res/layout/fragment_sensors.xml | 77 ++++++++
app/src/main/res/menu/menu_main.xml | 10 +
app/src/main/res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 3418 bytes
app/src/main/res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 2206 bytes
app/src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 4842 bytes
app/src/main/res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 7718 bytes
app/src/main/res/mipmap-xxxhdpi/ic_launcher.png | Bin 0 -> 10486 bytes
app/src/main/res/values-v21/styles.xml | 9 +
app/src/main/res/values-w820dp/dimens.xml | 6 +
app/src/main/res/values/colors.xml | 6 +
app/src/main/res/values/dimens.xml | 7 +
app/src/main/res/values/strings.xml | 8 +
app/src/main/res/values/styles.xml | 20 ++
.../es/jmrs/pablossmartlight/ExampleUnitTest.java | 15 ++
build.gradle | 23 +++
gradle.properties | 18 ++
gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 53637 bytes
gradle/wrapper/gradle-wrapper.properties | 6 +
gradlew | 160 ++++++++++++++++
gradlew.bat | 90 +++++++++
settings.gradle | 1 +
46 files changed, 1802 insertions(+)
create mode 100644 .gitignore
create mode 100644 .idea/.name
create mode 100644 .idea/compiler.xml
create mode 100644 .idea/copyright/profiles_settings.xml
create mode 100644 .idea/encodings.xml
create mode 100644 .idea/gradle.xml
create mode 100644 .idea/misc.xml
create mode 100644 .idea/modules.xml
create mode 100644 .idea/runConfigurations.xml
create mode 100644 .idea/vcs.xml
create mode 100644 app/.gitignore
create mode 100644 app/build.gradle
create mode 100644 app/proguard-rules.pro
create mode 100644 app/src/androidTest/java/es/jmrs/pablossmartlight/ApplicationTest.java
create mode 100644 app/src/main/AndroidManifest.xml
create mode 100644 app/src/main/java/es/jmrs/pablossmartlight/LEDConfig.java
create mode 100644 app/src/main/java/es/jmrs/pablossmartlight/MainActivity.java
create mode 100644 app/src/main/java/es/jmrs/pablossmartlight/PSLControl.java
create mode 100644 app/src/main/java/es/jmrs/pablossmartlight/SensorsFragment.java
create mode 100644 app/src/main/java/es/jmrs/pablossmartlight/SensorsInformation.java
create mode 100644 app/src/main/java/layout/ColorsFragment.java
create mode 100644 app/src/main/res/layout/activity_main.xml
create mode 100644 app/src/main/res/layout/fragment_colors.xml
create mode 100644 app/src/main/res/layout/fragment_debug_and_test.xml
create mode 100644 app/src/main/res/layout/fragment_main.xml
create mode 100644 app/src/main/res/layout/fragment_sensors.xml
create mode 100644 app/src/main/res/menu/menu_main.xml
create mode 100644 app/src/main/res/mipmap-hdpi/ic_launcher.png
create mode 100644 app/src/main/res/mipmap-mdpi/ic_launcher.png
create mode 100644 app/src/main/res/mipmap-xhdpi/ic_launcher.png
create mode 100644 app/src/main/res/mipmap-xxhdpi/ic_launcher.png
create mode 100644 app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
create mode 100644 app/src/main/res/values-v21/styles.xml
create mode 100644 app/src/main/res/values-w820dp/dimens.xml
create mode 100644 app/src/main/res/values/colors.xml
create mode 100644 app/src/main/res/values/dimens.xml
create mode 100644 app/src/main/res/values/strings.xml
create mode 100644 app/src/main/res/values/styles.xml
create mode 100644 app/src/test/java/es/jmrs/pablossmartlight/ExampleUnitTest.java
create mode 100644 build.gradle
create mode 100644 gradle.properties
create mode 100644 gradle/wrapper/gradle-wrapper.jar
create mode 100644 gradle/wrapper/gradle-wrapper.properties
create mode 100644 gradlew
create mode 100644 gradlew.bat
create mode 100644 settings.gradle
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..c6cbe56
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,8 @@
+*.iml
+.gradle
+/local.properties
+/.idea/workspace.xml
+/.idea/libraries
+.DS_Store
+/build
+/captures
diff --git a/.idea/.name b/.idea/.name
new file mode 100644
index 0000000..543563b
--- /dev/null
+++ b/.idea/.name
@@ -0,0 +1 @@
+PablosSmartLight
\ No newline at end of file
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
new file mode 100644
index 0000000..9a8b7e5
--- /dev/null
+++ b/.idea/compiler.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="CompilerConfiguration">
+ <option name="DEFAULT_COMPILER" value="Javac" />
+ <resourceExtensions />
+ <wildcardResourcePatterns>
+ <entry name="!?*.java" />
+ <entry name="!?*.form" />
+ <entry name="!?*.class" />
+ <entry name="!?*.groovy" />
+ <entry name="!?*.scala" />
+ <entry name="!?*.flex" />
+ <entry name="!?*.kt" />
+ <entry name="!?*.clj" />
+ </wildcardResourcePatterns>
+ <annotationProcessing>
+ <profile default="true" name="Default" enabled="false">
+ <processorPath useClasspath="true" />
+ </profile>
+ </annotationProcessing>
+ </component>
+</project>
\ No newline at end of file
diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml
new file mode 100644
index 0000000..e7bedf3
--- /dev/null
+++ b/.idea/copyright/profiles_settings.xml
@@ -0,0 +1,3 @@
+<component name="CopyrightManager">
+ <settings default="" />
+</component>
\ No newline at end of file
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
new file mode 100644
index 0000000..97626ba
--- /dev/null
+++ b/.idea/encodings.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="Encoding">
+ <file url="PROJECT" charset="UTF-8" />
+ </component>
+</project>
\ No newline at end of file
diff --git a/.idea/gradle.xml b/.idea/gradle.xml
new file mode 100644
index 0000000..d390b65
--- /dev/null
+++ b/.idea/gradle.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="GradleSettings">
+ <option name="linkedExternalProjectsSettings">
+ <GradleProjectSettings>
+ <option name="distributionType" value="LOCAL" />
+ <option name="externalProjectPath" value="$PROJECT_DIR$" />
+ <option name="gradleHome" value="C:\Program Files\Android\Android Studio\gradle\gradle-2.8" />
+ <option name="gradleJvm" value="1.7" />
+ <option name="modules">
+ <set>
+ <option value="$PROJECT_DIR$" />
+ <option value="$PROJECT_DIR$/app" />
+ </set>
+ </option>
+ </GradleProjectSettings>
+ </option>
+ </component>
+</project>
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..6a1e020
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="EntryPointsManager">
+ <entry_points version="2.0" />
+ </component>
+ <component name="NullableNotNullManager">
+ <option name="myDefaultNullable" value="android.support.annotation.Nullable" />
+ <option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
+ <option name="myNullables">
+ <value>
+ <list size="4">
+ <item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
+ <item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
+ <item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" />
+ <item index="3" class="java.lang.String" itemvalue="android.support.annotation.Nullable" />
+ </list>
+ </value>
+ </option>
+ <option name="myNotNulls">
+ <value>
+ <list size="4">
+ <item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" />
+ <item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" />
+ <item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" />
+ <item index="3" class="java.lang.String" itemvalue="android.support.annotation.NonNull" />
+ </list>
+ </value>
+ </option>
+ </component>
+ <component name="ProjectLevelVcsManager" settingsEditedManually="false">
+ <OptionsSetting value="true" id="Add" />
+ <OptionsSetting value="true" id="Remove" />
+ <OptionsSetting value="true" id="Checkout" />
+ <OptionsSetting value="true" id="Update" />
+ <OptionsSetting value="true" id="Status" />
+ <OptionsSetting value="true" id="Edit" />
+ <ConfirmationsSetting value="0" id="Add" />
+ <ConfirmationsSetting value="0" id="Remove" />
+ </component>
+ <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" assert-keyword="true" jdk-15="true" project-jdk-name="1.7" project-jdk-type="JavaSDK">
+ <output url="file://$PROJECT_DIR$/build/classes" />
+ </component>
+ <component name="ProjectType">
+ <option name="id" value="Android" />
+ </component>
+</project>
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..0bcff4d
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="ProjectModuleManager">
+ <modules>
+ <module fileurl="file://$PROJECT_DIR$/PablosSmartLight.iml" filepath="$PROJECT_DIR$/PablosSmartLight.iml" />
+ <module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
+ </modules>
+ </component>
+</project>
\ No newline at end of file
diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml
new file mode 100644
index 0000000..7f68460
--- /dev/null
+++ b/.idea/runConfigurations.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="RunConfigurationProducerService">
+ <option name="ignoredProducers">
+ <set>
+ <option value="org.jetbrains.plugins.gradle.execution.test.runner.AllInPackageGradleConfigurationProducer" />
+ <option value="org.jetbrains.plugins.gradle.execution.test.runner.TestClassGradleConfigurationProducer" />
+ <option value="org.jetbrains.plugins.gradle.execution.test.runner.TestMethodGradleConfigurationProducer" />
+ </set>
+ </option>
+ </component>
+</project>
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..6564d52
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="VcsDirectoryMappings">
+ <mapping directory="" vcs="" />
+ </component>
+</project>
\ No newline at end of file
diff --git a/app/.gitignore b/app/.gitignore
new file mode 100644
index 0000000..796b96d
--- /dev/null
+++ b/app/.gitignore
@@ -0,0 +1 @@
+/build
diff --git a/app/build.gradle b/app/build.gradle
new file mode 100644
index 0000000..2553647
--- /dev/null
+++ b/app/build.gradle
@@ -0,0 +1,30 @@
+apply plugin: 'com.android.application'
+
+android {
+ compileSdkVersion 22
+ buildToolsVersion '23.0.2'
+
+ defaultConfig {
+ applicationId "es.jmrs.pablossmartlight"
+ minSdkVersion 22
+ targetSdkVersion 22
+ versionCode 1
+ versionName "1.0"
+ }
+ buildTypes {
+ release {
+ minifyEnabled false
+ proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
+ }
+ }
+}
+
+dependencies {
+ compile fileTree(dir: 'libs', include: ['*.jar'])
+ testCompile 'junit:junit:4.12'
+ compile 'com.android.support:appcompat-v7:22.2.1'
+ compile 'com.android.support:design:22.2.1'
+ compile 'org.apache.httpcomponents:httpclient-android:4.3.5.1'
+ compile 'com.larswerkman:HoloColorPicker:1.5'
+ compile 'com.android.support:support-v4:22.2.1'
+}
diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro
new file mode 100644
index 0000000..bed187e
--- /dev/null
+++ b/app/proguard-rules.pro
@@ -0,0 +1,17 @@
+# Add project specific ProGuard rules here.
+# By default, the flags in this file are appended to flags specified
+# in C:\Users\jmrodriguez\AppData\Local\Android\sdk/tools/proguard/proguard-android.txt
+# You can edit the include path and order by changing the proguardFiles
+# directive in build.gradle.
+#
+# 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 *;
+#}
diff --git a/app/src/androidTest/java/es/jmrs/pablossmartlight/ApplicationTest.java b/app/src/androidTest/java/es/jmrs/pablossmartlight/ApplicationTest.java
new file mode 100644
index 0000000..6180630
--- /dev/null
+++ b/app/src/androidTest/java/es/jmrs/pablossmartlight/ApplicationTest.java
@@ -0,0 +1,13 @@
+package es.jmrs.pablossmartlight;
+
+import android.app.Application;
+import android.test.ApplicationTestCase;
+
+/**
+ * <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
+ */
+public class ApplicationTest extends ApplicationTestCase<Application> {
+ public ApplicationTest() {
+ super(Application.class);
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
new file mode 100644
index 0000000..62c42b6
--- /dev/null
+++ b/app/src/main/AndroidManifest.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="es.jmrs.pablossmartlight">
+
+ <uses-permission android:name="android.permission.INTERNET"/>
+
+ <application
+ android:allowBackup="true"
+ android:icon="@mipmap/ic_launcher"
+ android:label="@string/app_name"
+ android:supportsRtl="true"
+ android:theme="@style/AppTheme">
+
+ <activity
+ android:name=".MainActivity"
+ android:label="@string/app_name"
+ android:theme="@style/AppTheme.NoActionBar">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+
+ </application>
+
+</manifest>
diff --git a/app/src/main/java/es/jmrs/pablossmartlight/LEDConfig.java b/app/src/main/java/es/jmrs/pablossmartlight/LEDConfig.java
new file mode 100644
index 0000000..66c89ae
--- /dev/null
+++ b/app/src/main/java/es/jmrs/pablossmartlight/LEDConfig.java
@@ -0,0 +1,52 @@
+package es.jmrs.pablossmartlight;
+
+/**
+ * Created by jmrodriguez on 19/12/2015.
+ */
+public class LEDConfig {
+
+ private String m_command;
+ private int m_RGB;
+ private int m_brightness;
+ private int m_delay;
+
+ public LEDConfig(String command, int red, int green, int blue, int brightness, int delay)
+ {
+ m_command = command;
+ m_RGB = (red << 16) | (green << 8) | blue;
+ m_brightness = brightness;
+ m_delay = delay;
+ }
+
+ public LEDConfig(String command, int RGB, int brightness, int delay)
+ {
+ m_command = command;
+ m_RGB = RGB & 0x00FFFFFF;
+ m_brightness = brightness;
+ m_delay = delay;
+ }
+
+ String getCommmand() { return m_command; }
+ String getRGB() { return String.format("0x%06X", m_RGB); }
+ int getRedComponent() { return (m_RGB >> 16) & 0xFF; }
+ int getGreenComponent()
+ {
+ return (m_RGB >> 8) & 0xFF;
+ }
+ int getBlueComponent()
+ {
+ return (m_RGB) & 0xFF;
+ }
+ int getBrightness() {
+ return m_brightness;
+ }
+ int getDelay() {
+ return m_delay;
+ }
+
+ public String toString()
+ {
+ return "Command " + getCommmand() + " RGB [" + getRedComponent() + ", " + getGreenComponent() + ", " +
+ getBlueComponent() + "] Brightness " + getBrightness() + " Delay " + getDelay();
+ }
+}
diff --git a/app/src/main/java/es/jmrs/pablossmartlight/MainActivity.java b/app/src/main/java/es/jmrs/pablossmartlight/MainActivity.java
new file mode 100644
index 0000000..bf94e0d
--- /dev/null
+++ b/app/src/main/java/es/jmrs/pablossmartlight/MainActivity.java
@@ -0,0 +1,203 @@
+package es.jmrs.pablossmartlight;
+
+import android.support.v7.app.AppCompatActivity;
+import android.support.v7.widget.Toolbar;
+
+import android.support.v4.app.Fragment;
+import android.support.v4.app.FragmentManager;
+import android.support.v4.app.FragmentPagerAdapter;
+import android.support.v4.view.ViewPager;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.view.View;
+import android.view.ViewGroup;
+
+import android.widget.Button;
+import android.widget.TextView;
+
+import com.larswerkman.holocolorpicker.ColorPicker;
+import com.larswerkman.holocolorpicker.SaturationBar;
+import com.larswerkman.holocolorpicker.ValueBar;
+
+import layout.ColorsFragment;
+
+public class MainActivity extends AppCompatActivity {
+ private TextView text;
+ /**
+ * The {@link android.support.v4.view.PagerAdapter} that will provide
+ * fragments for each of the sections. We use a
+ * {@link FragmentPagerAdapter} derivative, which will keep every
+ * loaded fragment in memory. If this becomes too memory intensive, it
+ * may be best to switch to a
+ * {@link android.support.v4.app.FragmentStatePagerAdapter}.
+ */
+ private SectionsPagerAdapter mSectionsPagerAdapter;
+
+ /**
+ * The {@link ViewPager} that will host the section contents.
+ */
+ private ViewPager mViewPager;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_main);
+
+ Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
+ setSupportActionBar(toolbar);
+ // Create the adapter that will return a fragment for each of the three
+ // primary sections of the activity.
+ mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
+
+ // Set up the ViewPager with the sections adapter.
+ mViewPager = (ViewPager) findViewById(R.id.container);
+ mViewPager.setAdapter(mSectionsPagerAdapter);
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ // Inflate the menu; this adds items to the action bar if it is present.
+ getMenuInflater().inflate(R.menu.menu_main, menu);
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ // Handle action bar item clicks here. The action bar will
+ // automatically handle clicks on the Home/Up button, so long
+ // as you specify a parent activity in AndroidManifest.xml.
+ int id = item.getItemId();
+
+ //noinspection SimplifiableIfStatement
+ if (id == R.id.action_settings) {
+ return true;
+ }
+
+ return super.onOptionsItemSelected(item);
+ }
+
+ /**
+ * A placeholder fragment containing a simple view.
+ */
+ public static class PlaceholderFragment extends Fragment implements ColorPicker.OnColorChangedListener {
+
+ /**
+ * The fragment argument representing the section number for this
+ * fragment.
+ */
+ private static final String ARG_SECTION_NUMBER = "section_number";
+
+ private View m_rootView = null;
+ private ColorPicker m_colorPicker;
+ private SaturationBar m_saturationBar;
+ private ValueBar m_valueBar;
+
+ private LEDConfig m_ledConfig;
+
+ @Override
+ public void onColorChanged(int color) {
+ m_ledConfig = new LEDConfig(PSLControl.COMMAND.STATIC, color, PSLControl.DEFAULT_BRIGHTNESS, 0);
+ }
+
+ public PlaceholderFragment() {
+ }
+
+ /**
+ * Returns a new instance of this fragment for the given section
+ * number.
+ */
+ public static PlaceholderFragment newInstance(int sectionNumber) {
+ PlaceholderFragment fragment = new PlaceholderFragment();
+ Bundle args = new Bundle();
+ args.putInt(ARG_SECTION_NUMBER, sectionNumber);
+ fragment.setArguments(args);
+ return fragment;
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+
+ m_rootView = inflater.inflate(R.layout.fragment_debug_and_test, container, false);
+
+ TextView textView = (TextView) m_rootView.findViewById(R.id.section_label);
+ textView.setText(getString(R.string.section_format, getArguments().getInt(ARG_SECTION_NUMBER)));
+
+ m_colorPicker = (ColorPicker) m_rootView.findViewById(R.id.colorPicker);
+ m_colorPicker.setOnColorChangedListener(this);
+
+ m_saturationBar = (SaturationBar) m_rootView.findViewById(R.id.saturationBar);
+ m_valueBar = (ValueBar) m_rootView.findViewById(R.id.valueBar);
+
+ m_colorPicker.addSaturationBar(m_saturationBar);
+ m_colorPicker.addValueBar(m_valueBar);
+
+ Button button = (Button) m_rootView.findViewById(R.id.buttonChangeColor);
+ final TextView statusTextView = (TextView) m_rootView.findViewById(R.id.led_status);
+ button.setOnClickListener(new View.OnClickListener() {
+
+ @Override
+ public void onClick(View v) {
+ m_colorPicker.setOldCenterColor(m_colorPicker.getColor());
+ m_ledConfig = new LEDConfig(PSLControl.COMMAND.STATIC, m_colorPicker.getColor(), PSLControl.DEFAULT_BRIGHTNESS, 0);
+ //statusTextView.setText(m_ledConfig.toString());
+ //new CheckLEDsStatus().execute("http://192.168.1.10:4567/leds");
+ new PSLControl.SetLEDsConfig().execute(m_ledConfig);
+ }
+ });
+
+ return m_rootView;
+ }
+ }
+
+ /**
+ * A {@link FragmentPagerAdapter} that returns a fragment corresponding to
+ * one of the sections/tabs/pages.
+ */
+ public class SectionsPagerAdapter extends FragmentPagerAdapter {
+
+ public SectionsPagerAdapter(FragmentManager fm) {
+ super(fm);
+ }
+
+ @Override
+ public Fragment getItem(int position) {
+ // getItem is called to instantiate the fragment for the given page.
+ // Return a PlaceholderFragment (defined as a static inner class below).
+ Log.d("Tag selected", ""+position);
+
+ switch (position) {
+ case 0:
+ return ColorsFragment.newInstance("","");
+ case 1:
+ return SensorsFragment.newInstance("", "");
+ default:
+ break;
+ }
+
+ return PlaceholderFragment.newInstance(position + 1);
+ }
+
+ @Override
+ public int getCount() {
+ // Show 3 total pages.
+ return 3;
+ }
+
+ @Override
+ public CharSequence getPageTitle(int position) {
+ switch (position) {
+ case 0:
+ return "Color selection and effects";
+ case 1:
+ return "Sensors";
+ case 2:
+ return "Debug and testing";
+ }
+ return null;
+ }
+ }
+}
diff --git a/app/src/main/java/es/jmrs/pablossmartlight/PSLControl.java b/app/src/main/java/es/jmrs/pablossmartlight/PSLControl.java
new file mode 100644
index 0000000..e69982b
--- /dev/null
+++ b/app/src/main/java/es/jmrs/pablossmartlight/PSLControl.java
@@ -0,0 +1,208 @@
+package es.jmrs.pablossmartlight;
+
+import android.content.Context;
+import android.os.AsyncTask;
+import android.util.Log;
+import android.view.View;
+import android.widget.TextView;
+
+import org.apache.http.HttpResponse;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPut;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.HttpClientBuilder;
+import org.apache.http.util.EntityUtils;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import java.io.IOException;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+
+public class PSLControl {
+
+ private static final String CONTROL_IP = "192.168.1.17";
+ private static final String CONTROL_PORT = "4567";
+ private static final String LEDS_URL = "/leds";
+ private static final String SENSORS_URL = "/sensors";
+
+ public static final int DEFAULT_BRIGHTNESS = 100;
+
+ public static final class COMMAND
+ {
+ public static final String STATIC = "/color";
+ public static final String CHASE = "/chaser";
+ public static final String RANDOM = "/random";
+ public static final String RANGE = "/range";
+ }
+
+ public static final class CHASER_DELAY
+ {
+ public static final int VERY_SLOW = 150;
+ public static final int SLOW = 100;
+ public static final int NORMAL = 50;
+ }
+ public static final class RANDOM_DELAY
+ {
+ public static final int VERY_SLOW = 1500;
+ public static final int SLOW = 1000;
+ public static final int NORMAL = 500;
+ }
+ public static final class BRIGHTNESS
+ {
+ public static final int VERY_LOW = 15;
+ public static final int LOW = 25;
+ public static final int NORMAL = 50;
+ }
+
+ public static class SetLEDsConfig extends AsyncTask<LEDConfig, Void, Integer> {
+
+ private static String URL = "http://" + CONTROL_IP + ":" + CONTROL_PORT + LEDS_URL;
+
+ protected Integer doInBackground(LEDConfig... params) {
+
+ HttpClient client = HttpClientBuilder.create().build();
+
+ LEDConfig ledConfig = params[0];
+
+ HttpPut putRequest = new HttpPut(URL + ledConfig.getCommmand());
+ putRequest.addHeader("Content-Type", "application/json");
+ putRequest.addHeader("Accept", "application/json");
+
+ JSONObject putArguments = new JSONObject();
+ try {
+ putArguments.put("RGB", ledConfig.getRGB());
+ putArguments.put("brightness", ledConfig.getBrightness());
+ putArguments.put("delay", ledConfig.getDelay());
+
+ StringEntity entity = new StringEntity(putArguments.toString());
+ putRequest.setEntity(entity);
+
+ return client.execute(putRequest).getStatusLine().getStatusCode();
+ } catch (IOException e) {
+ e.printStackTrace();
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ return -1;
+ }
+
+ }
+
+ public static class GetSensorsInformation extends AsyncTask<Void, Void, SensorsInformation> {
+
+ private static String URL = "http://" + CONTROL_IP + ":" + CONTROL_PORT + SENSORS_URL;
+
+ private Context m_context;
+ private View m_rootView;
+
+ public GetSensorsInformation (Context context, View rootView)
+ {
+ m_context = context;
+ m_rootView = rootView;
+ }
+
+ @Override
+ protected SensorsInformation doInBackground(Void... params) {
+
+ HttpClient client = HttpClientBuilder.create().build();
+ HttpGet getRequest = new HttpGet(URL);
+
+ try {
+ HttpResponse response = client.execute(getRequest);
+ String information = EntityUtils.toString(response.getEntity());
+
+ JSONObject jsonInformation = new JSONObject(information);
+
+ String infoField = jsonInformation.getString(SensorsInformation.JSON_TAG.DHT_VALID);
+ Boolean dhtValid = Boolean.parseBoolean(infoField);
+
+ float temperature = 0, humidity = 0, pressure = 0, bmpTemperature = 0;
+
+ Log.d("response", jsonInformation.toString());
+ if (dhtValid) {
+ infoField = jsonInformation.getString(SensorsInformation.JSON_TAG.TEMPERATURE);
+ temperature = Float.parseFloat(infoField) / SensorsInformation.FACTOR;
+ infoField = jsonInformation.getString(SensorsInformation.JSON_TAG.HUMIDITY);
+ humidity = Float.parseFloat(infoField) / SensorsInformation.FACTOR;
+ }
+
+ infoField = jsonInformation.getString(SensorsInformation.JSON_TAG.BMP_VALID);
+ Boolean bmpValid = Boolean.parseBoolean(infoField);
+ if (bmpValid) {
+ infoField = jsonInformation.getString(SensorsInformation.JSON_TAG.PRESSURE);
+ pressure = Float.parseFloat(infoField) / SensorsInformation.FACTOR;
+ infoField = jsonInformation.getString(SensorsInformation.JSON_TAG.BMT_TEMPERATURE);
+ bmpTemperature = Float.parseFloat(infoField) / SensorsInformation.FACTOR;
+ }
+
+ return new SensorsInformation(dhtValid, temperature, humidity, bmpValid, pressure, bmpTemperature);
+
+ } catch (IOException e) {
+ e.printStackTrace();
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+
+ return new SensorsInformation();
+ }
+
+ @Override
+ protected void onPostExecute(SensorsInformation info)
+ {
+ String failure = "Failed to retrieve information: ";
+ TextView textView;
+ String timeStamp = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(Calendar.getInstance().getTime());
+
+ if (info.IsDhtValid()) {
+ textView = (TextView) m_rootView.findViewById(R.id.textViewTemperature);
+ textView.setText(String.format("Temperature: %.2f °C", info.getTemperature()));
+ textView = (TextView) m_rootView.findViewById(R.id.textViewHumidity);
+ textView.setText(String.format("Humidity: %.2f %%", info.getHumidity()));
+ }
+ else {
+ failure += "Temp/Humid ";
+ }
+
+ if (info.IsBmpValid()) {
+
+ textView = (TextView) m_rootView.findViewById(R.id.textViewPressure);
+ textView.setText(String.format("Pressure: %.2f hPa", info.getPressure()));
+ textView = (TextView) m_rootView.findViewById(R.id.textViewBmpTemperature);
+ textView.setText(String.format("Internal temperature: %.2f °C", info.getBmpTemperature()));
+ }
+ else {
+ failure += "Press";
+ }
+
+ textView = (TextView) m_rootView.findViewById(R.id.textViewStatus);
+
+ if (info.IsDhtValid() && info.IsBmpValid()) {
+ textView.setText("Updated at " + timeStamp);
+ }
+ else
+ {
+ textView.setText(failure);
+ }
+
+ int fakeColor = SensorsInformation.MAX_TEMPERATURE << 16;
+ fakeColor = fakeColor | ((int)Math.round(info.getTemperature()) << 8);
+ fakeColor = fakeColor | SensorsInformation.MIN_TEMPERATURE;
+ new PSLControl.SetLEDsConfig().execute(new LEDConfig(PSLControl.COMMAND.RANGE, fakeColor, 100, 0));
+
+
+ try {
+ Thread.sleep(5000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+
+ fakeColor = SensorsInformation.MIN_HUMIDITY << 16;
+ fakeColor = fakeColor | ((int)Math.round(info.getHumidity()) << 8);
+ fakeColor = fakeColor | SensorsInformation.MAX_HUMIDITY;
+ new PSLControl.SetLEDsConfig().execute(new LEDConfig(PSLControl.COMMAND.RANGE, fakeColor, 100, 0));
+ }
+ }
+
+}
diff --git a/app/src/main/java/es/jmrs/pablossmartlight/SensorsFragment.java b/app/src/main/java/es/jmrs/pablossmartlight/SensorsFragment.java
new file mode 100644
index 0000000..bb882ba
--- /dev/null
+++ b/app/src/main/java/es/jmrs/pablossmartlight/SensorsFragment.java
@@ -0,0 +1,113 @@
+package es.jmrs.pablossmartlight;
+
+import android.net.Uri;
+import android.os.Bundle;
+import android.support.v4.app.Fragment;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Button;
+import android.widget.TextView;
+
+
+/**
+ * A simple {@link Fragment} subclass.
+ * Activities that contain this fragment must implement the
+ * {@link SensorsFragment.OnFragmentInteractionListener} interface
+ * to handle interaction events.
+ * Use the {@link SensorsFragment#newInstance} factory method to
+ * create an instance of this fragment.
+ *
+ */
+public class SensorsFragment extends Fragment {
+ // TODO: Rename parameter arguments, choose names that match
+ // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
+ private static final String ARG_PARAM1 = "param1";
+ private static final String ARG_PARAM2 = "param2";
+
+ // TODO: Rename and change types of parameters
+ private String mParam1;
+ private String mParam2;
+
+ private View m_fragmentView = null;
+
+ private OnFragmentInteractionListener mListener;
+
+ /**
+ * Use this factory method to create a new instance of
+ * this fragment using the provided parameters.
+ *
+ * @param param1 Parameter 1.
+ * @param param2 Parameter 2.
+ * @return A new instance of fragment SensorsFragment.
+ */
+ // TODO: Rename and change types and number of parameters
+ public static SensorsFragment newInstance(String param1, String param2) {
+ SensorsFragment fragment = new SensorsFragment();
+ Bundle args = new Bundle();
+ args.putString(ARG_PARAM1, param1);
+ args.putString(ARG_PARAM2, param2);
+ fragment.setArguments(args);
+ return fragment;
+ }
+ public SensorsFragment() {
+ // Required empty public constructor
+ }
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ if (getArguments() != null) {
+ mParam1 = getArguments().getString(ARG_PARAM1);
+ mParam2 = getArguments().getString(ARG_PARAM2);
+ }
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ // Inflate the layout for this fragment
+
+ m_fragmentView = inflater.inflate(R.layout.fragment_sensors, container, false);
+
+ Button m_retrieveButton = (Button) m_fragmentView.findViewById(R.id.buttonRetrieve);
+ m_retrieveButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ TextView status = (TextView) m_fragmentView.findViewById(R.id.textViewStatus);
+ status.setText("Retrieving information...");
+ new PSLControl.GetSensorsInformation(getActivity(), m_fragmentView).execute();
+ }
+ });
+
+ return m_fragmentView;
+ }
+
+ // TODO: Rename method, update argument and hook method into UI event
+ public void onButtonPressed(Uri uri) {
+ if (mListener != null) {
+ mListener.onFragmentInteraction(uri);
+ }
+ }
+