Last active
January 1, 2016 16:29
-
-
Save Akkiesoft/8170833 to your computer and use it in GitHub Desktop.
RasPiでIPアドレスを表示するRubyスクリプト。lcd.rbを流用。手抜きをしたのでアレだけど、ちゃんと書けばシェルスクリプトでできるし、そのほうがRasPiではスマートかと思われる。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
require 'wiringpi' | |
class Lcd | |
def initialize | |
@io = WiringPi::GPIO.new | |
end | |
def setLcdInfo(i2cset, i2cbus, chip_addr, light_gpio) | |
@i2cset = i2cset | |
@i2cbus = i2cbus | |
@chip_addr = chip_addr | |
end | |
def sendBlockData(v1, v2) | |
`#{@i2cset} -y #{@i2cbus} #{@chip_addr} #{v1} #{v2} i` | |
end | |
def sendByteData(v1, v2) | |
`#{@i2cset} -y #{@i2cbus} #{@chip_addr} #{v1} #{v2} b` | |
end | |
def reset | |
sendBlockData(0, "0x38 0x39 0x14 0x78 0x5e 0x6c") | |
sleep 0.25 | |
sendBlockData(0, "0x0c 0x01 0x06") | |
sleep 0.05 | |
end | |
def clear | |
sendBlockData(0, 1) | |
end | |
def moveCursor(x, y) | |
sendByteData(0, 128 + 64 * x + y) | |
end | |
def lcdprint(str) | |
for x in str.split(//) | |
sendstr = sendstr.to_s + " " + x.ord.to_s | |
end | |
sendBlockData(0x40, sendstr.to_s) | |
end | |
end | |
lcd = Lcd.new | |
lcd.setLcdInfo("/usr/sbin/i2cset", 1, 0x3e, 7) | |
lcd.reset | |
lcd.clear | |
lcd.moveCursor(0,0) | |
lcd.lcdprint("IP Check") | |
sleep(5) | |
lcd.clear | |
# ip = `ifconfig eth0|grep 'inet addr'|awk -F ':' '{print $2}'|awk -F ' ' '{print $1}'`.chomp.split(".") | |
count = 0 | |
ip = "" | |
while ip == "" do | |
ip = `hostname -I`.chomp.split(".") | |
if ip == "" then | |
count++ | |
lcd.moveCursor(1,0) | |
lcd.lcdprint("Try(#{count})") | |
sleep(15) | |
end | |
end | |
ip1 = "#{ip[0]}.#{ip[1]}." | |
ip2 = "#{ip[2]}.#{ip[3]}" | |
lcd.clear | |
lcd.moveCursor(0,0) | |
lcd.lcdprint(ip1) | |
lcd.moveCursor(1,0) | |
lcd.lcdprint(ip2) | |
exit 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment