Floppy-currentcost 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,340 @@
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\0a\352aJ7\3607\262\5\353\5\371\0\347\0" <<
101
+ "\377\0\337\0\377\4\323\4\371.\310.\262L\267LJ\0\0\0\0\0\0\0\0\0\0\0\0" <<
102
+ "\0\0\0\0\0\0\0\0\0\0\0\0j\336j\30""5\3665\270\0\370\0\377\0\360\0\377" <<
103
+ "\0\350\0\377\0\337\0\377\0\327\0\377\0\317\0\377\0\306\0\377\0\275\0" <<
104
+ "\377&\257%\270I\232I\30\0\0\0\0\0\0\0\0\0\0\0\0j\336j\30\34\370\34\335" <<
105
+ "\0\370\0\377U\365U\377\0\347\0\377\0\337\0\377\0\327\0\377\0\316\0\377" <<
106
+ "\0\306\0\377\0\275\0\377\0\265\0\377\0\255\0\377\22\241\22\335B\214B" <<
107
+ "\30\0\0\0\0\0\0\0\0""5\3665\270\0\370\0\377q\366q\377\377\377\377\377" <<
108
+ "q\355q\377\0\326\0\377\0\316\0\377\0\306\0\377\0\275\0\377\0\265\0\377" <<
109
+ "\0\255\0\377\0\244\0\377\0\234\0\377\37\217\37\270\0\0\0\0a\350`J\0\370" <<
110
+ "\0\377\0\360\0\377\343\374\343\377\377\377\377\377\306\366\306\377\0" <<
111
+ "\316\0\377\0\306\0\377\0\275\0\377\0\265\0\377\0\255\0\377\0\244\0\377" <<
112
+ "\0\234\0\377\0\223\0\377\0\213\0\3774|3J7\3577\262\0\360\0\3779\3549" <<
113
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\34\314\34\377\0" <<
114
+ "\275\0\377\34\275\34\3779\2769\377\0\244\0\377\0\233\0\377\0\223\0\377" <<
115
+ "\0\213\0\377\0\202\0\377\33w\33\262\5\352\5\371\0\347\0\377\252\364\252" <<
116
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377q\332q\377\0\265" <<
117
+ "\0\377\306\354\306\377\377\377\377\377U\274U\377U\267U\377U\261U\377" <<
118
+ "U\253U\377U\246U\377W\237W\373\0\347\0\377\34\342\34\377\377\377\377" <<
119
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\306\356\306\377" <<
120
+ "9\2769\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" <<
121
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" <<
122
+ "\0\336\0\377\216\354\216\377\377\377\377\377\377\377\377\377U\323U\377" <<
123
+ "\377\377\377\377\377\377\377\377\252\340\252\377\377\377\377\377\377" <<
124
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" <<
125
+ "\377\377\377\377\377\377\377\377\377\377\40\325\40\372\343\371\343\377" <<
126
+ "\377\377\377\377\216\341\216\377\0\265\0\377\377\377\377\377\377\377" <<
127
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" <<
128
+ "\377\252\322\252\377\0q\0\377\0i\0\377\0`\0\377\2U\2\371\204\335\204" <<
129
+ "\314\377\377\377\377\377\377\377\377\34\275\34\377\0\254\0\377\306\352" <<
130
+ "\306\377\377\377\377\377\377\377\377\377\377\377\377\377q\271q\377\252" <<
131
+ "\322\252\377\34\200\34\377\0i\0\377\0a\0\377\0X\0\377\22N\22\262\274" <<
132
+ "\343\274\206\377\377\377\377\306\356\306\377\0\254\0\377\0\243\0\377" <<
133
+ "U\274U\377\377\377\377\377\377\377\377\377\306\343\306\377\0y\0\377\0" <<
134
+ "q\0\377\0i\0\377\0`\0\377\0X\0\377\0O\0\377\35G\35J\377\377\377\34\305" <<
135
+ "\351\305\347\34\265\34\377\0\244\0\377\0\233\0\377\0\223\0\377\377\377" <<
136
+ "\377\377\377\377\377\377U\246U\377\0q\0\377\0i\0\377\0`\0\377\0X\0\377" <<
137
+ "\0O\0\377\16E\16\270\0\0\0\0\0\0\0\0F\223F\30\22\237\22\335\0\233\0\377" <<
138
+ "\0\223\0\377\0\212\0\377\216\307\216\377\343\360\343\377\0q\0\377\0h" <<
139
+ "\0\377\0`\0\377\0W\0\377\0P\0\377\10E\10\335\35>\35\30\0\0\0\0\0\0\0" <<
140
+ "\0\0\0\0\0\77\205\77\30\36\215\36\270\0\212\0\377\0\202\0\377\0y\0\377" <<
141
+ "\0q\0\377\0h\0\377\0`\0\377\0X\0\377\0O\0\377\16E\16\270\35=\35\30\0" <<
142
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0""2x2J\33u\33\262\2l\2" <<
143
+ "\371\0g\0\377\0_\0\377\1T\1\371\21M\21\262\34F\35J\0\0\0\0\0\0\0\0\0" <<
144
+ "\0\0\0\0\0\0\0"
145
+
146
+ RED =
147
+ # Pixbuf magic (0x47646b50)
148
+ "GdkP" <<
149
+ # length: header (24) + pixel_data (1024)
150
+ "\0\0\4\30" <<
151
+ # pixdata_type (0x1010002)
152
+ "\1\1\0\2" <<
153
+ # rowstride (64)
154
+ "\0\0\0@" <<
155
+ # width (16)
156
+ "\0\0\0\20" <<
157
+ # height (16)
158
+ "\0\0\0\20" <<
159
+ # pixel_data:
160
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\351aaJ\36077\262\353\5\5\371\347\0\0" <<
161
+ "\377\337\0\0\377\322\4\4\371\310..\262\267LLJ\0\0\0\0\0\0\0\0\0\0\0\0" <<
162
+ "\0\0\0\0\0\0\0\0\0\0\0\0\336jj\30\36655\270\371\0\0\377\360\0\0\377\350" <<
163
+ "\0\0\377\337\0\0\377\327\0\0\377\316\0\0\377\306\0\0\377\275\0\0\377" <<
164
+ "\260%%\270\232II\30\0\0\0\0\0\0\0\0\0\0\0\0\336jj\30\371\34\34\335\370" <<
165
+ "\0\0\377\365UU\377\347\0\0\377\337\0\0\377\327\0\0\377\317\0\0\377\306" <<
166
+ "\0\0\377\275\0\0\377\265\0\0\377\255\0\0\377\241\22\22\335\213BB\30\0" <<
167
+ "\0\0\0\0\0\0\0\36655\270\370\0\0\377\366qq\377\377\377\377\377\355qq" <<
168
+ "\377\327\0\0\377\316\0\0\377\306\0\0\377\275\0\0\377\265\0\0\377\255" <<
169
+ "\0\0\377\244\0\0\377\234\0\0\377\217\37\37\270\0\0\0\0\351``J\370\0\0" <<
170
+ "\377\360\0\0\377\374\343\343\377\377\377\377\377\365\306\306\377\316" <<
171
+ "\0\0\377\306\0\0\377\275\0\0\377\265\0\0\377\255\0\0\377\244\0\0\377" <<
172
+ "\234\0\0\377\223\0\0\377\213\0\0\377}33J\35777\262\360\0\0\377\35499" <<
173
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\314\34\34\377\275" <<
174
+ "\0\0\377\275\34\34\377\27699\377\244\0\0\377\234\0\0\377\223\0\0\377" <<
175
+ "\213\0\0\377\202\0\0\377w\33\33\262\352\5\5\371\347\0\0\377\364\252\252" <<
176
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\332qq\377\265\0" <<
177
+ "\0\377\354\306\306\377\377\377\377\377\275UU\377\267UU\377\261UU\377" <<
178
+ "\254UU\377\246UU\377\237WW\373\347\0\0\377\342\34\34\377\377\377\377" <<
179
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\356\306\306\377" <<
180
+ "\27699\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" <<
181
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" <<
182
+ "\336\0\0\377\354\216\216\377\377\377\377\377\377\377\377\377\323UU\377" <<
183
+ "\377\377\377\377\377\377\377\377\340\252\252\377\377\377\377\377\377" <<
184
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" <<
185
+ "\377\377\377\377\377\377\377\377\377\377\325\40\40\372\371\343\343\377" <<
186
+ "\377\377\377\377\341\216\216\377\265\0\0\377\377\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\322\252\252\377q\0\0\377i\0\0\377`\0\0\377U\2\2\371\335\204\204" <<
189
+ "\314\377\377\377\377\377\377\377\377\275\34\34\377\254\0\0\377\352\306" <<
190
+ "\306\377\377\377\377\377\377\377\377\377\377\377\377\377\271qq\377\322" <<
191
+ "\252\252\377\200\34\34\377i\0\0\377`\0\0\377X\0\0\377N\22\22\262\343" <<
192
+ "\274\274\206\377\377\377\377\356\306\306\377\254\0\0\377\244\0\0\377" <<
193
+ "\274UU\377\377\377\377\377\377\377\377\377\343\306\306\377y\0\0\377q" <<
194
+ "\0\0\377i\0\0\377`\0\0\377X\0\0\377O\0\0\377G\35\35J\377\377\377\34\351" <<
195
+ "\305\305\347\265\34\34\377\243\0\0\377\233\0\0\377\223\0\0\377\377\377" <<
196
+ "\377\377\377\377\377\377\246UU\377q\0\0\377i\0\0\377`\0\0\377X\0\0\377" <<
197
+ "O\0\0\377E\16\16\270\0\0\0\0\0\0\0\0\224FF\30\237\22\22\335\233\0\0\377" <<
198
+ "\223\0\0\377\212\0\0\377\307\216\216\377\360\343\343\377q\0\0\377i\0" <<
199
+ "\0\377`\0\0\377X\0\0\377O\0\0\377E\10\10\335=\35\35\30\0\0\0\0\0\0\0" <<
200
+ "\0\0\0\0\0\204\77\77\30\214\36\36\270\212\0\0\377\201\0\0\377y\0\0\377" <<
201
+ "q\0\0\377h\0\0\377`\0\0\377X\0\0\377O\0\0\377E\16\16\270=\35\35\30\0" <<
202
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0y22Ju\33\33\262l\2\2\371" <<
203
+ "g\0\0\377^\0\0\377T\1\1\371M\21\21\262E\35\35J\0\0\0\0\0\0\0\0\0\0\0" <<
204
+ "\0\0\0\0\0"
205
+
206
+ YELLOW =
207
+ # Pixbuf magic (0x47646b50)
208
+ "GdkP" <<
209
+ # length: header (24) + pixel_data (1024)
210
+ "\0\0\4\30" <<
211
+ # pixdata_type (0x1010002)
212
+ "\1\1\0\2" <<
213
+ # rowstride (64)
214
+ "\0\0\0@" <<
215
+ # width (16)
216
+ "\0\0\0\20" <<
217
+ # height (16)
218
+ "\0\0\0\20" <<
219
+ # pixel_data:
220
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\351\352aJ\360\3607\262\353\353\5\371" <<
221
+ "\347\347\0\377\337\337\0\377\322\323\4\371\310\310.\262\267\267LJ\0\0" <<
222
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\336\336j\30\366\3665\270" <<
223
+ "\371\370\0\377\360\360\0\377\350\350\0\377\337\337\0\377\327\327\0\377" <<
224
+ "\316\317\0\377\306\306\0\377\275\275\0\377\260\257%\270\232\232I\30\0" <<
225
+ "\0\0\0\0\0\0\0\0\0\0\0\336\336j\30\371\370\34\335\370\370\0\377\365\365" <<
226
+ "U\377\347\347\0\377\337\337\0\377\327\327\0\377\317\316\0\377\306\306" <<
227
+ "\0\377\275\275\0\377\265\265\0\377\255\255\0\377\241\241\22\335\213\214" <<
228
+ "B\30\0\0\0\0\0\0\0\0\366\3665\270\370\370\0\377\366\366q\377\377\377" <<
229
+ "\377\377\355\355q\377\327\326\0\377\316\316\0\377\306\306\0\377\275\275" <<
230
+ "\0\377\265\265\0\377\255\255\0\377\244\244\0\377\234\234\0\377\217\217" <<
231
+ "\37\270\0\0\0\0\351\350`J\370\370\0\377\360\360\0\377\374\374\343\377" <<
232
+ "\377\377\377\377\365\366\306\377\316\316\0\377\306\306\0\377\275\275" <<
233
+ "\0\377\265\265\0\377\255\255\0\377\244\244\0\377\234\234\0\377\223\223" <<
234
+ "\0\377\213\213\0\377}|3J\357\3577\262\360\360\0\377\354\3549\377\377" <<
235
+ "\377\377\377\377\377\377\377\377\377\377\377\314\314\34\377\275\275\0" <<
236
+ "\377\275\275\34\377\276\2769\377\244\244\0\377\234\233\0\377\223\223" <<
237
+ "\0\377\213\213\0\377\202\202\0\377ww\33\262\352\352\5\371\347\347\0\377" <<
238
+ "\364\364\252\377\377\377\377\377\377\377\377\377\377\377\377\377\332" <<
239
+ "\332q\377\265\265\0\377\354\354\306\377\377\377\377\377\275\274U\377" <<
240
+ "\267\267U\377\261\261U\377\254\253U\377\246\246U\377\237\237W\373\347" <<
241
+ "\347\0\377\342\342\34\377\377\377\377\377\377\377\377\377\377\377\377" <<
242
+ "\377\377\377\377\377\356\356\306\377\276\2769\377\377\377\377\377\377" <<
243
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" <<
244
+ "\377\377\377\377\377\377\377\377\377\377\336\336\0\377\354\354\216\377" <<
245
+ "\377\377\377\377\377\377\377\377\323\323U\377\377\377\377\377\377\377" <<
246
+ "\377\377\340\340\252\377\377\377\377\377\377\377\377\377\377\377\377" <<
247
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" <<
248
+ "\377\377\377\377\325\325\40\372\371\371\343\377\377\377\377\377\341\341" <<
249
+ "\216\377\265\265\0\377\377\377\377\377\377\377\377\377\377\377\377\377" <<
250
+ "\377\377\377\377\377\377\377\377\377\377\377\377\322\322\252\377qq\0" <<
251
+ "\377ii\0\377``\0\377UU\2\371\335\335\204\314\377\377\377\377\377\377" <<
252
+ "\377\377\275\275\34\377\254\254\0\377\352\352\306\377\377\377\377\377" <<
253
+ "\377\377\377\377\377\377\377\377\271\271q\377\322\322\252\377\200\200" <<
254
+ "\34\377ii\0\377`a\0\377XX\0\377NN\22\262\343\343\274\206\377\377\377" <<
255
+ "\377\356\356\306\377\254\254\0\377\244\243\0\377\274\274U\377\377\377" <<
256
+ "\377\377\377\377\377\377\343\343\306\377yy\0\377qq\0\377ii\0\377``\0" <<
257
+ "\377XX\0\377OO\0\377GG\35J\377\377\377\34\351\351\305\347\265\265\34" <<
258
+ "\377\243\244\0\377\233\233\0\377\223\223\0\377\377\377\377\377\377\377" <<
259
+ "\377\377\246\246U\377qq\0\377ii\0\377``\0\377XX\0\377OO\0\377EE\16\270" <<
260
+ "\0\0\0\0\0\0\0\0\224\223F\30\237\237\22\335\233\233\0\377\223\223\0\377" <<
261
+ "\212\212\0\377\307\307\216\377\360\360\343\377qq\0\377ih\0\377``\0\377" <<
262
+ "XW\0\377OP\0\377EE\10\335=>\35\30\0\0\0\0\0\0\0\0\0\0\0\0\204\205\77" <<
263
+ "\30\214\215\36\270\212\212\0\377\201\202\0\377yy\0\377qq\0\377hh\0\377" <<
264
+ "``\0\377XX\0\377OO\0\377EE\16\270==\35\30\0\0\0\0\0\0\0\0\0\0\0\0\0\0" <<
265
+ "\0\0\0\0\0\0\0\0\0\0yx2Juu\33\262ll\2\371gg\0\377^_\0\377TT\1\371MM\21" <<
266
+ "\262EF\35J\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
267
+
268
+ $grey_pixbuf = Gdk::Pixbuf.new(GREY.unpack("C*"), true)
269
+ $green_pixbuf = Gdk::Pixbuf.new(GREEN.unpack("C*"), true)
270
+ $red_pixbuf = Gdk::Pixbuf.new(RED.unpack("C*"), true)
271
+ $yellow_pixbuf = Gdk::Pixbuf.new(YELLOW.unpack("C*"), true)
272
+
273
+ # build the UI
274
+
275
+ $tray = Gtk::StatusIcon.new
276
+ $tray.pixbuf = $grey_pixbuf
277
+
278
+ $menu = Gtk::Menu.new
279
+ about_item = Gtk::ImageMenuItem.new(Gtk::Stock::ABOUT)
280
+ quit_item = Gtk::ImageMenuItem.new(Gtk::Stock::QUIT)
281
+ $menu.append(about_item)
282
+ $menu.append(Gtk::SeparatorMenuItem.new)
283
+ $menu.append(quit_item)
284
+ $menu.show_all
285
+
286
+ about_item.signal_connect('activate') {
287
+ about = Gtk::AboutDialog.new
288
+ about.signal_connect('response') {
289
+ about.destroy
290
+ }
291
+ about.name = 'CurrentCost Tray Monitor'
292
+ about.version = '0.1'
293
+ about.copyright = '© 2008 James Smith'
294
+ about.comments = 'Heavily based on CCTrayRb: http://rubyforge.org/projects/cctrayrb/'
295
+ about.license = 'MIT License - see http://github.com/Floppy/currentcost-ruby/tree/master/COPYING'
296
+ about.website = 'http://github.com/Floppy/currentcost-ruby/wikis/currentcosttraymonitor'
297
+ about.authors = ['James Smith - james@floppy.org.uk']
298
+ about.show_all
299
+ }
300
+
301
+ quit_item.signal_connect('activate') {
302
+ $meter.close
303
+ Gtk.main_quit
304
+ }
305
+
306
+ $tray.signal_connect('popup_menu') { |icon, button, time|
307
+ if button == 3 # right mouse button
308
+ $menu.popup(nil, nil, button, time)
309
+ end
310
+ }
311
+
312
+ # Meter observer
313
+ class MeterObserver
314
+ def update(reading)
315
+ # Add all channels to get real figure
316
+ watts = 0
317
+ reading.channels.each { |c| watts += c[:watts] }
318
+ # Change icon colour based on power usage
319
+ case watts
320
+ when 0..349
321
+ $tray.pixbuf = $green_pixbuf
322
+ when 350..999
323
+ $tray.pixbuf = $yellow_pixbuf
324
+ else
325
+ $tray.pixbuf = $red_pixbuf
326
+ end
327
+ # Set tooltip
328
+ $tray.tooltip = "#{watts} watts"
329
+ rescue
330
+ $tray.pixbuf = $grey_pixbuf
331
+ end
332
+ end
333
+
334
+ # Create CurrentCost meter connection
335
+ $meter = CurrentCost::Meter.new(options[:port])
336
+ obs = MeterObserver.new
337
+ $meter.add_observer(obs)
338
+
339
+ # Go
340
+ Gtk.main
@@ -0,0 +1,39 @@
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
@@ -0,0 +1,7 @@
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
@@ -0,0 +1,81 @@
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
@@ -0,0 +1,10 @@
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
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.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Smith