Skip to content

Commit 1e7239f

Browse files
committed
add Settings options for screens
1 parent b5c25b1 commit 1e7239f

14 files changed

+191
-112
lines changed

install-little-backup-box.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,14 +379,20 @@ if [ "${SCRIPT_MODE}" = "install" ]; then
379379
for I2C in "${I2C_LIST[@]}"; do
380380
if [[ "${I2C_DETECT}" =~ " ${I2C}" ]]; then
381381
sudo sed -i '/conf_DISP=/d' "${CONFIG}"
382-
echo -e 'conf_DISP=true' | sudo tee -a "${CONFIG}"
382+
echo -e "conf_DISP='display'" | sudo tee -a "${CONFIG}"
383383

384384
sudo sed -i '/conf_DISP_I2C_ADDRESS=/d' "${CONFIG}"
385385
echo -e "conf_DISP_I2C_ADDRESS=\"${I2C}\"" | sudo tee -a "${CONFIG}"
386+
387+
conf_DISP='display'
386388
break
387389
fi
388390
done
389391

392+
if [[ "$conf_DISP" != "display" && -f /usr/sbin/lightdm ]]; then
393+
sudo sed -i '/conf_DISP=/d' "${CONFIG}"
394+
echo -e "conf_DISP='screen'" | sudo tee -a "${CONFIG}"
395+
fi
390396
fi
391397

392398
# remove all from crontab
Lines changed: 50 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@
1717
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1818
#######################################################################
1919

20+
import argparse
2021
import os
2122
import subprocess
2223

2324
import lib_setup
2425
import lib_system
2526

2627
class display_config(object):
27-
def __init__(self):
28+
def __init__(self, activate=None):
2829
self.CONFIG_FILE = '/boot/firmware/lbb-display.txt'
2930
self.UDEV_FILE = '/etc/udev/hwdb.d/61-ads7846-touch.hwdb'
3031

@@ -36,6 +37,8 @@ def __init__(self):
3637
self.conf_TOUCH_MATRIX_X = self.__setup.get_val('conf_TOUCH_MATRIX_X')
3738
self.conf_TOUCH_MATRIX_Y = self.__setup.get_val('conf_TOUCH_MATRIX_Y')
3839

40+
self.conf_DISP = activate if activate in ['display', 'screen', '0'] else self.__setup.get_val('conf_DISP')
41+
3942
def setup_display(self):
4043
if not os.path.isfile('/usr/sbin/lightdm'):
4144
return(False)
@@ -46,24 +49,25 @@ def setup_display(self):
4649
def __write_config_txt(self):
4750
rpi = lib_system.get_pi_model(number_only=True)
4851

49-
# define driver
50-
match self.conf_SCREEN_DRIVER:
51-
case 'piscreen':
52-
DRIVER = f'dtoverlay=piscreen,speed={self.conf_SCREEN_SPEED},rotate={self.conf_SCREEN_ROTATE}'
53-
case 'waveshare35a':
54-
DRIVER = f'dtoverlay=waveshare35a,speed={self.conf_SCREEN_SPEED},rotate={self.conf_SCREEN_ROTATE}'
55-
case 'mipi-dbi':
56-
DRIVER = f'''dtoverlay=mipi-dbi,spi0-0,ili9486
57-
dtparam=speed={self.conf_SCREEN_SPEED}
58-
dtparam=rotate={self.conf_SCREEN_ROTATE}
59-
dtparam=reset-gpio=25
60-
dtparam=dc-gpio=24'''
61-
62-
# Raspberry Pi 4 specific settings
63-
Pi4 = '' if rpi >= 5 else 'hdmi_force_hotplug=1'
64-
65-
# assemble include for config.txt
66-
CONFIG = f"""# Display settings
52+
if self.conf_DISP == 'screen':
53+
# define driver
54+
match self.conf_SCREEN_DRIVER:
55+
case 'piscreen':
56+
DRIVER = f'dtoverlay=piscreen,speed={self.conf_SCREEN_SPEED},rotate={self.conf_SCREEN_ROTATE}'
57+
case 'waveshare35a':
58+
DRIVER = f'dtoverlay=waveshare35a,speed={self.conf_SCREEN_SPEED},rotate={self.conf_SCREEN_ROTATE}'
59+
case 'mipi-dbi':
60+
DRIVER = f'''dtoverlay=mipi-dbi,spi0-0,ili9486
61+
dtparam=speed={self.conf_SCREEN_SPEED}
62+
dtparam=rotate={self.conf_SCREEN_ROTATE}
63+
dtparam=reset-gpio=25
64+
dtparam=dc-gpio=24'''
65+
66+
# Raspberry Pi 4 specific settings
67+
Pi4 = '' if rpi >= 5 else 'hdmi_force_hotplug=1'
68+
69+
# assemble include for config.txt
70+
CONFIG = f"""# Display settings
6771
6872
# Enable SPI bus
6973
dtparam=spi=on
@@ -75,25 +79,48 @@ def __write_config_txt(self):
7579
{DRIVER}
7680
7781
dtparam=drm=on
78-
"""
82+
"""
83+
else:
84+
CONFIG = ''
85+
7986
with open(self.CONFIG_FILE, 'w') as config_file:
8087
config_file.write(CONFIG)
8188

8289
def __write_touch_udev(self):
8390
# create and activate self.UDEV_FILE
84-
CONFIG = f"""evdev:name:ADS7846 Touchscreen*:*
91+
if self.conf_DISP == 'screen':
92+
CONFIG = f"""evdev:name:ADS7846 Touchscreen*:*
8593
LIBINPUT_MODEL_PRESSURE_PAD=1
8694
LIBINPUT_ATTR_PRESSURE_RANGE=10:255
8795
LIBINPUT_ATTR_TOUCH_SIZE_RANGE=1:1
8896
LIBINPUT_CALIBRATION_MATRIX={self.conf_TOUCH_MATRIX_X} {self.conf_TOUCH_MATRIX_Y} 0 0 1
89-
"""
97+
"""
98+
else:
99+
CONFIG = ''
100+
90101
with open(self.UDEV_FILE, 'w') as config_file:
91102
config_file.write(CONFIG)
92103

93104
subprocess.run(['sudo', 'systemd-hwdb', 'update'])
94105
subprocess.run(['sudo', 'udevadm', 'trigger', '-s', 'input'])
95106

107+
def parse_args() -> argparse.Namespace:
108+
parser = argparse.ArgumentParser(
109+
description="Write config files for SPI touchscreens"
110+
)
111+
112+
activates = ['display', 'screen', '0']
113+
parser.add_argument(
114+
"--activate",
115+
choices=activates,
116+
default="",
117+
help=f'One of {activates}',
118+
)
119+
120+
return parser.parse_args()
121+
96122
if __name__ == "__main__":
97-
display_config().setup_display()
123+
args = parse_args()
124+
display_config(activate=args.activate).setup_display()
98125

99126

scripts/display.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -98,39 +98,39 @@ def __init__(self):
9898
self.__display_content_files = display_content_files(self.__setup)
9999

100100
# setup
101-
self.__conf_DISP_CONNECTION = self.__setup.get_val('conf_DISP_CONNECTION')
102-
self.__conf_DISP_DRIVER = self.__setup.get_val('conf_DISP_DRIVER')
101+
self.__conf_DISP_CONNECTION = self.__setup.get_val('conf_DISP_CONNECTION')
102+
self.__conf_DISP_DRIVER = self.__setup.get_val('conf_DISP_DRIVER')
103103
self.__conf_DISP_I2C_ADDRESS = self.__setup.get_val('conf_DISP_I2C_ADDRESS')
104104
self.__conf_DISP_SPI_PORT = self.__setup.get_val('conf_DISP_SPI_PORT')
105105
self.__conf_DISP_RESOLUTION_X = self.__setup.get_val('conf_DISP_RESOLUTION_X')
106106
self.__conf_DISP_RESOLUTION_Y = self.__setup.get_val('conf_DISP_RESOLUTION_Y')
107107
self.__conf_DISP_OFFSET_X = self.__setup.get_val('conf_DISP_OFFSET_X')
108108
self.__conf_DISP_OFFSET_Y = self.__setup.get_val('conf_DISP_OFFSET_Y')
109-
self.__conf_DISP_ROTATE = self.__setup.get_val('conf_DISP_ROTATE')
109+
self.__conf_DISP_ROTATE = self.__setup.get_val('conf_DISP_ROTATE')
110110
self.__conf_DISP_CONTRAST = self.__setup.get_val('conf_DISP_CONTRAST')
111-
self.__conf_DISP_COLOR_BGR = self.__setup.get_val('conf_DISP_COLOR_BGR')
112-
self.__conf_DISP_COLOR_INVERSE = self.__setup.get_val('conf_DISP_COLOR_INVERSE')
111+
self.__conf_DISP_COLOR_BGR = self.__setup.get_val('conf_DISP_COLOR_BGR')
112+
self.__conf_DISP_COLOR_INVERSE = self.__setup.get_val('conf_DISP_COLOR_INVERSE')
113113
self.__conf_DISP_COLOR_MODEL = self.__setup.get_val('conf_DISP_COLOR_MODEL')
114-
self.__conf_DISP_COLOR_TEXT = self.__setup.get_val('conf_DISP_COLOR_TEXT')
115-
self.__conf_DISP_COLOR_HIGH = self.__setup.get_val('conf_DISP_COLOR_HIGH')
114+
self.__conf_DISP_COLOR_TEXT = self.__setup.get_val('conf_DISP_COLOR_TEXT')
115+
self.__conf_DISP_COLOR_HIGH = self.__setup.get_val('conf_DISP_COLOR_HIGH')
116116
self.__conf_DISP_COLOR_ALERT = self.__setup.get_val('conf_DISP_COLOR_ALERT')
117117
self.__conf_DISP_COLOR_BACKGROUND = self.__setup.get_val('conf_DISP_COLOR_BACKGROUND')
118-
self.__conf_DISP_FONT_SIZE = self.__setup.get_val('conf_DISP_FONT_SIZE')
119-
self.__conf_DISP_FRAME_TIME = self.__setup.get_val('conf_DISP_FRAME_TIME')
120-
self.__conf_DISP_SHOW_STATUSBAR = self.__setup.get_val('conf_DISP_SHOW_STATUSBAR')
121-
self.__conf_DISP_BACKLIGHT_PIN = self.__setup.get_val('conf_DISP_BACKLIGHT_PIN')
122-
self.__conf_DISP_BACKLIGHT_ENABLED = self.__setup.get_val('conf_DISP_BACKLIGHT_ENABLED')
118+
self.__conf_DISP_FONT_SIZE = self.__setup.get_val('conf_DISP_FONT_SIZE')
119+
self.__conf_DISP_FRAME_TIME = self.__setup.get_val('conf_DISP_FRAME_TIME')
120+
self.__conf_DISP_SHOW_STATUSBAR = self.__setup.get_val('conf_DISP_SHOW_STATUSBAR')
121+
self.__conf_DISP_BACKLIGHT_PIN = self.__setup.get_val('conf_DISP_BACKLIGHT_PIN')
122+
self.__conf_DISP_BACKLIGHT_ENABLED = self.__setup.get_val('conf_DISP_BACKLIGHT_ENABLED')
123123
self.__conf_MENU_ENABLED = self.__setup.get_val('conf_MENU_ENABLED')
124-
self.__conf_DIPLAY_IMAGES_KEEP = self.__setup.get_val('conf_DIPLAY_IMAGES_KEEP')
124+
self.__conf_DIPLAY_IMAGES_KEEP = self.__setup.get_val('conf_DIPLAY_IMAGES_KEEP')
125125

126126
self.__const_DISPLAY_CONTENT_OLD_FILE = self.__setup.get_val('const_DISPLAY_CONTENT_OLD_FILE')
127127
self.__const_DISPLAY_LINES_LIMIT = self.__setup.get_val('const_DISPLAY_LINES_LIMIT')
128128
self.__const_DISPLAY_STATUSBAR_TOGGLE_SEC = self.__setup.get_val('const_DISPLAY_STATUSBAR_TOGGLE_SEC')
129-
self.__const_FONT_PATH = self.__setup.get_val('const_FONT_PATH')
129+
self.__const_FONT_PATH = self.__setup.get_val('const_FONT_PATH')
130130
self.__const_DISPLAY_CONTENT_PATH = self.__setup.get_val('const_DISPLAY_CONTENT_PATH')
131-
self.__const_DISPLAY_IMAGE_EXPORT_FILE = self.__setup.get_val('const_DISPLAY_IMAGE_EXPORT_FILE')
131+
self.__const_DISPLAY_IMAGE_EXPORT_FILE = self.__setup.get_val('const_DISPLAY_IMAGE_EXPORT_FILE')
132132
self.__const_DISPLAY_IMAGE_KEEP_PATH = self.__setup.get_val('const_DISPLAY_IMAGE_KEEP_PATH')
133-
self.__const_TASKS_PATH = self.__setup.get_val('const_TASKS_PATH')
133+
self.__const_TASKS_PATH = self.__setup.get_val('const_TASKS_PATH')
134134

135135
#define colors
136136
color = {}
@@ -164,6 +164,7 @@ def __init__(self):
164164

165165
self.hardware_ready = True
166166

167+
serial = None
167168
try:
168169
if self.__conf_DISP_CONNECTION == 'I2C':
169170
serial = i2c(port=1, address=self.__conf_DISP_I2C_ADDRESS)
@@ -183,7 +184,7 @@ def __init__(self):
183184
print(f'Display connection to {self.__conf_DISP_CONNECTION} could not be enabled.', file=sys.stderr)
184185

185186
try:
186-
if self.__conf_DISP_DRIVER == 'none':
187+
if self.__conf_DISP_DRIVER == 'none' or serial is None:
187188
self.device = self.__display_dummy()
188189
self.hardware_ready = False
189190
elif self.__conf_DISP_DRIVER == 'SSD1306':

scripts/kiosk-calibrate.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ main() {
140140

141141
wait_for_cal_done
142142

143-
python3 /var/www/little-backup-box/create_display_config.py
143+
python3 /var/www/little-backup-box/create_screen_config.py
144144

145145
stop_firefox
146146
stop_cal_server

scripts/lang/de.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,6 @@
243243
},
244244
"display": {
245245
"section": "Display",
246-
"activate_label": "Ist ein Display angeschlossen und soll es verwendet werden?",
247246
"connection_header": "Schnittstelle für das Display",
248247
"connection_label": "Welche Schnittstelle soll verwendet werden?",
249248
"i2c_address_label": "i2c-Adresse des Displays",
@@ -292,7 +291,12 @@
292291
"backlight_header": "Display-Hintergrundbeleuchtung",
293292
"backlight_enabled_label": "Display-Hintergrundbeleuchtung aktivieren (falls vorhanden)",
294293
"backlight_pin_label": "Welcher GPIO-PIN (BCM-Notation) ist mit der Hintergrundbeleuchtung verbunden?",
295-
"additional_settings_header": "Weitere Display-Einstellungen "
294+
"additional_settings_header": "Weitere Display-Einstellungen ",
295+
"activate": {
296+
"display_label": "Ein am GPIO angeschlossenes Display soll verwendet werden.",
297+
"none_label": "Keine Anzeige",
298+
"screen_label": "Ein am GPIO angeschlossener Bildschirm (oder Touchscreen) soll verwendet werden."
299+
}
296300
},
297301
"menu": {
298302
"enable_header": "Display-Menu aktivieren",
@@ -354,7 +358,8 @@
354358
"speed": {
355359
"header": "Bildschirmgeschwindigkeit",
356360
"label": "Wählen Sie die Geschwindigkeit, mit der Ihr Bildschirm angesprochen werden kann."
357-
}
361+
},
362+
"usage_updated": "Die Konfiguration der Anzeige wurde gespeichert."
358363
},
359364
"exit": {
360365
"section": "LBB beenden",

scripts/lang/en.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,6 @@
502502
},
503503
"display": {
504504
"section": "Display",
505-
"activate_label": "Is a display connected and should it be used?",
506505
"connection_header": "Interface for the display",
507506
"connection_label": "Which interface should be used?",
508507
"i2c_address_label": "i2c address of the display",
@@ -551,7 +550,12 @@
551550
"backlight_header": "Display backlight",
552551
"backlight_enabled_label": "Activate display backlight (if available)",
553552
"backlight_pin_label": "Which GPIO pin (BCM notation) is connected to the backlight?",
554-
"additional_settings_header": "Additional display settings"
553+
"additional_settings_header": "Additional display settings",
554+
"activate": {
555+
"display_label": "A display connected via GPIO should be used.",
556+
"none_label": "No display",
557+
"screen_label": "A screen (or touchscreen) connected via GPIO should be used."
558+
}
555559
},
556560
"menu": {
557561
"enable_header": "Activate display menu",
@@ -613,7 +617,8 @@
613617
"speed": {
614618
"header": "Display speed",
615619
"label": "Select the speed at which your display can be driven."
616-
}
620+
},
621+
"usage_updated": "The display configuration has been saved."
617622
},
618623
"exit": {
619624
"section": "Terminate LBB",

scripts/lang/es.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,6 @@
243243
},
244244
"display": {
245245
"section": "Pantalla",
246-
"activate_label": "¿Hay una pantalla conectada y debería usarse?",
247246
"connection_header": "Interfaz para la pantalla",
248247
"connection_label": "¿Qué interfaz se debe utilizar?",
249248
"i2c_address_label": "Dirección i2c de la pantalla",
@@ -292,7 +291,12 @@
292291
"backlight_header": "Retroiluminación de la pantalla",
293292
"backlight_enabled_label": "Activar la retroiluminación de la pantalla (si está disponible)",
294293
"backlight_pin_label": "¿Qué pin GPIO (notación BCM) está conectado a la luz de fondo?",
295-
"additional_settings_header": "Configuraciones de pantalla adicionales"
294+
"additional_settings_header": "Configuraciones de pantalla adicionales",
295+
"activate": {
296+
"display_label": "Se debe utilizar una pantalla conectada al GPIO.",
297+
"none_label": "Sin pantalla",
298+
"screen_label": "Se debe utilizar una pantalla (o pantalla táctil) conectada al GPIO."
299+
}
296300
},
297301
"menu": {
298302
"enable_header": "Activar menú de visualización",
@@ -354,7 +358,8 @@
354358
"speed": {
355359
"header": "Velocidad de la pantalla",
356360
"label": "Seleccione la velocidad a la que se puede controlar su pantalla."
357-
}
361+
},
362+
"usage_updated": "La configuración de la pantalla se ha guardado."
358363
},
359364
"exit": {
360365
"section": "Terminar LBB",

scripts/lang/fr.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,6 @@
243243
},
244244
"display": {
245245
"section": "Filtrer",
246-
"activate_label": "Un écran est-il connecté et doit-il être utilisé ?",
247246
"connection_header": "Interface pour l'affichage",
248247
"connection_label": "Quelle interface utiliser ?",
249248
"i2c_address_label": "Adresse i2c de l'écran",
@@ -292,7 +291,12 @@
292291
"backlight_header": "Rétroéclairage de l'écran",
293292
"backlight_enabled_label": "Activer le rétroéclairage de l'écran (si disponible)",
294293
"backlight_pin_label": "Quelle broche GPIO (notation BCM) est connectée au rétroéclairage ?",
295-
"additional_settings_header": "Paramètres d'affichage supplémentaires"
294+
"additional_settings_header": "Paramètres d'affichage supplémentaires",
295+
"activate": {
296+
"display_label": "Un écran connecté au GPIO doit être utilisé.",
297+
"none_label": "Aucun affichage",
298+
"screen_label": "Un écran (ou écran tactile) connecté au GPIO doit être utilisé."
299+
}
296300
},
297301
"menu": {
298302
"enable_header": "Activer le menu d'affichage",
@@ -354,7 +358,8 @@
354358
"speed": {
355359
"header": "Vitesse de l’écran",
356360
"label": "Sélectionnez la vitesse à laquelle votre écran peut être piloté."
357-
}
361+
},
362+
"usage_updated": "La configuration de l’affichage a été enregistrée."
358363
},
359364
"exit": {
360365
"section": "Terminer LBB",

scripts/lib_comitup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def config(self, Password=''): # use general password if None is given
7373

7474
def dynamic_password(self):
7575
if self.__setup.get_val('conf_WIFI_PASSWORD_TYPE') != 'dynamic' or \
76-
not self.__setup.get_val('conf_DISP') or \
76+
not self.__setup.get_val('conf_DISP') == 'display' or \
7777
self.__setup.get_val('conf_DISP_RESOLUTION_X') < 64 or \
7878
self.__setup.get_val('conf_DISP_RESOLUTION_Y') < 64:
7979
return

scripts/lib_display.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def __init__(self):
5555
self.__start_display()
5656

5757
def __start_display(self):
58-
if self.conf_DISP and subprocess.run(f'sudo pgrep -fa "{self.WORKING_DIR}/display.p[y]" | grep -v "pgrep"', shell=True, stdout=subprocess.DEVNULL).returncode != 0:
58+
if self.conf_DISP == 'display' and subprocess.run(f'sudo pgrep -fa "{self.WORKING_DIR}/display.p[y]" | grep -v "pgrep"', shell=True, stdout=subprocess.DEVNULL).returncode != 0:
5959
# grep: returncode=1 if no matches found
6060
try:
6161
subprocess.run(f"sh -c 'sudo {self.python} {self.WORKING_DIR}/display.py &'", shell=True)
@@ -74,7 +74,7 @@ def message(self, RawLines, logging=True): # Lines = ['abc','def',...]
7474

7575
if Lines:
7676
# if display is disabled, write message into const_DISPLAY_CONTENT_OLD_FILE to prevent repeating IP message
77-
DisplayFilePath = os.path.join(self.const_DISPLAY_CONTENT_PATH,"{:014d}.txt".format(int(lib_system.get_uptime_sec()*100))) if self.conf_DISP else self.const_DISPLAY_CONTENT_OLD_FILE
77+
DisplayFilePath = os.path.join(self.const_DISPLAY_CONTENT_PATH,"{:014d}.txt".format(int(lib_system.get_uptime_sec()*100))) if self.conf_DISP == 'display' else self.const_DISPLAY_CONTENT_OLD_FILE
7878

7979
# write DisplayFile in any case to prevent repeting IP message
8080
for i in range (4):
@@ -121,7 +121,7 @@ def message(self, RawLines, logging=True): # Lines = ['abc','def',...]
121121
self.log.message(LogMessage)
122122

123123
def wait_for_empty_stack(self):
124-
if not self.conf_DISP:
124+
if self.conf_DISP != 'display':
125125
return(None)
126126

127127
while self.display_content_files.get_ContentFilesList():

0 commit comments

Comments
 (0)