Class: FreestyleLibre::Reader
- Inherits:
-
Object
- Object
- FreestyleLibre::Reader
- Defined in:
- lib/freestyle_libre/reader.rb
Constant Summary collapse
- VENDOR_ID =
0x1a61
- PRODUCT_ID =
0x3650
- INIT_COMMAND_SEQUENCE =
[0x04, 0x05, 0x15, 0x1]
Instance Method Summary collapse
-
#arresult ⇒ Record
Manual measurements and date/time changes.
- #close ⇒ Object
-
#database_record_number ⇒ Object
latest record ID ???.
- #date_time ⇒ Object
- #date_time=(value) ⇒ Object
-
#history ⇒ Object
Automatic glucose measurements.
-
#initialize(interface = nil) ⇒ Reader
constructor
A new instance of Reader.
- #patient_id ⇒ Object
- #patient_id=(value) ⇒ Object
- #patient_name ⇒ Object
- #patient_name=(value) ⇒ Object
- #serial ⇒ Object
- #software_version ⇒ Object
Constructor Details
#initialize(interface = nil) ⇒ Reader
Returns a new instance of Reader.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/freestyle_libre/reader.rb', line 9 def initialize(interface = nil) HIDAPI::SetupTaskHelper.new(VENDOR_ID, PRODUCT_ID, "abbott-freestyle-libre", interface).run @device = HIDAPI::open(VENDOR_ID, PRODUCT_ID, interface) raise 'device could not be opened' unless @device INIT_COMMAND_SEQUENCE.each do |c| write_report(c, '') read_report end end |
Instance Method Details
#arresult ⇒ Record
Manual measurements and date/time changes
81 82 83 84 |
# File 'lib/freestyle_libre/reader.rb', line 81 def arresult write_report(0x60, '$arresult?') read_multi.map { |record| ar(record) }.compact end |
#close ⇒ Object
86 87 88 |
# File 'lib/freestyle_libre/reader.rb', line 86 def close @device.close end |
#database_record_number ⇒ Object
latest record ID ???
65 66 67 68 69 70 71 |
# File 'lib/freestyle_libre/reader.rb', line 65 def database_record_number # TODO: not sure this matches the description. # We should check that by scanning the tag two times and seeing that the number of new history # matches the increase of this number write_report(0x60, '$dbrnum?') read_text_command.gsub('DB Record Number =', '').strip.to_i end |
#date_time ⇒ Object
30 31 32 33 34 35 |
# File 'lib/freestyle_libre/reader.rb', line 30 def date_time write_report(0x60, '$date?') date = read_text_command.strip write_report(0x60, '$time?') DateTime.strptime("#{date} #{read_text_command}", '%m,%d,%y %H,%M') end |
#date_time=(value) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/freestyle_libre/reader.rb', line 37 def date_time=(value) write_report(0x60, "$date,#{value.strftime('%-m,%-d,%y')}") read_text_command write_report(0x60, "$time,#{value.strftime('%H,%M')}") read_text_command end |
#history ⇒ Object
Automatic glucose measurements
74 75 76 77 |
# File 'lib/freestyle_libre/reader.rb', line 74 def history write_report(0x60, '$history?') read_multi.map { |record| auto_measurement(record) } end |
#patient_id ⇒ Object
59 60 61 62 |
# File 'lib/freestyle_libre/reader.rb', line 59 def patient_id write_report(0x60, '$ptid?') read_text_command.strip end |
#patient_id=(value) ⇒ Object
54 55 56 57 |
# File 'lib/freestyle_libre/reader.rb', line 54 def patient_id=(value) write_report(0x60, "$ptid,#{value}") read_text_command end |
#patient_name ⇒ Object
49 50 51 52 |
# File 'lib/freestyle_libre/reader.rb', line 49 def patient_name write_report(0x60, '$ptname?') read_text_command.strip end |
#patient_name=(value) ⇒ Object
44 45 46 47 |
# File 'lib/freestyle_libre/reader.rb', line 44 def patient_name=(value) write_report(0x60, "$ptname,#{value}") read_text_command end |
#serial ⇒ Object
20 21 22 23 |
# File 'lib/freestyle_libre/reader.rb', line 20 def serial write_report(0x60, '$sn?') read_text_command.strip end |
#software_version ⇒ Object
25 26 27 28 |
# File 'lib/freestyle_libre/reader.rb', line 25 def software_version write_report(0x60, '$swver?') read_text_command.strip end |