# # (C) Copyright Johannes Brodwall , 2006 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. def xps_led_all(color = 1, intensity = 7) system "xps_led_control -all #{color} -front 1 -bright #{intensity}" or raise "xps_led_control failed. Error code: #{$?}" end def xps_led(intensity, color = 1) intensity %= 14 intensity -= 7 intensity = intensity.abs # puts "xps_led_control -all #{color} -bright #{intensity}" xps_led_all(color, intensity) end def pulse_brightness(sleep_time = 0.2, color = 1) (0..100).each do |i| xps_led(i, color) sleep(sleep_time) end end def pulse_color(sleep_time = 0.5, brightness = 7) (0..16000).each do |i| xps_led(brightness, (i % 16) + 1) sleep(sleep_time) xps_led(brightness, 0) sleep(sleep_time/2) end end def cycle_array(colors, sleep_time = 0.2) colors.each { |color| xps_led(7, color); sleep(sleep_time) } end if __FILE__ == $0 puts "Cycle array" cycle_array([1, 5, 0, 1, 0, 2, 0, 1]) end