__deets__ hat geschrieben: Donnerstag 30. August 2018, 17:49 Mit einer solchen Aussage kann man nix anfangen. Einfach nur einkopiert bewirkt der Code gar nix. Und wie genau du den verwendest wird aus einer solchen Beschreibung nicht ersichtlich. Also bitte poste deinem Code.
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 Pi to Video A/V Out 1 and Audio A/V Out 3 with OSD
# No VideoDetect Video Signal Inputs 1, 2 and 3: Video A/V In Pi with Audio
# A/V In Pi to Video A/V Out 2 and Audio A/V Out 4 with OSD
# Marco Dittmann DL9AM, August 2018
#!/usr/bin/python
import RPi.GPIO as GPIO
import smbus
import spidev
import time
import datetime
import os
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_Button = 4
GPIO_VideoDetect_1 = 18
GPIO_VideoDetect_2 = 23
GPIO_VideoDetect_3 = 24
GPIO_SquelchDetect_1 = 12
GPIO_SquelchDetect_2 = 16
GPIO_SquelchDetect_3 = 20
GPIO_SquelchDetect_4 = 21
GPIO_D0 = 26
GPIO_D1 = 19
GPIO_D2 = 13
GPIO_D3 = 6
GPIO_DINT = 5
#Setup Inputs with pull-ups enabled
GPIO.setup(GPIO_Button, GPIO.IN, pull_up_down=GPIO.PUD_UP)
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_SquelchDetect_1, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(GPIO_SquelchDetect_2, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(GPIO_SquelchDetect_3, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(GPIO_SquelchDetect_4, 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 Inputs 1, 2, 3 and SquelchDetect 1, 2, 3 and 4")
#====== FMS6501 Matrix
#define values
DEVICE_BUS = 1
DEVICE_ADDR = 0x43 #0x43 or 0x03
DEVICE_BUS_RELAIS = 1
DEVICE_ADDR_RELAIS = 0x01
#setup i2c bus
i2cbus = smbus.SMBus(DEVICE_BUS)
i2cbus_relais = smbus.SMBus(DEVICE_BUS_RELAIS)
#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(.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()
class SourceStack(object):
def __init__(self):
self._stack = []
def on(self, value):
if value not in self._stack:
self._stack.append(value)
def off(self, value):
if value in self._stack:
self._stack.remove(value)
@property
def current(self):
return self._stack[-1] if self._stack else None
VIDEO1, VIDEO2, VIDEO3 = "video1", "video2", "video3"
ss = SourceStack()
ss.on(VIDEO1)
print(ss.current)
ss.on(VIDEO1)
print(ss.current)
ss.off(VIDEO2)
print(ss.current)
ss.on(VIDEO2)
print(ss.current)
ss.off(VIDEO1)
print(ss.current)
ss.off(VIDEO2)
print(ss.current)
#Loop
while True:
VideoDetect_1 = GPIO.input(GPIO_VideoDetect_1)
VideoDetect_2 = GPIO.input(GPIO_VideoDetect_2)
VideoDetect_3 = GPIO.input(GPIO_VideoDetect_3)
SquelchDetect_1 = GPIO.input(GPIO_SquelchDetect_1)
SquelchDetect_2 = GPIO.input(GPIO_SquelchDetect_2)
SquelchDetect_3 = GPIO.input(GPIO_SquelchDetect_3)
SquelchDetect_4 = GPIO.input(GPIO_SquelchDetect_4)
Button = GPIO.input(GPIO_Button)
if Button == False:
max7456.printStr(1,1, "HAMKit VMAC PiHat", enable = True)
max7456.printStr(2,1, "Reboot by Sysop", enable = True)
flashleds (10)
os.system("sudo reboot")
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(10)
max7456.printStr(1,1, " ", enable = True)
elif DValue == 2:
max7456.printStr(1,1, "CQ de 1.251GHz ", enable = True)
time.sleep(10)
max7456.printStr(1,1, " ", enable = True)
elif DValue == 3:
max7456.printStr(1,1, "CQ de Test ", enable = True)
time.sleep(10)
max7456.printStr(1,1, " ", enable = True)
if VideoDetect_1 == True:
print ("VideoDetect_1")
# i2cbus_relais.write_byte_data(DEVICE_ADDR_RELAIS, 0x02, 0x02) #Switch HDMI 2 to CVBS
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_relais.write_byte_data(DEVICE_ADDR_RELAIS, 0x02, 0x02) #Switch HDMI 2 to CVBS
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, 0x88) #Input 5 to Output 3
i2cbus.write_byte_data(DEVICE_ADDR, 0x09, 0x88) #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_relais.write_byte_data(DEVICE_ADDR_RELAIS, 0x02, 0x02) #Switch HDMI 2 to CVBS
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, 0x89) #Input 6 to Output 3
i2cbus.write_byte_data(DEVICE_ADDR, 0x09, 0x89) #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)
elif SquelchDetect_1 == False:
print ("SquelchDetect_1")
print ("CQ 436MHz")
# i2cbus_relais.write_byte_data(DEVICE_ADDR_RELAIS, 0x03, 0x03) #Switch HDMI 3 to DVB-T
flashleds (4)
else:
print ("Pi")
# i2cbus_relais.write_byte_data(DEVICE_ADDR_RELAIS, 0x01, 0x01) #Switch HDMI 1 to camera
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, 0x8b) #Input Pi-A to Output 3
i2cbus.write_byte_data(DEVICE_ADDR, 0x09, 0x8b) #Input Pi-A 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), enable = True)
max7456.printStr(14,9, ", Pi Temp C", enable = True)
file = open("/home/pi/1.txt","r")
max7456.printStr(14,19, file.readline().rstrip('\n'), enable = True)
file.close()
flashleds (0)
#Heatbeat PTT LED as test
GPIO.output(PTT,GPIO.HIGH)
time.sleep(.2)
GPIO.output(PTT,GPIO.LOW)
time.sleep(1)