ich habe das Problem, das ich u.A. auf einen DTMF-Code aus einem MT88L70AS im Skript höre,
welcher mir bei korrekt einen Text im OSD anzeigt.
Desweiteren läuft eine Video/Audio Matrix als while.
Gibt es die Möglichkeit die DTMF-Sache separat als while im gleichen Skript laufen zu lassen und wenn ja wie
muss es aussehen ?
Dann noch eine weitere Frage:
gibt es im while die Möglichkeit wenn ein "if" oder "elife" erkannt einen da drunter liegenden Befehl nur einmal
zu senden - es ginge da drum, ein i²c-Befehl zu einer Relaisplatine 1 Sekunde lang zu senden (also ein Relais zieht
1 Sekunde an und soll einen HDMI-Schalter betätigen...), wenn der "if" oder "elif" abgearbeitet ist, soll erneut mit
einem Befehl nur einmal wieder eine Sekunde über ein anderes Relais via i²c auf einem anderen HDMI geschaltet werden.
Anbei der bisherige Code:
Achso, dieser Teil von unten sollte als eigener while im gleichem Skript laufen:
Und unter VideoDetect_1...3 fehlt noch der i²c Befehl...
Ich hoffe auf euere Hilfe
GLG Marco DL9AM
Code: Alles auswählen
DINT = GPIO.input(GPIO_DINT)
if DINT == True:
D0 = GPIO.input(GPIO_D0)
D1 = GPIO.input(GPIO_D1)
D2 = GPIO.input(GPIO_D2)
D3 = GPIO.input(GPIO_D3)
DValue = D0+(D1*2)+(D2*4)+(D3*8)
if DValue == 1:
max7456.printStr(1,1, "CQ de 10.420GHz", enable = True)
time.sleep(15)
max7456.printStr(1,1, " ", enable = True)
elif DValue == 2:
max7456.printStr(1,1, "CQ de 1.251GHz ", enable = True)
time.sleep(15)
max7456.printStr(1,1, " ", enable = True)
elif DValue == 3:
max7456.printStr(1,1, "CQ de Test ", enable = True)
time.sleep(15)
max7456.printStr(1,1, " ", enable = True)
hier der komplette bisherige Skript
Code: Alles auswählen
# coding: utf-8
# HAMKit VMAC PiHat 2.4 - VideoDetect Video and Audio Matrix with OSD
# Video A/V In 1 and Audio A/V In 4 to Video A/V Out 1 and Audio A/V Out 3
# with OSD
# Video A/V In 1 and Audio A/V In 4 to Video A/V Out 2 and Audio A/V Out 4
# with OSD
# Video A/V In 2 and Audio A/V In 5 to Video A/V Out 1 and Audio A/V Out 3
# with OSD
# Video A/V In 2 and Audio A/V In 5 to Video A/V Out 2 and Audio A/V Out 4
# with OSD
# Video A/V In 3 and Audio A/V In 6 to Video A/V Out 1 and Audio A/V Out 3
# with OSD
# Video A/V In 3 and Audio A/V In 6 to Video A/V Out 2 and Audio A/V Out 4
# with OSD
# No VideoDetect Video Signal Inputs 1, 2 and 3: Video A/V In Pi with Audio
# A/V In 5 and 6 to Video A/V Out 1 and Audio A/V Out 3 and 4 with OSD
# No VideoDetect Video Signal Inputs 1, 2 and 3: Video A/V In Pi with Audio
# A/V In 5 and 6 to Video A/V Out 2 and Audio A/V Out 3 and 4 with OSD
# Marco Dittmann DL9AM, August 2018
#!/usr/bin/python
import RPi.GPIO as GPIO
import smbus
import spidev
import time
import datetime
from ctypes import *
#====== GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.cleanup()
#Define GPIO Outputs
LEDStatus = 22
PTT = 27
OSD_RST = 25
#Setup Outputs
GPIO.setup(LEDStatus,GPIO.OUT)
GPIO.setup(PTT,GPIO.OUT)
GPIO.setup(OSD_RST,GPIO.OUT)
#Define GPIO Inputs
GPIO_VideoDetect_1 = 18
GPIO_VideoDetect_2 = 23
GPIO_VideoDetect_3 = 24
GPIO_D0 = 26
GPIO_D1 = 19
GPIO_D2 = 13
GPIO_D3 = 6
GPIO_DINT = 5
#Setup Inputs with pull-ups enabled
GPIO.setup(GPIO_VideoDetect_1, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(GPIO_VideoDetect_2, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(GPIO_VideoDetect_3, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(GPIO_D0, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(GPIO_D1, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(GPIO_D2, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(GPIO_D3, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(GPIO_DINT, GPIO.IN, pull_up_down=GPIO.PUD_UP)
#Initiate LEDs
GPIO.output(LEDStatus,GPIO.HIGH)
GPIO.output(PTT,GPIO.HIGH)
time.sleep(.2)
GPIO.output(LEDStatus,GPIO.LOW)
GPIO.output(PTT,GPIO.LOW)
time.sleep(1)
#Define Variables
VideoDetect_1 = False
VideoDetect_2 = False
VideoDetect_3 = False
DValueStore = 0
dateString = '%H %M %S'
#Good old fashion subroutines
def flashleds (flashes):
for x in range(flashes):
GPIO.output(LEDStatus,GPIO.HIGH)
GPIO.output(PTT,GPIO.HIGH)
time.sleep(.2)
GPIO.output(LEDStatus,GPIO.LOW)
GPIO.output(PTT,GPIO.LOW)
time.sleep(1)
print ("VideoDetect Video Signal Inputs 1, 2 and 3")
#====== FMS6501 Matrix
#define values
DEVICE_BUS = 1
DEVICE_ADDR = 0x43 #0x43 or 0x03
#setup i2c bus
i2cbus = smbus.SMBus(DEVICE_BUS)
#OSD REset High
GPIO.output(OSD_RST,GPIO.HIGH)
#Set all outputs to mute.
i2cbus.write_byte_data(DEVICE_ADDR, 0x01, 0x0) #Mute
time.sleep(.01)
i2cbus.write_byte_data(DEVICE_ADDR, 0x03, 0x0) #Mute
time.sleep(.01)
i2cbus.write_byte_data(DEVICE_ADDR, 0x06, 0x0) #Mute
time.sleep(.01)
i2cbus.write_byte_data(DEVICE_ADDR, 0x09, 0x0) #Mute
time.sleep(.01)
#OSD MAX7456
class max7456():
# Create a SPI
spi = spidev.SpiDev()
# MAX7456 opcodes
VM0_reg = 0x00
VM1_reg = 0x01
HOS_reg = 0x02
VOS_reg = 0x03
DMM_reg = 0x04
DMAH = 0x05
DMAL = 0x06
DMDI = 0x07
OSDM = 0x0C
RB0 = 0x10
HOS_reg = 0x02
STATUS = 0xA0
# PAL - VM0_reg commands
ENABLE_display = 0x48
ENABLE_display_vert = 0x4c
MAX7456_reset = 0x42
DISABLE_display = 0x40
# Read command
READ = 0x80
MAX_screen_rows = 16
# White levels
WHITE_level_80 = 0x03
WHITE_level_90 = 0x02
WHITE_level_100 = 0x01
WHITE_level_120 = 0x00
chars = {' ':0, '1':1, '2':2, '3':3, '4':4, '5':5, '6':6, '7':7, '8':8, '9': 9,
'0':10, 'A':11, 'B':12, 'C':13, 'D':14, 'E':15, 'F':16, 'G':17, 'H':18, 'I':19,
'J':20, 'K':21, 'L':22, 'M':23, 'N':24, 'O':25, 'P':26, 'Q':27, 'R':28, 'S':29,
'T':30, 'U':31, 'V':32, 'W':33, 'X':34, 'Y':35, 'Z':36, 'a':37, 'b':38, 'c':39,
'd':40, 'e':41, 'f':42, 'g':43, 'h':44, 'i':45, 'j':46, 'k':47, 'l':48, 'm':49,
'n':50, 'o':51, 'p':52, 'q':53, 'r':54, 's':55, 't':56, 'u':57, 'v':58, 'w':59,
'x':60, 'y':61, 'z':62, '(':63, ')':64, '.':65, '?':66, ';':67, ':':68, ',':69,
'´':70, '/':71, '"':72, '-':73, '<':74, '>':75, '@':76
}
def __init__(self):
# Open a SPI port - max7456 connected on SPI0
self.spi.open(0, 0)
self.spi.max_speed_hz = 1000000
self.spi.bits_per_word = 8
self.spi.cshigh = False
self.spi.lsbfirst = False
self.spi.mode = 0
# On init, reset max7456
self.reset()
# Set all rows at the same white level
for x in range (0, self.MAX_screen_rows):
self.spi.xfer2([(self.RB0 + x), self.WHITE_level_90])
# Enable max7456
self.spi.xfer2([self.VM0_reg, self.ENABLE_display]);
def printStr(self, X, Y, string, enable = True):
disp = []
for char in string:
disp.append(self.chars[char])
print (string)
if enable == False:
self.spi.xfer([self.VM0_reg, self.Disable_display])
# Enable 8 bit mode:
dmm = self.spi.xfer2([self.DMM_reg + self.READ, 0x00])
dmm = self.setBit(dmm[1], 6)
self.spi.xfer2([self.DMM_reg, dmm])
start = X * 30 + Y
# Clear position
self.spi.xfer2([self.DMAH, 0x00])
self.spi.xfer2([self.DMAL, 0x00])
for char in disp:
# Write char
dmah = self.spi.xfer2([self.DMAH + self.READ, 0x00])
dmah = self.clearBit(dmah[1], 1)
self.spi.xfer2([self.DMAH, dmah])
dmah_pos = ((start >> 8) & 0x01)
dmal = (start & 0xff)
dmah = dmah | dmah_pos
start = start + 1
# Select MSB
self.spi.xfer2([self.DMAH, dmah])
self.spi.xfer2([self.DMAL, dmal])
self.spi.xfer2([self.DMDI, (char)])
def reset(self):
self.spi.xfer2([self.VM0_reg, self.MAX7456_reset])
time.sleep(0.1)
while True:
r = self.spi.xfer([self.STATUS, 0x00])
stable = self.testBit(r[1], 1)
if stable == 0:
print ("Reset MAX7456 Ok...")
break
break
def testBit(self, value, offset):
mask = 1 << value
return(value & mask)
def setBit(self, value, offset):
mask = 1 << offset
return(value + mask)
def clearBit(self, int_type, offset):
mask = ~(1 << offset)
return(int_type & mask)
try:
max7456 = max7456()
except KeyboardInterrupt:
spi.close()
#Loop
while True:
VideoDetect_1 = GPIO.input(GPIO_VideoDetect_1)
VideoDetect_2 = GPIO.input(GPIO_VideoDetect_2)
VideoDetect_3 = GPIO.input(GPIO_VideoDetect_3)
if VideoDetect_1 == True:
print ("VideoDetect_1")
i2cbus.write_byte_data(DEVICE_ADDR, 0x01, 0x81) #Input 1 to Output 1
i2cbus.write_byte_data(DEVICE_ADDR, 0x03, 0x81) #Input 1 to Output 2
i2cbus.write_byte_data(DEVICE_ADDR, 0x06, 0x87) #Input 4 to Output 3
i2cbus.write_byte_data(DEVICE_ADDR, 0x09, 0x87) #Input 4 to Output 4
i2cbus.write_byte_data(DEVICE_ADDR, 0x07, 0x81) #Input 1 to OSD In
i2cbus.write_byte_data(DEVICE_ADDR, 0x01, 0x86) #Input OSD to Output 1
i2cbus.write_byte_data(DEVICE_ADDR, 0x03, 0x86) #Input OSD to Output 2
max7456.printStr(14,1, "CQ 10.420GHz ", enable = True)
flashleds (1)
elif VideoDetect_2 == True:
print ("VideoDetect_2")
i2cbus.write_byte_data(DEVICE_ADDR, 0x01, 0x83) #Input 2 to Output 1
i2cbus.write_byte_data(DEVICE_ADDR, 0x03, 0x83) #Input 2 to Output 2
i2cbus.write_byte_data(DEVICE_ADDR, 0x06, 0x89) #Input 5 to Output 3
i2cbus.write_byte_data(DEVICE_ADDR, 0x09, 0x89) #Input 5 to Output 4
i2cbus.write_byte_data(DEVICE_ADDR, 0x07, 0x83) #Input 2 to OSD In
i2cbus.write_byte_data(DEVICE_ADDR, 0x01, 0x86) #Input OSD to Output 1
i2cbus.write_byte_data(DEVICE_ADDR, 0x03, 0x86) #Input OSD to Output 2
max7456.printStr(14,1, "CQ 1.251GHz ", enable = True)
flashleds (2)
elif VideoDetect_3 == True:
print ("VideoDetect_3")
i2cbus.write_byte_data(DEVICE_ADDR, 0x01, 0x85) #Input 3 to Output 1
i2cbus.write_byte_data(DEVICE_ADDR, 0x03, 0x85) #Input 3 to Output 2
i2cbus.write_byte_data(DEVICE_ADDR, 0x06, 0x8b) #Input 6 to Output 3
i2cbus.write_byte_data(DEVICE_ADDR, 0x09, 0x8b) #Input 6 to Output 4
i2cbus.write_byte_data(DEVICE_ADDR, 0x07, 0x85) #Input 3 to OSD In
i2cbus.write_byte_data(DEVICE_ADDR, 0x01, 0x86) #Input OSD to Output 1
i2cbus.write_byte_data(DEVICE_ADDR, 0x03, 0x86) #Input OSD to Output 2
max7456.printStr(14,1, "Test ", enable = True)
flashleds (3)
else:
print ("Pi")
i2cbus.write_byte_data(DEVICE_ADDR, 0x01, 0x8c) #Input Pi-V to Output 1
i2cbus.write_byte_data(DEVICE_ADDR, 0x03, 0x8c) #Input Pi-V to Output 2
i2cbus.write_byte_data(DEVICE_ADDR, 0x06, 0x89) #Input 5 to Output 3
i2cbus.write_byte_data(DEVICE_ADDR, 0x09, 0x8b) #Input 6 to Output 4
i2cbus.write_byte_data(DEVICE_ADDR, 0x07, 0x8c) #Input Pi-V to OSD In
i2cbus.write_byte_data(DEVICE_ADDR, 0x01, 0x86) #Input OSD to Output 1
i2cbus.write_byte_data(DEVICE_ADDR, 0x03, 0x86) #Input OSD to Output 2
max7456.printStr(14,1, datetime.datetime.now().strftime(dateString), ena ble = True)
max7456.printStr(14,9, ", Pi Temp C", enable = True)
file = open("/home/pi/1.txt","r")
max7456.printStr(14,19, file.readline(4), enable = True)
file.close()
flashleds (0)
DINT = GPIO.input(GPIO_DINT)
if DINT == True:
D0 = GPIO.input(GPIO_D0)
D1 = GPIO.input(GPIO_D1)
D2 = GPIO.input(GPIO_D2)
D3 = GPIO.input(GPIO_D3)
DValue = D0+(D1*2)+(D2*4)+(D3*8)
if DValue == 1:
max7456.printStr(1,1, "CQ de 10.420GHz", enable = True)
time.sleep(15)
max7456.printStr(1,1, " ", enable = True)
elif DValue == 2:
max7456.printStr(1,1, "CQ de 1.251GHz ", enable = True)
time.sleep(15)
max7456.printStr(1,1, " ", enable = True)
elif DValue == 3:
max7456.printStr(1,1, "CQ de Test ", enable = True)
time.sleep(15)
max7456.printStr(1,1, " ", enable = True)
#Heatbeat PTT LED as test
GPIO.output(PTT,GPIO.HIGH)
time.sleep(.2)
GPIO.output(PTT,GPIO.LOW)
time.sleep(1)