Class: Denko::EEPROM::BuiltIn
Instance Attribute Summary
#callback_mutex
#board
Instance Method Summary
collapse
#_read, #read, #read_using, #wait_for_read
#add_callback, #callbacks, #initialize, #remove_callback, #update
#initialize, #state
#initialize, #micro_delay
Instance Method Details
#[](index) ⇒ Object
40
41
42
|
# File 'lib/denko/eeprom/built_in.rb', line 40
def [](index)
@state_mutex.synchronize { @state.send :[], index }
end
|
#[]=(index, value) ⇒ Object
44
45
46
|
# File 'lib/denko/eeprom/built_in.rb', line 44
def []=(index, value)
@state_mutex.synchronize { @state.send :[]=, index, value }
end
|
#after_initialize(options = {}) ⇒ Object
13
14
15
16
17
|
# File 'lib/denko/eeprom/built_in.rb', line 13
def after_initialize(options={})
super(options)
self.state = Array.new(board.eeprom_length, nil)
load
end
|
#each(&block) ⇒ Object
48
49
50
|
# File 'lib/denko/eeprom/built_in.rb', line 48
def each(&block)
@state_mutex.synchronize { @state.send :each, &block }
end
|
#each_with_index(&block) ⇒ Object
52
53
54
|
# File 'lib/denko/eeprom/built_in.rb', line 52
def each_with_index(&block)
@state_mutex.synchronize { @state.send :each_with_index, &block }
end
|
#length ⇒ Object
Also known as:
count
Specific Array-like methods for convenience.
37
|
# File 'lib/denko/eeprom/built_in.rb', line 37
def length; board.eeprom_length; end
|
#load ⇒ Object
19
20
21
22
23
|
# File 'lib/denko/eeprom/built_in.rb', line 19
def load
state.each_slice(128).with_index do |slice, index|
read_using -> { board.eeprom_read(index * 128, slice.length) }
end
end
|
#pin ⇒ Object
9
10
11
|
# File 'lib/denko/eeprom/built_in.rb', line 9
def pin
254
end
|
#pre_callback_filter(message) ⇒ Object
56
57
58
59
60
|
# File 'lib/denko/eeprom/built_in.rb', line 56
def pre_callback_filter(message)
address = message.split("-", 2)[0].to_i
bytes = message.split("-", 2)[1].split(",").map(&:to_i)
{address: address, data: bytes}
end
|
#save ⇒ Object
25
26
27
28
29
30
31
32
|
# File 'lib/denko/eeprom/built_in.rb', line 25
def save
@state_mutex.synchronize do
@state.each_slice(128).with_index do |slice, index|
board.eeprom_write(index * 128, slice)
end
end
load
end
|
#update_state(hash) ⇒ Object
62
63
64
65
66
|
# File 'lib/denko/eeprom/built_in.rb', line 62
def update_state(hash)
@state_mutex.synchronize do
@state[hash[:address], hash[:data].length] = hash[:data]
end
end
|