Floppy-currentcost 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Floppy-currentcost
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Smith
@@ -1,343 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- dir = File.dirname(__FILE__) + '/../lib'
4
- $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
5
-
6
- require 'gtk2'
7
- require 'rubygems'
8
- require 'currentcost'
9
- require 'optparse'
10
-
11
- # Command-line options
12
- options = {:port => '/dev/ttyS0'}
13
- OptionParser.new do |opts|
14
- opts.on("-p", "--serial_port SERIAL_PORT", "serial port") do |p|
15
- options[:port] = p
16
- end
17
- end.parse!
18
-
19
-
20
- # Pixbuf images - generated from PNG files with gdk-pixbuf-csource --raw
21
- GREY =
22
- # Pixbuf magic (0x47646b50)
23
- "GdkP" <<
24
- # length: header (24) + pixel_data (1024)
25
- "\0\0\4\30" <<
26
- # pixdata_type (0x1010002)
27
- "\1\1\0\2" <<
28
- # rowstride (64)
29
- "\0\0\0@" <<
30
- # width (16)
31
- "\0\0\0\20" <<
32
- # height (16)
33
- "\0\0\0\20" <<
34
- # pixel_data:
35
- "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\351\352\351J\360\360\360\262\353\353" <<
36
- "\353\371\347\347\347\377\337\337\337\377\322\323\322\371\310\310\310" <<
37
- "\262\267\267\267J\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\336" <<
38
- "\336\336\30\366\366\366\270\371\370\370\377\360\360\360\377\350\350\347" <<
39
- "\377\337\337\337\377\327\327\327\377\316\317\317\377\306\306\306\377" <<
40
- "\275\275\276\377\260\257\257\270\232\232\232\30\0\0\0\0\0\0\0\0\0\0\0" <<
41
- "\0\336\336\336\30\371\370\370\335\370\370\370\377\365\365\365\377\347" <<
42
- "\347\350\377\337\337\337\377\327\327\327\377\317\316\316\377\306\306" <<
43
- "\306\377\275\275\276\377\265\265\265\377\255\255\255\377\241\241\241" <<
44
- "\335\213\214\214\30\0\0\0\0\0\0\0\0\366\366\366\270\370\370\370\377\366" <<
45
- "\366\366\377\377\377\377\377\355\355\355\377\327\326\327\377\316\316" <<
46
- "\316\377\306\306\306\377\275\275\275\377\265\265\265\377\255\255\254" <<
47
- "\377\244\244\244\377\234\234\234\377\217\217\217\270\0\0\0\0\351\350" <<
48
- "\350J\370\370\370\377\360\360\360\377\374\374\374\377\377\377\377\377" <<
49
- "\365\366\366\377\316\316\316\377\306\306\306\377\275\275\275\377\265" <<
50
- "\265\265\377\255\255\255\377\244\244\244\377\234\234\234\377\223\223" <<
51
- "\223\377\213\213\213\377}||J\357\357\357\262\360\360\360\377\354\354" <<
52
- "\354\377\377\377\377\377\377\377\377\377\377\377\377\377\314\314\314" <<
53
- "\377\275\275\275\377\275\275\275\377\276\276\276\377\244\244\244\377" <<
54
- "\234\233\233\377\223\223\223\377\213\213\213\377\202\202\203\377www\262" <<
55
- "\352\352\352\371\347\347\347\377\364\364\364\377\377\377\377\377\377" <<
56
- "\377\377\377\377\377\377\377\332\332\332\377\265\265\265\377\354\354" <<
57
- "\354\377\377\377\377\377\275\274\275\377\267\267\267\377\261\261\261" <<
58
- "\377\254\253\253\377\246\246\246\377\237\237\237\373\347\347\347\377" <<
59
- "\342\342\342\377\377\377\377\377\377\377\377\377\377\377\377\377\377" <<
60
- "\377\377\377\356\356\356\377\276\276\277\377\377\377\377\377\377\377" <<
61
- "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" <<
62
- "\377\377\377\377\377\377\377\377\377\336\336\336\377\354\354\355\377" <<
63
- "\377\377\377\377\377\377\377\377\323\323\323\377\377\377\377\377\377" <<
64
- "\377\377\377\340\340\340\377\377\377\377\377\377\377\377\377\377\377" <<
65
- "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" <<
66
- "\377\377\377\377\377\325\325\325\372\371\371\371\377\377\377\377\377" <<
67
- "\341\341\341\377\265\265\265\377\377\377\377\377\377\377\377\377\377" <<
68
- "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\322\322" <<
69
- "\322\377qqr\377iii\377``a\377UUU\371\335\335\335\314\377\377\377\377" <<
70
- "\377\377\377\377\275\275\275\377\254\254\254\377\352\352\352\377\377" <<
71
- "\377\377\377\377\377\377\377\377\377\377\377\271\271\271\377\322\322" <<
72
- "\322\377\200\200\200\377iih\377`aa\377XXX\377NNN\262\343\343\343\206" <<
73
- "\377\377\377\377\356\356\356\377\254\254\254\377\244\243\243\377\274" <<
74
- "\274\274\377\377\377\377\377\377\377\377\377\343\343\343\377yyy\377q" <<
75
- "qq\377iii\377```\377XXX\377OOO\377GGGJ\377\377\377\34\351\351\351\347" <<
76
- "\265\265\265\377\243\244\244\377\233\233\233\377\223\223\223\377\377" <<
77
- "\377\377\377\377\377\377\377\246\246\245\377qqq\377iii\377```\377XXX" <<
78
- "\377OOO\377EEE\270\0\0\0\0\0\0\0\0\224\223\224\30\237\237\237\335\233" <<
79
- "\233\233\377\223\223\223\377\212\212\212\377\307\307\307\377\360\360" <<
80
- "\360\377qqq\377ihh\377```\377XWX\377OPO\377EEE\335=>=\30\0\0\0\0\0\0" <<
81
- "\0\0\0\0\0\0\204\205\205\30\214\215\214\270\212\212\212\377\201\202\202" <<
82
- "\377yyy\377qqq\377hhh\377```\377XXX\377OOO\377EEE\270===\30\0\0\0\0\0" <<
83
- "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0yxyJuuu\262lll\371ggg\377^_^\377" <<
84
- "TTS\371MMM\262EFFJ\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
85
-
86
- GREEN =
87
- # Pixbuf magic (0x47646b50)
88
- "GdkP" <<
89
- # length: header (24) + pixel_data (1024)
90
- "\0\0\4\30" <<
91
- # pixdata_type (0x1010002)
92
- "\1\1\0\2" <<
93
- # rowstride (64)
94
- "\0\0\0@" <<
95
- # width (16)
96
- "\0\0\0\20" <<
97
- # height (16)
98
- "\0\0\0\20" <<
99
- # pixel_data:
100
- "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\303\351\304J\317\356\320\262\302\351" <<
101
- "\303\371\270\346\271\377\243\335\244\377\206\321\210\371n\306p\262M\265" <<
102
- "QJ\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\242\335\243\30\342" <<
103
- "\365\343\270\346\367\347\377\317\357\320\377\270\346\272\377\244\336" <<
104
- "\246\377\217\325\221\377}\315\177\377j\305m\377Y\274\\\377@\256C\270" <<
105
- "\36\231\"\30\0\0\0\0\0\0\0\0\0\0\0\0\242\335\243\30\351\367\351\335\347" <<
106
- "\367\347\377\337\364\337\377\270\346\272\377\244\336\245\377\217\325" <<
107
- "\221\377}\315\177\377j\305m\377Y\274\\\377I\264L\377:\253>\377(\237+" <<
108
- "\335\14\213\20\30\0\0\0\0\0\0\0\0\341\364\342\270\346\367\347\377\344" <<
109
- "\366\344\377\377\377\377\377\314\354\315\377\216\325\221\377|\315~\377" <<
110
- "j\305m\377Y\274\\\377I\263L\377:\253>\377,\2430\377\40\232$\377\17\215" <<
111
- "\23\270\0\0\0\0\277\347\300J\345\366\346\377\317\356\320\377\367\374" <<
112
- "\367\377\377\377\377\377\345\365\346\377|\315~\377j\304m\377Y\274\\\377" <<
113
- "I\264L\377;\253>\377,\2430\377\40\232$\377\24\222\30\377\12\211\16\377" <<
114
- "\0u\3J\315\355\317\262\317\356\320\377\307\353\310\377\377\377\377\377" <<
115
- "\377\377\377\377\377\377\377\377z\312}\377Y\274\\\377\\\273_\377f\275" <<
116
- "i\377,\2420\377\40\232#\377\24\222\30\377\12\211\16\377\2\200\5\377\0" <<
117
- "m\3\262\277\350\300\371\270\346\271\377\340\363\341\377\377\377\377\377" <<
118
- "\377\377\377\377\377\377\377\377\242\331\244\377H\263L\377\322\354\323" <<
119
- "\377\377\377\377\377j\273m\377b\265e\377[\260^\377V\252Y\377U\240W\377" <<
120
- "V\223X\373\266\345\267\377\254\340\255\377\377\377\377\377\377\377\377" <<
121
- "\377\377\377\377\377\377\377\377\377\325\356\326\377f\275h\377\377\377" <<
122
- "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" <<
123
- "\377\377\377\377\377\377\377\377\377\377\377\377\377\240\334\242\377" <<
124
- "\314\354\316\377\377\377\377\377\377\377\377\377\217\322\221\377\377" <<
125
- "\377\377\377\377\377\377\377\270\340\271\377\377\377\377\377\377\377" <<
126
- "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" <<
127
- "\377\377\377\377\377\377\377\377\377\217\324\221\372\360\371\360\377" <<
128
- "\377\377\377\377\264\341\266\377H\263L\377\377\377\377\377\377\377\377" <<
129
- "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" <<
130
- "\252\317\253\377\0b\3\377\0S\2\377\0F\2\377\0""7\1\371\250\334\251\314" <<
131
- "\377\377\377\377\377\377\377\377\\\273_\3779\253=\377\317\352\320\377" <<
132
- "\377\377\377\377\377\377\377\377\377\377\377\377r\270s\377\252\317\253" <<
133
- "\377\34s\36\377\0S\2\377\0G\2\377\0:\1\377\0.\1\262\274\342\275\206\377" <<
134
- "\377\377\377\326\356\326\3779\252<\377+\242/\377i\273l\377\377\377\377" <<
135
- "\377\377\377\377\377\306\342\307\377\0p\3\377\0a\3\377\0S\2\377\0F\2" <<
136
- "\377\0:\1\377\0/\1\377\0'\1J\377\377\377\34\313\350\314\347N\264R\377" <<
137
- ",\2420\377\37\231#\377\24\221\30\377\377\377\377\377\377\377\377\377" <<
138
- "U\240W\377\0a\3\377\0S\2\377\0F\2\377\0:\1\377\0/\1\377\0$\1\270\0\0" <<
139
- "\0\0\0\0\0\0\25\222\31\30%\235)\335\37\231#\377\24\221\30\377\11\211" <<
140
- "\15\377\216\306\220\377\343\357\343\377\0a\3\377\0S\2\377\0F\2\377\0" <<
141
- ":\1\377\0/\1\377\0$\1\335\0\34\0\30\0\0\0\0\0\0\0\0\0\0\0\0\4\204\10" <<
142
- "\30\16\211\22\270\11\210\15\377\1\177\5\377\0p\3\377\0a\3\377\0S\2\377" <<
143
- "\0F\2\377\0:\1\377\0/\1\377\0#\1\270\0\33\0\30\0\0\0\0\0\0\0\0\0\0\0" <<
144
- "\0\0\0\0\0\0\0\0\0\0\0\0\0\0n\3J\0i\3\262\0Y\3\371\0Q\2\377\0C\2\377" <<
145
- "\0""6\1\371\0-\1\262\0$\1J\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
146
-
147
- RED =
148
- # Pixbuf magic (0x47646b50)
149
- "GdkP" <<
150
- # length: header (24) + pixel_data (1024)
151
- "\0\0\4\30" <<
152
- # pixdata_type (0x1010002)
153
- "\1\1\0\2" <<
154
- # rowstride (64)
155
- "\0\0\0@" <<
156
- # width (16)
157
- "\0\0\0\20" <<
158
- # height (16)
159
- "\0\0\0\20" <<
160
- # pixel_data:
161
- "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\351\303\303J\356\317\317\262\351\302" <<
162
- "\302\371\346\270\270\377\335\243\243\377\321\206\206\371\306nn\262\265" <<
163
- "MMJ\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\335\242\242\30\365" <<
164
- "\342\342\270\367\346\346\377\357\317\317\377\346\270\270\377\336\244" <<
165
- "\244\377\325\217\217\377\315}}\377\305jj\377\274YY\377\256@@\270\231" <<
166
- "\36\36\30\0\0\0\0\0\0\0\0\0\0\0\0\335\242\242\30\367\351\351\335\367" <<
167
- "\347\347\377\364\337\337\377\346\270\270\377\336\244\244\377\325\217" <<
168
- "\217\377\315}}\377\305jj\377\274YY\377\264II\377\253::\377\237((\335" <<
169
- "\213\14\14\30\0\0\0\0\0\0\0\0\364\341\341\270\367\346\346\377\366\344" <<
170
- "\344\377\377\377\377\377\354\314\314\377\325\216\216\377\315||\377\305" <<
171
- "jj\377\274YY\377\263II\377\253::\377\243,,\377\232\40\40\377\215\17\17" <<
172
- "\270\0\0\0\0\347\277\277J\366\345\345\377\356\317\317\377\374\367\367" <<
173
- "\377\377\377\377\377\365\345\345\377\315||\377\304jj\377\274YY\377\264" <<
174
- "II\377\253;;\377\243,,\377\232\40\40\377\222\24\24\377\211\12\12\377" <<
175
- "u\0\0J\355\315\315\262\356\317\317\377\353\307\307\377\377\377\377\377" <<
176
- "\377\377\377\377\377\377\377\377\312zz\377\274YY\377\273\\\\\377\275" <<
177
- "ff\377\242,,\377\232\40\40\377\222\24\24\377\211\12\12\377\200\2\2\377" <<
178
- "m\0\0\262\350\277\277\371\346\270\270\377\363\340\340\377\377\377\377" <<
179
- "\377\377\377\377\377\377\377\377\377\331\242\242\377\263HH\377\354\322" <<
180
- "\322\377\377\377\377\377\273jj\377\265bb\377\260[[\377\252VV\377\240" <<
181
- "UU\377\223VV\373\345\266\266\377\340\254\254\377\377\377\377\377\377" <<
182
- "\377\377\377\377\377\377\377\377\377\377\377\356\325\325\377\275ff\377" <<
183
- "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" <<
184
- "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\334\240" <<
185
- "\240\377\354\314\314\377\377\377\377\377\377\377\377\377\322\217\217" <<
186
- "\377\377\377\377\377\377\377\377\377\340\270\270\377\377\377\377\377" <<
187
- "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" <<
188
- "\377\377\377\377\377\377\377\377\377\377\377\324\217\217\372\371\360" <<
189
- "\360\377\377\377\377\377\341\264\264\377\263HH\377\377\377\377\377\377" <<
190
- "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" <<
191
- "\377\377\317\252\252\377b\0\0\377S\0\0\377F\0\0\3777\0\0\371\334\250" <<
192
- "\250\314\377\377\377\377\377\377\377\377\273\\\\\377\25399\377\352\317" <<
193
- "\317\377\377\377\377\377\377\377\377\377\377\377\377\377\270rr\377\317" <<
194
- "\252\252\377s\34\34\377S\0\0\377G\0\0\377:\0\0\377.\0\0\262\342\274\274" <<
195
- "\206\377\377\377\377\356\326\326\377\25299\377\242++\377\273ii\377\377" <<
196
- "\377\377\377\377\377\377\377\342\306\306\377p\0\0\377a\0\0\377S\0\0\377" <<
197
- "F\0\0\377:\0\0\377/\0\0\377'\0\0J\377\377\377\34\350\313\313\347\264" <<
198
- "NN\377\242,,\377\231\37\37\377\221\24\24\377\377\377\377\377\377\377" <<
199
- "\377\377\240UU\377a\0\0\377S\0\0\377F\0\0\377:\0\0\377/\0\0\377$\0\0" <<
200
- "\270\0\0\0\0\0\0\0\0\222\25\25\30\235%%\335\231\37\37\377\221\24\24\377" <<
201
- "\211\11\11\377\306\216\216\377\357\343\343\377a\0\0\377S\0\0\377F\0\0" <<
202
- "\377:\0\0\377/\0\0\377$\0\0\335\34\0\0\30\0\0\0\0\0\0\0\0\0\0\0\0\204" <<
203
- "\4\4\30\211\16\16\270\210\11\11\377\177\1\1\377p\0\0\377a\0\0\377S\0" <<
204
- "\0\377F\0\0\377:\0\0\377/\0\0\377#\0\0\270\33\0\0\30\0\0\0\0\0\0\0\0" <<
205
- "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0n\0\0Ji\0\0\262Y\0\0\371Q\0\0\377C\0" <<
206
- "\0\3776\0\0\371-\0\0\262$\0\0J\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
207
-
208
- YELLOW =
209
- # Pixbuf magic (0x47646b50)
210
- "GdkP" <<
211
- # length: header (24) + pixel_data (1024)
212
- "\0\0\4\30" <<
213
- # pixdata_type (0x1010002)
214
- "\1\1\0\2" <<
215
- # rowstride (64)
216
- "\0\0\0@" <<
217
- # width (16)
218
- "\0\0\0\20" <<
219
- # height (16)
220
- "\0\0\0\20" <<
221
- # pixel_data:
222
- "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\351\346\303J\356\354\317\262\351\346" <<
223
- "\302\371\346\342\270\377\335\331\243\377\321\314\206\371\306\300n\262" <<
224
- "\265\256MJ\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\335\331\242" <<
225
- "\30\365\363\342\270\367\365\346\377\357\354\317\377\346\343\270\377\336" <<
226
- "\332\244\377\325\320\217\377\315\307}\377\305\277j\377\274\265Y\377\256" <<
227
- "\247@\270\231\221\36\30\0\0\0\0\0\0\0\0\0\0\0\0\335\331\242\30\367\366" <<
228
- "\351\335\367\365\347\377\364\362\337\377\346\343\270\377\336\332\244" <<
229
- "\377\325\320\217\377\315\307}\377\305\277j\377\274\265Y\377\264\254I" <<
230
- "\377\253\243:\377\237\227(\335\213\202\14\30\0\0\0\0\0\0\0\0\364\363" <<
231
- "\341\270\367\365\346\377\366\364\344\377\377\377\377\377\354\352\314" <<
232
- "\377\325\320\216\377\315\307|\377\305\276j\377\274\265Y\377\263\254I" <<
233
- "\377\253\243:\377\243\233,\377\232\222\40\377\215\205\17\270\0\0\0\0" <<
234
- "\347\344\277J\366\365\345\377\356\354\317\377\374\373\367\377\377\377" <<
235
- "\377\377\365\364\345\377\315\307|\377\304\276j\377\274\265Y\377\264\254" <<
236
- "I\377\253\243;\377\243\233,\377\232\222\40\377\222\211\24\377\211\200" <<
237
- "\12\377un\0J\355\353\315\262\356\354\317\377\353\350\307\377\377\377" <<
238
- "\377\377\377\377\377\377\377\377\377\377\312\305z\377\274\265Y\377\273" <<
239
- "\265\\\377\275\267f\377\242\232,\377\232\222\40\377\222\211\24\377\211" <<
240
- "\200\12\377\200w\2\377mf\0\262\350\345\277\371\346\342\270\377\363\362" <<
241
- "\340\377\377\377\377\377\377\377\377\377\377\377\377\377\331\325\242" <<
242
- "\377\263\254H\377\354\352\322\377\377\377\377\377\273\266j\377\265\257" <<
243
- "b\377\260\252[\377\252\244V\377\240\233U\377\223\217V\373\345\341\266" <<
244
- "\377\340\335\254\377\377\377\377\377\377\377\377\377\377\377\377\377" <<
245
- "\377\377\377\377\356\354\325\377\275\267f\377\377\377\377\377\377\377" <<
246
- "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" <<
247
- "\377\377\377\377\377\377\377\377\377\334\330\240\377\354\352\314\377" <<
248
- "\377\377\377\377\377\377\377\377\322\315\217\377\377\377\377\377\377" <<
249
- "\377\377\377\340\335\270\377\377\377\377\377\377\377\377\377\377\377" <<
250
- "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" <<
251
- "\377\377\377\377\377\324\317\217\372\371\370\360\377\377\377\377\377" <<
252
- "\341\336\264\377\263\254H\377\377\377\377\377\377\377\377\377\377\377" <<
253
- "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\317\315\252" <<
254
- "\377b[\0\377SN\0\377FB\0\37773\0\371\334\331\250\314\377\377\377\377" <<
255
- "\377\377\377\377\273\265\\\377\253\2439\377\352\350\317\377\377\377\377" <<
256
- "\377\377\377\377\377\377\377\377\377\270\263r\377\317\315\252\377sm\34" <<
257
- "\377SM\0\377GB\0\377:6\0\377.*\0\262\342\337\274\206\377\377\377\377" <<
258
- "\356\354\326\377\252\2429\377\242\232+\377\273\266i\377\377\377\377\377" <<
259
- "\377\377\377\377\342\340\306\377pi\0\377a[\0\377SN\0\377FA\0\377:6\0" <<
260
- "\377/,\0\377'$\0J\377\377\377\34\350\346\313\347\264\255N\377\242\232" <<
261
- ",\377\231\221\37\377\221\210\24\377\377\377\377\377\377\377\377\377\240" <<
262
- "\233U\377a[\0\377SN\0\377FA\0\377:6\0\377/,\0\377$!\0\270\0\0\0\0\0\0" <<
263
- "\0\0\222\211\25\30\235\225%\335\231\221\37\377\221\210\24\377\211\200" <<
264
- "\11\377\306\302\216\377\357\356\343\377a[\0\377SM\0\377FB\0\377:6\0\377" <<
265
- "/,\0\377$\"\0\335\34\32\0\30\0\0\0\0\0\0\0\0\0\0\0\0\204{\4\30\211\201" <<
266
- "\16\270\210\177\11\377\177w\1\377ph\0\377a[\0\377SM\0\377FA\0\377:6\0" <<
267
- "\377/,\0\377#!\0\270\33\31\0\30\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" <<
268
- "\0\0\0\0\0ng\0Jib\0\262YT\0\371QL\0\377C\77\0\37762\0\371-)\0\262$\"" <<
269
- "\0J\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
270
-
271
- $grey_pixbuf = Gdk::Pixbuf.new(GREY.unpack("C*"), true)
272
- $green_pixbuf = Gdk::Pixbuf.new(GREEN.unpack("C*"), true)
273
- $red_pixbuf = Gdk::Pixbuf.new(RED.unpack("C*"), true)
274
- $yellow_pixbuf = Gdk::Pixbuf.new(YELLOW.unpack("C*"), true)
275
-
276
- # build the UI
277
-
278
- $tray = Gtk::StatusIcon.new
279
- $tray.pixbuf = $grey_pixbuf
280
-
281
- $menu = Gtk::Menu.new
282
- about_item = Gtk::ImageMenuItem.new(Gtk::Stock::ABOUT)
283
- quit_item = Gtk::ImageMenuItem.new(Gtk::Stock::QUIT)
284
- $menu.append(about_item)
285
- $menu.append(Gtk::SeparatorMenuItem.new)
286
- $menu.append(quit_item)
287
- $menu.show_all
288
-
289
- about_item.signal_connect('activate') {
290
- about = Gtk::AboutDialog.new
291
- about.signal_connect('response') {
292
- about.destroy
293
- }
294
- about.name = 'CurrentCost Tray Monitor'
295
- about.version = '0.1'
296
- about.copyright = '© 2008 James Smith'
297
- about.comments = 'Heavily based on CCTrayRb: http://rubyforge.org/projects/cctrayrb/'
298
- about.license = 'MIT License - see http://github.com/Floppy/currentcost-ruby/tree/master/COPYING'
299
- about.website = 'http://github.com/Floppy/currentcost-ruby/wikis/currentcosttraymonitor'
300
- about.authors = ['James Smith - james@floppy.org.uk']
301
- about.show_all
302
- }
303
-
304
- quit_item.signal_connect('activate') {
305
- $meter.close
306
- Gtk.main_quit
307
- }
308
-
309
- $tray.signal_connect('popup_menu') { |icon, button, time|
310
- if button == 3 # right mouse button
311
- $menu.popup(nil, nil, button, time)
312
- end
313
- }
314
-
315
- # Meter observer
316
- class MeterObserver
317
- def update(reading)
318
- # Add all channels to get real figure
319
- watts = 0
320
- reading.channels.each { |c| watts += c[:watts] }
321
- # Change icon colour based on power usage
322
- case watts
323
- when 0..349
324
- $tray.pixbuf = $green_pixbuf
325
- when 350..999
326
- $tray.pixbuf = $yellow_pixbuf
327
- else
328
- $tray.pixbuf = $red_pixbuf
329
- end
330
- # Set tooltip
331
- $tray.tooltip = "#{watts} watts"
332
- rescue
333
- $tray.pixbuf = $grey_pixbuf
334
- end
335
- end
336
-
337
- # Create CurrentCost meter connection
338
- $meter = CurrentCost::Meter.new(options[:port])
339
- obs = MeterObserver.new
340
- $meter.add_observer(obs)
341
-
342
- # Go
343
- Gtk.main
data/examples/simple.rb DELETED
@@ -1,39 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- dir = File.dirname(__FILE__) + '/../lib'
4
- $LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
5
-
6
- require 'rubygems'
7
- require 'currentcost/meter'
8
-
9
- require 'optparse'
10
-
11
- # Command-line options
12
- options = {:port => '/dev/ttyS0'}
13
- OptionParser.new do |opts|
14
- opts.on("-p", "--serial_port SERIAL_PORT", "serial port") do |p|
15
- options[:port] = p
16
- end
17
- end.parse!
18
-
19
- # A simple observer class which will receive updates from the meter
20
- class SimpleObserver
21
- def update(reading)
22
- # Add all channels to get real figure
23
- watts = 0
24
- reading.channels.each { |c| watts += c[:watts] }
25
- # Print out measurement
26
- puts "New reading received: #{watts} W"
27
- end
28
- end
29
-
30
- # Create meter
31
- meter = CurrentCost::Meter.new(options[:port])
32
- # Create observer
33
- observer = SimpleObserver.new
34
- # Register observer with meter
35
- meter.add_observer(observer)
36
- # Wait a while, let some readings come in
37
- sleep(30)
38
- # Close the meter object to stop it receiving data
39
- meter.close
@@ -1,7 +0,0 @@
1
- module CurrentCost
2
-
3
- # Signifies an XML parsing error. Raised by CurrentCost::Reading.from_xml.
4
- class ParseError < Exception
5
- end
6
-
7
- end
@@ -1,81 +0,0 @@
1
- require 'currentcost/exceptions'
2
- require 'rexml/document'
3
-
4
- module CurrentCost
5
-
6
- class Reading
7
-
8
- # Creates a reading object from an XML string.
9
- # Raises CurrentCost::ParseError if the XML is malformed or missing
10
- # expected content.
11
- def self.from_xml(xml)
12
- # Parse XML
13
- doc = REXML::Document.new(xml)
14
- # Create reading object
15
- r = Reading.new
16
- # Extract basic data
17
- r.days_since_birth = REXML::XPath.first(doc, "/msg/date/dsb").text.to_i
18
- r.hour = REXML::XPath.first(doc, "/msg/date/hr").text.to_i
19
- r.minute = REXML::XPath.first(doc, "/msg/date/min").text.to_i
20
- r.second = REXML::XPath.first(doc, "/msg/date/sec").text.to_i
21
- r.name = REXML::XPath.first(doc, "/msg/src/name").text
22
- r.id = REXML::XPath.first(doc, "/msg/src/id").text
23
- r.type = REXML::XPath.first(doc, "/msg/src/type").text
24
- r.software_version = REXML::XPath.first(doc, "/msg/src/sver").text
25
- r.temperature = REXML::XPath.first(doc, "/msg/tmpr").text.to_f
26
- r.channels = []
27
- REXML::XPath.each(doc, "/msg/*/watts") do |node|
28
- r.channels << { :watts => node.text.to_i }
29
- end
30
- # Extract history data
31
- if REXML::XPath.first(doc, "/msg/hist")
32
- r.history = {}
33
- r.history[:hours] = []
34
- REXML::XPath.each(doc, "/msg/hist/hrs/*") do |node|
35
- r.history[:hours][node.name.slice(1,2).to_i] = node.text.to_f
36
- end
37
- r.history[:days] = []
38
- REXML::XPath.each(doc, "/msg/hist/days/*") do |node|
39
- r.history[:days][node.name.slice(1,2).to_i] = node.text.to_i
40
- end
41
- r.history[:months] = []
42
- REXML::XPath.each(doc, "/msg/hist/mths/*") do |node|
43
- r.history[:months][node.name.slice(1,2).to_i] = node.text.to_i
44
- end
45
- r.history[:years] = []
46
- REXML::XPath.each(doc, "/msg/hist/yrs/*") do |node|
47
- r.history[:years][node.name.slice(1,2).to_i] = node.text.to_i
48
- end
49
- end
50
- # Done
51
- return r
52
- rescue
53
- raise CurrentCost::ParseError.new("Couldn't parse XML data.")
54
- end
55
-
56
- # Number of days since the meter was turned on
57
- attr_accessor :days_since_birth
58
- # Current time - hour
59
- attr_accessor :hour
60
- # Current time - minute
61
- attr_accessor :minute
62
- # Current time - second
63
- attr_accessor :second
64
- # Name of the device - always "CC02".
65
- attr_accessor :name
66
- # ID number of the device
67
- attr_accessor :id
68
- # Type id of the device - "1" for a standard CurrentCost meter.
69
- attr_accessor :type
70
- # Version of the meter software
71
- attr_accessor :software_version
72
- # An array of channels. channels[x][:watts] contains the current power for that channel in watts. The figure shown on the meter is the sum of the wattage for all channels.
73
- attr_accessor :channels
74
- # Current temperature
75
- attr_accessor :temperature
76
- # Historical data, represented as a hash. There is a hash entry for days, weeks, months, and years. Each of these is an array of historical kWh data.
77
- attr_accessor :history
78
-
79
- end
80
-
81
- end
@@ -1,10 +0,0 @@
1
- module CurrentCost
2
-
3
- module VERSION #:nodoc:
4
- MAJOR = 0
5
- MINOR = 1
6
- TINY = 2
7
- STRING = [MAJOR, MINOR, TINY].join('.')
8
- end
9
-
10
- end