Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby
- # -*- coding: utf-8 -*-
- # IR code decoder for NEC format
- line = ARGF.read
- ar = line.split(",")
- while true do
- v = ar.slice(0, 2)
- break if v == nil || v.length != 2
- v[0] = v[0].to_i
- v[1] = v[1].to_i
- if 800 < v[0]
- # Leader (start of new frame)
- str = ""
- elsif 300 < v[1]
- # Trailer
- puts str if 0 < str.length
- if str.length == 32
- c0 = "%02X" % str.slice(0, 8).reverse.to_i(2)
- c1 = "%02X" % str.slice(8, 8).reverse.to_i(2)
- d0 = "%02X" % str.slice(16, 8).reverse.to_i(2)
- d1 = "%02X" % str.slice(24, 8).reverse.to_i(2)
- puts "#{c0} #{c1} #{d0} "
- end
- str = ""
- else
- if v[0] * 2 < v[1]
- str = str + "1"
- else
- str = str + "0"
- end
- end
- ar = ar.slice(2, ar.length)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement