Si vous constatez la perte de tickets, de commentaires ou de projets, veuillez consulter la page https://status.framasoft.org/incident/626.

Commit 3ae36dea authored by ZettaScript's avatar ZettaScript

Update driver

parent 2fb197de
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Copyright 2017-2018 Pascal Engélibert
Raspberry Pi - Minitel driver
......@@ -9,12 +10,12 @@ http://pila.fr/content/interface_usb_minitel/specifications%20techniques%20d%27u
from time import sleep, time
from threading import Thread, RLock
import RPi.GPIO as gpio
from sys import stdout
from sys import stdout, stderr
FREQ = 1200# frequency (Hz)
PULSE = 1/FREQ# pulse duration (s)
PULSE2 = PULSE/16
PULSE0 = PULSE*16
PULSE0 = PULSE*10
TX = 21# output pin (RPi out, Minitel in)
RX = 20# input pin (RPi in, Minitel out)
......@@ -57,10 +58,13 @@ class RecBuf(Thread):
n = 1
if n > 0:
c += [v] * round(n/6)
while len(c) >= 10 and c[0] == 0 and c[9] == 1:
if (c[1]+c[2]+c[3]+c[4]+c[5]+c[6]+c[7])&1 == c[8]:
stdout.write(chr(c[1]|(c[2]<<1)|(c[3]<<2)|(c[4]<<3)|(c[5]<<4)|(c[6]<<5)|(c[7]<<6)))
#stdout.write(hex(c[1]|(c[2]<<1)|(c[3]<<2)|(c[4]<<3)|(c[5]<<4)|(c[6]<<5)|(c[7]<<6))+" ")
stdout.flush()
c = c[10:]
s = []
if (c[1]+c[2]+c[3]+c[4]+c[5]+c[6]+c[7])&1 == c[8]:
stdout.write(chr(c[1]|(c[2]<<1)|(c[3]<<2)|(c[4]<<3)|(c[5]<<4)|(c[6]<<5)|(c[7]<<6)))
stdout.flush()
sleep(PULSE2)
class SendBuf(Thread):
......@@ -73,8 +77,8 @@ class SendBuf(Thread):
bytebuf = []
outgpio = gpio.output
tx_high = False
LOW = gpio.LOW
HIGH = gpio.HIGH
LOW = gpio.HIGH
HIGH = gpio.LOW
while self.work:
if len(bytebuf) > 0:
if bytebuf.pop(0):
......@@ -88,28 +92,29 @@ class SendBuf(Thread):
if d != -1:
#bytebuf = [1,d&0x40,d&0x20,d&0x10,d&0x08,d&0x04,d&0x02,d&0x01, ((d&0x40)+(d&0x20)+(d&0x10)+(d&0x08)+(d&0x04)+(d&0x02)+(d&0x01))&1]
bytebuf = [0, d&0x01,d&0x02,d&0x04,d&0x08,d&0x10,d&0x20,d&0x40, ((d&0x40)+(d&0x20)+(d&0x10)+(d&0x08)+(d&0x04)+(d&0x02)+(d&0x01))&1,1]
#sleep(PULSE/2)
#if tx_high:
# outgpio(TX, LOW)
# tx_high = False
#sleep(PULSE/2)
sleep(PULSE)
if tx_high:
outgpio(TX, LOW)
tx_high = False
#sleep(PULSE)
# Return false if the buffer is empty
def busy(self):
return self.databuf != []
sendbuf = SendBuf()
recbuf = RecBuf()
# Init GPIO and start the com thread
def initSerial():
gpio.setwarnings(False)
gpio.setmode(gpio.BCM)
gpio.setup(TX, gpio.OUT, initial=gpio.LOW)
gpio.setup(TX, gpio.OUT, initial=gpio.HIGH)
gpio.setup(RX, gpio.IN, pull_up_down=gpio.PUD_UP)
sendbuf.start()
recbuf.start()
sendbuf = SendBuf()
recbuf = RecBuf()
# Stop com thread
def stop():
recbuf.work = False
......@@ -123,9 +128,14 @@ busy = sendbuf.busy
initSerial()
try:
while True:
for c in input():
sendbuf.databuf.append(ord(c))
try:
for c in input():
sendbuf.databuf.append(ord(c))
except (UnicodeDecodeError, UnicodeEncodeError):
stderr.write("En mode tele-informatique, le Minitel ne supporte pas l'ASCII etendu.")
stderr.flush()
except KeyboardInterrupt:
print("KeyboardInterrupt")
stderr.write("KeyboardInterrupt\n")
stderr.flush()
stop()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment