Permalink
Browse files

[lcd-icreader] use wiringpi i2c class, fix playbook / fix libpafe url

* wiringpi-rubyだけでI2C制御できるようになった
* ナウいplaybookにした
* libpafeのURLが変わっていたので変更した
  • Loading branch information...
Akkiesoft committed Nov 29, 2018
1 parent eedbc35 commit ba57a864a3ac47e73c6684fe82bdf6acb94a4daa
@@ -1,4 +1,5 @@
---
- hosts: lcd-icreader
gather_facts: no
roles:
- lcd-icreader
@@ -5,7 +5,3 @@
- name: reload udev
command: udevadm control --reload-rules
become: yes
- name: reboot
command: reboot
become: yes
@@ -1,114 +1,111 @@
- set_fact:
libpafe_url: "http://hito.music.coocan.jp/pasori"
libpafe_ver: 0.0.8
libpafe_ruby_ver: 0.0.8
- set_fact:
libpafe_so: "/usr/local/lib/libpafe.so.{{ libpafe_ver }}"
pasori_so: /usr/local/lib/arm-linux-gnueabihf/site_ruby/pasori.so
- name: install packages
apt: >
name={{ item }}
state=present
update_cache=yes
cache_valid_time=3600
with_items:
- i2c-tools
apt:
name:
- gcc
- libusb-1.0-0-dev
- ruby
- ruby-dev
- wiringpi
state: present
update_cache: yes
cache_valid_time: 3600
become: yes
- name: install wiringpi module
gem: >
name=wiringpi
state=present
become: yes
- name: enable i2c
lineinfile: >
dest=/boot/config.txt
line="dtparam=i2c_arm=on"
notify: reboot
gem:
name: wiringpi
state: present
become: yes
- name: enable i2c
lineinfile: >
dest=/etc/modules
line={{ item }}
with_items:
- i2c-bcm2708
- i2c-dev
notify: reboot
command: raspi-config nonint do_i2c 0
become: yes
- name: download libpafe
get_url: >
url=http://homepage3.nifty.com/slokar/pasori/libpafe-0.0.8.tar.gz
dest=/home/pi/
get_url:
url: "{{ libpafe_url }}/libpafe-{{ libpafe_ver }}.tar.gz"
dest: /home/pi
- name: unarchive libpafe
unarchive: >
src=/home/pi/libpafe-0.0.8.tar.gz
dest=/home/pi
copy=no
- name: check exist libpafe library
stat: path=/usr/local/lib/libpafe.so.0.0.8
register: libpafe_so
unarchive:
src: "/home/pi/libpafe-{{ libpafe_ver }}.tar.gz"
dest: /home/pi
copy: no
- name: configure libpafe
command: ./configure chdir=/home/pi/libpafe-0.0.8
when: not libpafe_so.stat.exists
command: ./configure
args:
chdir: "/home/pi/libpafe-{{ libpafe_ver }}"
creates: "{{ libpafe_so }}"
- name: make libpafe
command: make chdir=/home/pi/libpafe-0.0.8
when: not libpafe_so.stat.exists
command: make
args:
chdir: "/home/pi/libpafe-{{ libpafe_ver }}"
creates: "{{ libpafe_so }}"
- name: install libpafe
command: make install chdir=/home/pi/libpafe-0.0.8
when: not libpafe_so.stat.exists
command: make install
args:
chdir: "/home/pi/libpafe-{{ libpafe_ver }}"
creates: "{{ libpafe_so }}"
notify: run ldconfig
become: yes
- name: copy udev rule for libpafe
copy:
src=60-libpafe.rules
dest=/etc/udev/rules.d
src: 60-libpafe.rules
dest: /etc/udev/rules.d
notify: reload udev
become: yes
- name: download libpafe-ruby
get_url: >
url=http://homepage3.nifty.com/slokar/pasori/libpafe-ruby-0.0.8.tar.gz
dest=/home/pi/
get_url:
url: "{{ libpafe_url }}/libpafe-ruby-{{ libpafe_ruby_ver }}.tar.gz"
dest: /home/pi
- name: unarchive libpafe-ruby
unarchive: >
src=/home/pi/libpafe-ruby-0.0.8.tar.gz
src="/home/pi/libpafe-ruby-{{ libpafe_ruby_ver }}.tar.gz"
dest=/home/pi
copy=no
- name: check exist libpafe-ruby module
stat: path=/usr/local/lib/site_ruby/arm-linux-eabihf/pasori.so
register: pasori_so
- name: ruby extconf.rb
command: ruby extconf.rb chdir=/home/pi/libpafe-ruby
when: not pasori_so.stat.exists
command: ruby extconf.rb
args:
chdir: /home/pi/libpafe-ruby
creates: "{{ pasori_so }}"
- name: make libpafe-ruby
command: make chdir=/home/pi/libpafe-ruby
when: not pasori_so.stat.exists
command: make
args:
chdir: /home/pi/libpafe-ruby
creates: "{{ pasori_so }}"
- name: install libpafe-ruby
command: make install chdir=/home/pi/libpafe-ruby
when: not pasori_so.stat.exists
command: make install
args:
chdir: /home/pi/libpafe-ruby
creates: "{{ pasori_so }}"
become: yes
- name: copy lcd-icreader.rb
copy: >
src=lcd-icreader.rb
dest=/home/pi/
copy:
src: lcd-icreader.rb
dest: /home/pi/
- name: set autostart lcd-icreader.rb
lineinfile: >
dest=/etc/rc.local
insertbefore="exit 0"
line="become /usr/bin/ruby /home/pi/lcd-icreader.rb &"
lineinfile:
dest: /etc/rc.local
insertbefore: "exit 0"
line: "become /usr/bin/ruby /home/pi/lcd-icreader.rb &"
become: yes
@@ -1,6 +1,6 @@
# coding: utf-8
# IC balance checker / 2013-2015 @Akkiesoft
# IC balance checker / 2013-2018 @Akkiesoft
# Licence:
# MIT License
# references:
@@ -14,12 +14,12 @@
# For Switch Science i2c miniLCD
# https://www.switch-science.com/catalog/1405/
contrast = "0x5d"
contrast = 0x5d
gpio_light = 0
# For Strawberry Linux SB1602BW
# https://strawberry-linux.com/catalog/items?code=27021
# contrast = "0x5e"
# contrast = 0x5e
# gpio_light = 7
# Please set 0 to gpio_beep if if you don't have the buzzer.
@@ -28,19 +28,15 @@
class Lcd
OUTPUT = 1
def initialize
@io = WiringPi::GPIO.new
end
def setLcdInfo(i2cset, i2cbus, chip_addr, light_gpio=0, beep_gpio, contrast)
@i2cset = i2cset
@i2cbus = i2cbus
def initialize(chip_addr, contrast, light_gpio=0, beep_gpio)
@chip_addr = chip_addr
@contrast = contrast
@light_gpio = light_gpio
@beep_gpio = beep_gpio
@contrast = contrast
# if you are using Switch Science i2c miniLCD, comment out here.
@io = WiringPi::GPIO.new
@i2c = WiringPi::I2C.new(@chip_addr)
if @light_gpio != 0
@io.pin_mode(@light_gpio, OUTPUT)
end
@@ -50,52 +46,51 @@ def setLcdInfo(i2cset, i2cbus, chip_addr, light_gpio=0, beep_gpio, contrast)
end
end
def light(value)
if @light_gpio != 0
@io.digital_write(@light_gpio, value)
end
def sendBlockData(reg, block)
block.each { |i| sendByteData(reg, i) }
end
def beep()
if @beep_gpio != 0
@io.digital_write(@beep_gpio, 1)
sleep 0.1
@io.digital_write(@beep_gpio, 0)
sleep 0.025
@io.digital_write(@beep_gpio, 1)
sleep 0.1
@io.digital_write(@beep_gpio, 0)
end
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`
def sendByteData(reg, byte)
@i2c.write_reg_8(reg, byte)
end
def reset
sendBlockData(0, "0x38 0x39 0x14 0x78 " + @contrast + " 0x6c")
sendBlockData(0, [0x38, 0x39, 0x14, 0x78, @contrast, 0x6c])
sleep 0.25
sendBlockData(0, "0x0c 0x01 0x06")
sendBlockData(0, [0x0c, 0x01, 0x06])
sleep 0.05
end
def clear
sendBlockData(0, 1)
sendBlockData(0, [1])
end
def moveCursor(x, y)
sendByteData(0, 128 + 64 * x + y)
sendByteData(0, 128 + 64 * y + x)
end
def lcdprint(str)
for x in str.split(//)
sendstr = sendstr.to_s + " " + x.ord.to_s
sendByteData(0x40, x.ord)
end
end
def light(value)
if @light_gpio != 0
@io.digital_write(@light_gpio, value)
end
end
def beep()
if @beep_gpio != 0
@io.digital_write(@beep_gpio, 1)
sleep 0.1
@io.digital_write(@beep_gpio, 0)
sleep 0.025
@io.digital_write(@beep_gpio, 1)
sleep 0.1
@io.digital_write(@beep_gpio, 0)
end
sendBlockData(0x40, sendstr.to_s)
end
end
@@ -105,8 +100,7 @@ def firstmessage(lcd)
lcd.lcdprint("Please touch IC.")
end
lcd = Lcd.new
lcd.setLcdInfo("/usr/sbin/i2cset", 1, 0x3e, gpio_light, gpio_beep, contrast)
lcd = Lcd.new(0x3e, contrast, gpio_light, gpio_beep)
lcd.reset
lcd.clear
@@ -204,11 +198,11 @@ def firstmessage(lcd)
lcd.moveCursor(0,0)
if card["name"] == "Unknown"
lcd.lcdprint("Unknown card.")
lcd.moveCursor(1,0)
lcd.moveCursor(0,1)
lcd.lcdprint("#{card["balance"]}")
else
lcd.lcdprint("#{card["name"]} ザンダカ:".encode("Shift_JIS"))
lcd.moveCursor(1,0)
lcd.moveCursor(0,1)
balance = sprintf("%c%s", 0x5c, card["balance"]).encode("Shift_JIS")
if card["point"]
balance += sprintf("/%spts", card["point"]).encode("Shift_JIS")

0 comments on commit ba57a86

Please sign in to comment.