-
Notifications
You must be signed in to change notification settings - Fork 11
/
lcd.py
executable file
·116 lines (90 loc) · 3.16 KB
/
lcd.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/env python
#-*- coding: utf8 -*-
"""
Copyright (C) 2020 Yoann QUERET <[email protected]>
"""
"""
This file is part of ODR-EncoderManager.
ODR-EncoderManager is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
ODR-EncoderManager is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with ODR-EncoderManager. If not, see <http://www.gnu.org/licenses/>.
"""
import sys
import time
import os
import socket
import argparse
from config import Config
from lcd import LcdMatrix
PORT_SERIE = '/dev/ttyACM0' #identification du port série sur lequel le LCD USB est connecté
LCD_COLS = 16 # Taille du LCD 16 caractères x 2 lignes
LCD_ROWS = 2
def wtitle(title, msg):
lcd.clear_screen()
lcd.position( 1, 1 )
lcd.write( title )
if len(msg) <= 16:
lcd.position( 2, 1 )
lcd.write( msg )
time.sleep(2)
else:
i=0
while i != len(msg)-15:
m = msg[i:i+16]
lcd.position( 2, 1 )
lcd.write( m )
if i == 0:
time.sleep(2)
else:
time.sleep(0.5)
i=i+1
time.sleep(1)
if __name__ == '__main__':
# Get configuration file in argument
parser = argparse.ArgumentParser(description='ODR Encoder Manager (LCD)')
parser.add_argument('-c','--config', help='configuration filename',required=True)
cli_args = parser.parse_args()
# Check if configuration exist and is readable
if os.path.isfile(cli_args.config) and os.access(cli_args.config, os.R_OK):
print ("Use configuration file %s" % (cli_args.config))
else:
print ("Configuration file is missing or is not readable - %s" % (cli_args.config))
sys.exit(1)
# Load configuration
config = Config(cli_args.config)
# Load LcdMatrix
lcd = LcdMatrix( PORT_SERIE )
# Initialiser la taille du LCD (et sauver dans l'EEPROM)
lcd.set_lcd_size( LCD_COLS, LCD_ROWS )
lcd.clear_screen()
# Set splash screen
lcd.set_splashscreen( 'DAB+ Encoder Starting ... ' )
# Activer le rétro-éclairage
lcd.activate_lcd( True )
# Luminosité max
lcd.brightness( 255 )
# Background RGB
lcd.color( 120, 120, 255 )
while True:
lcd.autoscroll( False )
# Display hostname and admin ip
lcd.clear_screen()
lcd.write( 'DAB+ Encoder')
time.sleep( 2 )
# Retreive NETWORK IFACE IP
for card in config.config['global']['network']['cards']:
try:
ip = os.popen('ip addr show %s' % (card['card'])).read().split("inet ")[1].split("/")[0]
except:
pass
else:
lcd.clear_screen()
wtitle( str('IP iface %s' % (card['alias']) ), ip)
time.sleep( 4 )