Module: LegacyFirmware
- Defined in:
- lib/sensors/basic_message_arduino_sensor.rb
Instance Method Summary collapse
- #finish_times ⇒ Object
- #racers ⇒ Object
- #send_length(ticks) ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
- #time ⇒ Object
Instance Method Details
#finish_times ⇒ Object
227 228 229 |
# File 'lib/sensors/basic_message_arduino_sensor.rb', line 227 def finish_times @t['finish_times'] || [] end |
#racers ⇒ Object
231 232 233 |
# File 'lib/sensors/basic_message_arduino_sensor.rb', line 231 def racers @t['racers'] || [[],[],[],[]] end |
#send_length(ticks) ⇒ Object
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/sensors/basic_message_arduino_sensor.rb', line 162 def send_length(ticks) begin Timeout.timeout(1.0){ @f.flush @f.putc ?l @f.putc(ticks % 256) @f.putc(ticks / 256) @f.putc ?\r puts "setting length" @length_status = @f.readline puts "length status: #{@length_status}" } rescue Timeout::Error puts "Timeout setting length" else #TODO raise an ErrorReceivingTickLength and catch it in the app like # we do with a missing arduino error. #raise @length_status unless @length_status=~/OK/ end end |
#start ⇒ Object
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 |
# File 'lib/sensors/basic_message_arduino_sensor.rb', line 183 def start @t.kill if @t @t = Thread.new do @f.putc 'g' Thread.current["racers"] = [[],[],[],[]] Thread.current["finish_times"] = [] @f.flush while true do l = @f.readline if l=~/:/ if l =~ /0:/ Thread.current["racers"][0] = [0] * l.gsub(/0: /,'').to_i end if l =~ /1:/ Thread.current["racers"][1] = [1] * l.gsub(/1: /,'').to_i end if l =~ /2:/ Thread.current["racers"][2] = [2] * l.gsub(/2: /,'').to_i end if l =~ /3:/ Thread.current["racers"][3] = [3] * l.gsub(/3: /,'').to_i end if l =~ /0f:/ Thread.current["finish_times"][0] = l.gsub(/0f: /,'').to_i end if l =~ /1f:/ Thread.current["finish_times"][1] = l.gsub(/1f: /,'').to_i end if l =~ /2f:/ Thread.current["finish_times"][2] = l.gsub(/2f: /,'').to_i end if l =~ /3f:/ Thread.current["finish_times"][3] = l.gsub(/3f: /,'').to_i end if l =~ /t:/ Thread.current["time"] = l.gsub(/t: /,'').to_i end end puts l end end self end |
#stop ⇒ Object
239 240 241 242 243 |
# File 'lib/sensors/basic_message_arduino_sensor.rb', line 239 def stop @f.puts 's' @f.flush @t.kill end |
#time ⇒ Object
235 236 237 |
# File 'lib/sensors/basic_message_arduino_sensor.rb', line 235 def time @t['time'] || 0 end |