Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
A
AIDA-2020 TLU - Software
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
AIDA-2020 TLU - Software
Commits
ab189fa3
Commit
ab189fa3
authored
Jul 24, 2018
by
Paolo Baesso
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'PythonScripts'
This should only be minor tweaks.
parents
c422c61c
666e4f6e
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
310 additions
and
298 deletions
+310
-298
.gitignore
.gitignore
+1
-0
AIDA_testScript.py
TLU_v1e/scripts/AIDA_testScript.py
+9
-1
TLU_v1e.py
TLU_v1e/scripts/TLU_v1e.py
+18
-20
I2CDISP.py
packages/I2CDISP.py
+159
-13
I2CuHal.py
packages/I2CuHal.py
+1
-0
TLU_powermodule.py
packages/TLU_powermodule.py
+122
-264
No files found.
.gitignore
View file @
ab189fa3
...
...
@@ -13,6 +13,7 @@ Simulation/
*.jou
*.str
*.BKP
*.repo
## Backup files
*.py~
...
...
TLU_v1e/scripts/AIDA_testScript.py
View file @
ab189fa3
...
...
@@ -7,6 +7,7 @@ from si5345 import si5345
from
AD5665R
import
AD5665R
from
PCA9539PW
import
PCA9539PW
from
E24AA025E48T
import
E24AA025E48T
from
I2CDISP
import
LCD_ada
#Library for display
manager
=
uhal
.
ConnectionManager
(
"file://./TLUconnection.xml"
)
hw
=
manager
.
getDevice
(
"tlu"
)
...
...
@@ -157,12 +158,19 @@ print "\tIC7 read back bank 0: 0x%X" % res[0]
#BANK 1
IC7
.
setInvertReg
(
1
,
0x00
)
# 0= normal
IC7
.
setIOReg
(
1
,
0x00
)
# 0= output <<<<<<<<<<<<<<<<<<<
IC7
.
setOutputs
(
1
,
0x
B0
)
IC7
.
setOutputs
(
1
,
0x
AF
)
res
=
IC7
.
getInputs
(
1
)
print
"
\t
IC7 read back bank 1: 0x
%
X"
%
res
[
0
]
# #I2C EXPANDER CONFIGURATION END
#Instantiate Display
doDisplaytest
=
False
if
doDisplaytest
:
DISP
=
LCD_ada
(
master_I2C
,
0x20
)
#3A
#self.DISP.clear()
DISP
.
test
()
# #Reset counters
#cmd = int("0x0", 16) #write 0x2 to reset
#hw.getNode("triggerInputs.SerdesRstW").write(cmd)
...
...
TLU_v1e/scripts/TLU_v1e.py
View file @
ab189fa3
...
...
@@ -12,7 +12,8 @@ from I2CuHal import I2CCore
from
si5345
import
si5345
# Library for clock chip
from
AD5665R
import
AD5665R
# Library for DAC
from
PCA9539PW
import
PCA9539PW
# Library for serial line expander
from
I2CDISP
import
CFA632
#Library for display
#from I2CDISP import LCD_ada # Library for Adafruit display
from
I2CDISP
import
LCD09052
# Library for SparkFun display
from
TLU_powermodule
import
PWRLED
from
ATSHA204A
import
ATSHA204A
...
...
@@ -114,8 +115,19 @@ class TLU:
self
.
IC7
.
setIOReg
(
1
,
0x00
)
# 0= output, 1= input
self
.
IC7
.
setOutputs
(
1
,
0xB0
)
# If output, set to XX
#Instantiate Display
self
.
DISP
=
CFA632
(
self
.
TLU_I2C
,
0x2A
)
#
#Attempt to instantiate Display
self
.
displayPresent
=
True
i2ccmd
=
[
7
,
150
]
mystop
=
True
print
" Attempting to detect TLU display"
res
=
self
.
TLU_I2C
.
write
(
0x3A
,
i2ccmd
,
mystop
)
if
(
res
==
-
1
):
# if this fails, likely no display installed
self
.
displayPresent
=
False
print
"
\t
No TLU display detected"
if
self
.
displayPresent
:
self
.
DISP
=
LCD09052
(
self
.
TLU_I2C
,
0x3A
)
#0x3A for Sparkfun, 0x20 for Adafruit
self
.
DISP
.
test2
(
"192.168.200.30"
,
"AIDA TLU"
)
#self.DISP=CFA632(self.TLU_I2C, 0x2A) #
#Instantiate Power/Led Module
dac_addr_module
=
int
(
parsed_cfg
.
get
(
section_name
,
"I2C_DACModule_Addr"
),
16
)
...
...
@@ -125,31 +137,17 @@ class TLU:
self
.
pwdled
=
PWRLED
(
self
.
TLU_I2C
,
dac_addr_module
,
pmtCtrVMax
,
exp1_addr
,
exp2_addr
)
#self.pwdled.setIndicatorRGB(1, [0, 0, 1])
#self.pwdled.setIndicatorRGB(2, [0, 0, 1])
#self.pwdled.setIndicatorRGB(3, [0, 0, 1])
#self.pwdled.setIndicatorRGB(4, [0, 0, 1])
#self.pwdled.setIndicatorRGB(5, [0, 0, 1])
#self.pwdled.setIndicatorRGB(6, [0, 0, 1])
#self.pwdled.setIndicatorRGB(7, [0, 0, 1])
#self.pwdled.setIndicatorRGB(8, [0, 0, 1])
#self.pwdled.setIndicatorRGB(9, [0, 0, 1])
#self.pwdled.setIndicatorRGB(10, [0, 0, 1])
#self.pwdled.setIndicatorRGB(11, [0, 0, 1])
self
.
pwdled
.
allGreen
()
time
.
sleep
(
0.1
)
self
.
pwdled
.
allBlue
()
time
.
sleep
(
0.1
)
self
.
pwdled
.
allBlack
()
time
.
sleep
(
0.1
)
#
self.pwdled.kitt()
self
.
pwdled
.
kitt
()
time
.
sleep
(
0.1
)
#self.pwdled.allBlack()
#self.pwdled.allRed()
#time.sleep(0.1)
self
.
pwdled
.
allWhite
()
#self.pwdled.test()
##################################################################################################################################
...
...
packages/I2CDISP.py
View file @
ab189fa3
...
...
@@ -4,6 +4,10 @@ from I2CuHal2 import I2CCore
import
StringIO
import
time
import
math
import
numpy
as
np
#######################################################################################
class
CFA632
:
#Class to configure the CFA632 display
...
...
@@ -22,13 +26,71 @@ class CFA632:
#myaddr= [int(i2ccmd)]
self
.
i2c
.
write
(
self
.
slaveaddr
,
i2ccmd
,
mystop
)
return
#######################################################################################
class
LCD_ada
:
def
__init__
(
self
,
i2c
,
slaveaddr
=
0x20
):
self
.
i2c
=
i2c
self
.
slaveaddr
=
slaveaddr
self
.
nRows
=
2
self
.
nCols
=
16
def
test
(
self
):
mystop
=
True
i2ccmd
=
[]
print
"Write to LCD_ada"
print
"
\t
"
,
i2ccmd
#myaddr= [int(i2ccmd)]
self
.
getIOdir
()
self
.
setIOdir
(
0x7F
)
self
.
getIOdir
()
self
.
setGPIO
(
0x80
)
self
.
i2c
.
write
(
self
.
slaveaddr
,
i2ccmd
,
mystop
)
def
getGPIO
(
self
):
# Read port (if configured as inputs)
mystop
=
False
regN
=
0x09
nwords
=
1
self
.
i2c
.
write
(
self
.
slaveaddr
,
[
regN
],
mystop
)
res
=
self
.
i2c
.
read
(
self
.
slaveaddr
,
nwords
)
print
"MCP23008 IOdir"
,
res
return
res
def
setGPIO
(
self
,
gpio
):
# Sets the output latch
mystop
=
True
i2ccmd
=
[
9
,
gpio
]
print
"Write GPIO to MCP23008"
self
.
i2c
.
write
(
self
.
slaveaddr
,
i2ccmd
,
mystop
)
def
getIOdir
(
self
):
mystop
=
False
regN
=
0x00
nwords
=
1
self
.
i2c
.
write
(
self
.
slaveaddr
,
[
regN
],
mystop
)
res
=
self
.
i2c
.
read
(
self
.
slaveaddr
,
nwords
)
print
"MCP23008 IOdir"
,
res
return
res
def
setIOdir
(
self
,
iodir
):
# 1 indicates the port is an input
# 0 indicates the port is an output
mystop
=
True
i2ccmd
=
[
0
,
iodir
]
print
"Write IODIR to MCP23008"
self
.
i2c
.
write
(
self
.
slaveaddr
,
i2ccmd
,
mystop
)
#######################################################################################
class
LCD09052
:
#Class to configure the LCD09052 display
def
__init__
(
self
,
i2c
,
slaveaddr
=
0x3A
):
self
.
i2c
=
i2c
self
.
slaveaddr
=
slaveaddr
self
.
nRows
=
2
self
.
nCols
=
16
self
.
setLCDtype
(
self
.
nRows
,
self
.
nCols
)
def
test
(
self
):
print
"
\t
Testing display (LCD09052)"
...
...
@@ -40,37 +102,100 @@ class LCD09052:
self
.
setBrightness
(
0
)
time
.
sleep
(
0.2
)
self
.
setBrightness
(
250
)
for
ipos
in
range
(
1
,
1
8
):
for
ipos
in
range
(
1
,
1
7
):
self
.
writeChar
(
33
)
self
.
posCursor
(
1
,
ipos
-
1
)
time
.
sleep
(
0.1
)
self
.
writeChar
(
254
)
self
.
posCursor
(
2
,
1
)
for
ipos
in
range
(
1
,
1
8
):
for
ipos
in
range
(
1
,
1
7
):
self
.
writeChar
(
33
)
self
.
posCursor
(
2
,
ipos
-
1
)
time
.
sleep
(
0.1
)
self
.
writeChar
(
254
)
self
.
clear
self
.
clearLine
(
1
)
self
.
writeChar
(
33
)
time
.
sleep
(
0.1
)
self
.
writeChar
(
33
)
time
.
sleep
(
0.1
)
self
.
writeChar
(
33
)
time
.
sleep
(
0.1
)
self
.
writeChar
(
33
)
time
.
sleep
(
0.1
)
self
.
writeChar
(
33
)
time
.
sleep
(
0.1
)
self
.
clearLine
(
1
)
self
.
writeString
([
80
,
81
,
80
,
81
,
82
])
return
def
clear
(
self
):
### Clears the display and locates the curson on position (1,1), i.e. top left
i2ccmd
=
[
4
]
def
test2
(
self
,
myString1
=
""
,
myString2
=
""
):
#myString= [80, 81, 80, 81, 82]
self
.
clear
()
self
.
dispString
(
myString1
)
self
.
posCursor
(
2
,
1
)
self
.
dispString
(
myString2
)
self
.
pulseLCD
(
1
)
time
.
sleep
(
0.3
)
myChar
=
[
0
,
17
,
0
,
0
,
17
,
14
,
0
,
0
]
#self.writeChar(1)
#time.sleep(1)
#self.createChar(1, [31, 31, 31, 0, 17, 14, 0, 0])
#self.createChar(2, [0, 0, 17, 0, 0, 17, 14, 0])
#time.sleep(1)
#self.writeChar(1)
return
def
dispString
(
self
,
myString
):
### Writes the string on the display
myInts
=
[]
for
iChar
in
list
(
myString
):
myInts
.
append
(
ord
(
iChar
))
self
.
writeString
(
myInts
)
return
def
writeString
(
self
,
myChars
):
### Writes a list of chars from the current position of the cursor
## NOTE: myChars is a list of integers corresponding to the ASCII code of each
## character to be printed. Use "dispString" to input an actual string.
#i2ccmd= [1, myChars]
myChars
.
insert
(
0
,
1
)
mystop
=
True
self
.
i2c
.
write
(
self
.
slaveaddr
,
i2ccmd
,
mystop
)
self
.
i2c
.
write
(
self
.
slaveaddr
,
myChars
,
mystop
)
def
posCursor
(
self
,
line
,
pos
):
### Position the cursor on a specific location
## line can be 1 (top) or 2 (bottom)
## pos can be [1, 16}
if
((
line
==
1
)
or
(
line
==
2
)
and
(
1
<=
pos
<=
16
)):
if
((
line
==
1
)
or
(
line
==
2
)
and
(
1
<=
pos
<=
self
.
nCols
)):
i2ccmd
=
[
2
,
line
,
pos
]
mystop
=
True
self
.
i2c
.
write
(
self
.
slaveaddr
,
i2ccmd
,
mystop
)
else
:
print
"Cursor line can only be 1 or 2, position must be in range [1,
16
]"
print
"Cursor line can only be 1 or 2, position must be in range [1,
"
,
self
.
nCols
,
"
]"
def
clearLine
(
self
,
iLine
):
### Clear line. Place cursor at beginning of line.
if
((
iLine
==
1
)
or
(
iLine
==
2
)):
i2ccmd
=
[
3
,
iLine
]
mystop
=
True
self
.
i2c
.
write
(
self
.
slaveaddr
,
i2ccmd
,
mystop
)
def
clear
(
self
):
### Clears the display and locates the curson on position (1,1), i.e. top left
i2ccmd
=
[
4
]
mystop
=
True
self
.
i2c
.
write
(
self
.
slaveaddr
,
i2ccmd
,
mystop
)
def
setLCDtype
(
self
,
nLines
,
nColumns
):
### Specifies the number of lines and columns in the display.
## This does not seem to do much but we use it anyway.
## NOTE: no check is performed on the nLines and nColumns parameters so be
## carefuls in using this function.
i2ccmd
=
[
5
,
nLines
,
nColumns
]
mystop
=
True
self
.
i2c
.
write
(
self
.
slaveaddr
,
i2ccmd
,
mystop
)
def
setBrightness
(
self
,
value
=
250
):
### Sets the brightness level of the backlight.
## Value is an integer in range [0, 250]. 0= no light, 250= maximum light.
...
...
@@ -84,14 +209,23 @@ class LCD09052:
mystop
=
True
self
.
i2c
.
write
(
self
.
slaveaddr
,
i2ccmd
,
mystop
)
def
writeChar
(
self
,
value
):
### Writes a char in the current cursor position
## The curso is then shifted right one position
## The curso
r
is then shifted right one position
## value must be an integer corresponding to the ascii code of the character
i2ccmd
=
[
1
,
value
]
i2ccmd
=
[
1
0
,
value
]
mystop
=
True
self
.
i2c
.
write
(
self
.
slaveaddr
,
i2ccmd
,
mystop
)
return
def
createChar
(
self
,
pos
=
1
,
myChar
=
[]):
### Define a personalized character and stores it in position "pos"
## NOTE: This is not working yet.
mystop
=
True
myChar
=
[
0
,
17
,
0
,
0
,
17
,
14
,
0
,
0
]
myChar
.
insert
(
0
,
64
)
self
.
i2c
.
write
(
self
.
slaveaddr
,
myChar
,
mystop
)
return
def
writeSomething
(
self
,
i2ccmd
):
mystop
=
True
...
...
@@ -101,3 +235,15 @@ class LCD09052:
self
.
i2c
.
write
(
self
.
slaveaddr
,
i2ccmd
,
mystop
)
return
def
pulseLCD
(
self
,
nCycles
):
### Sets the backlight to pulse for N cycles.
## Each cycle lasts approximately 1.5 s and start/stop on full brightness
## The light varies according to a sinusoidal wave
startP
=
0
endP
=
nCycles
*
(
math
.
pi
)
nPoints
=
15
*
nCycles
myList
=
np
.
linspace
(
startP
,
endP
,
nPoints
)
.
tolist
()
for
iPt
in
myList
:
iBright
=
int
(
250
*
abs
(
math
.
cos
(
iPt
)))
self
.
setBrightness
(
iBright
)
time
.
sleep
(
0.1
)
\ No newline at end of file
packages/I2CuHal.py
View file @
ab189fa3
...
...
@@ -130,6 +130,7 @@ class I2CCore:
if
not
ack
:
self
.
cmd_stat
.
write
(
I2CCore
.
stopcmd
)
self
.
target
.
dispatch
()
print
"no ack from I2C address"
,
hex
(
addr
>>
1
)
return
nwritten
nwritten
+=
1
for
val
in
data
:
...
...
packages/TLU_powermodule.py
View file @
ab189fa3
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment