-
Notifications
You must be signed in to change notification settings - Fork 0
/
c_mainwindow.py
480 lines (409 loc) · 22.2 KB
/
c_mainwindow.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
import json
import random
import subprocess
import time
import qdarkstyle
from PyQt5.QtCore import Qt, QTimer
from PyQt5.QtWidgets import QApplication
from PyQt5.QtWidgets import QMainWindow, QFrame, QSplitter, QGridLayout, QWidget, QStackedLayout, QVBoxLayout
import utils.utils_file_access
import utils.utils_system
from FPGA_protocol.gamma import init_gamma_table_list, gamma_table_list, max_gamma_value
from FPGA_protocol.protocol2 import FPGACmdCenter, protocolDict, FPGAJsonParams, fpga_test_value
from ext_dev.c_lcd1602 import LCD1602
from fpga.fpga_clients import FPGAClient
from global_def import *
from media_engine.media_engine import MediaEngine
from media_engine.media_engine_def import TAG_PlayStatus_Dict
from ui.ui_cms_page import CMSPage
from ui.ui_fpga_list_page import FpgaListPage
from ui.ui_functions_frame import UiFuncFrame
from ui.ui_hdmi_in_page import HDMIInPage
from ui.ui_led_settings_page import LedSettingsPage
from ui.ui_media_files_page import MediaFilesPage
from ui.ui_sys_sw_info import UiSystemSoftware
from ui.ui_test_page import TestPage
from ui.ui_system_page import SystemPage
'''List of Page Selector Button Name '''
Page_Select_Btn_Name_List = ["FPGA_List", "Media_Files", "HDMI_In", "CMS", "Led_Settings", "System", "Test"]
Page_List = [FpgaListPage, MediaFilesPage, HDMIInPage, CMSPage, LedSettingsPage, SystemPage, TestPage]
Page_Map = dict(zip(Page_Select_Btn_Name_List, Page_List))
class MainUi(QMainWindow):
from _handle_qlocal_message import parser_cmd_from_qlocalserver, cmd_function_map
from _handle_brightness_by_time import check_brightness_by_date_timer, is_sleep_time, check_daymode_nightmode
'''frame brightness test log'''
brightness_test_log = False
def __init__(self):
log.debug("Venom Main Window Init!")
super().__init__()
eth_if_promisc_cmd = os.popen("ifconfig {} promisc".format(ETH_DEV))
eth_if_promisc_cmd.close()
utils.utils_file_access.set_os_environ()
utils.utils_file_access.check_and_rebuild_binaries()
if platform.machine() in ('arm', 'arm64', 'aarch64'):
# keep the screen on for cms
keep_screen_alive = os.popen("xset s off -dpms")
keep_screen_alive.close()
# open pulseaudio with root
pulseaudio_with_root = os.popen("pulseaudio -D")
pulseaudio_with_root.close()
# export DISPLAY
export_display = os.popen("export DISPLAY=:0")
export_display.close()
self.screen = QApplication.primaryScreen()
'''main 3 object in window '''
self.left_top_frame = None # page selector
self.left_bottom_frame = None # system and software information
self.splitter_left_vertical_frame = None # group of upon widgets
self.right_frame = None # multi pages of different functions(fpga receiver/media files/hdmi-in )
self.right_layout = None
self.left_top_frame_layout = None
self.left_bottom_frame_layout = None
self.ui_funcs_select_frame = None
self.ui_sys_sw_info_frame = None
''' each pages of right frame'''
self.right_frame_page_list = []
self.right_frame_page_index = 0
self.splitter_horizontal_frame = None # group of main window widgets
self.main_window_layout = None
self.main_window_widget = None
self.media_engine = MediaEngine()
self.media_engine.led_video_params.install_fpga_current_gain_changed_slot(self.fpga_current_gain_changed)
self.media_engine.led_video_params.install_fpga_gamma_index_changed_slot(self.fpga_gamma_index_changed)
self.media_engine.install_signal_media_engine_status_changed_slot(self.media_engine_status_changed)
''' Jason for test FPGA read/write '''
self.fpga_cmd_center = FPGACmdCenter(ETH_DEV, protocolDict["sourceAddress"])
self.fpga_cmd_center.set_fpga_id_broadcast(FPGA_START_ID)
''' fpga_list initial '''
self.fpga_json_data = []
self.fpga_total_num = self.get_fpga_total_num()
log.debug("self.fpga_total_num : %d", self.fpga_total_num)
self.fpga_list = []
for i in range(FPGA_START_ID, FPGA_START_ID + self.fpga_total_num):
fpga_tmp = FPGAClient(i, self.fpga_cmd_center)
self.fpga_list.append(fpga_tmp)
ret, str_value = self.fpga_cmd_center.read_fpga_register(2, FPGAJsonParams.params_list[0])
if ret == 0:
log.debug("read device ID from id2, ret : %d, str_value: %s", ret, str_value)
self.init_fpga_json_file()
self.init_ui_total()
log.debug("Init UI ok!")
self.right_frame_page_list[0].sync_clients_table(self.fpga_list)
# Do not set gamma table at first
# self.init_fpga_gamma()
# self.set_fpga_test_register()
for fpga in self.fpga_list:
fpga.fpga_cmd_center.write_fpga_register(fpga.i_id, 'currentGammaTable', str(22))
self.sleep_start_time, self.sleep_end_time = utils.utils_file_access.get_sleep_time_from_file()
log.debug("self.sleep_start_time = %s", self.sleep_start_time)
log.debug("self.sleep_end_time = %s", self.sleep_end_time)
self.i_sleep_start_time_hour = int(self.sleep_start_time.split(":")[0])
self.i_sleep_start_time_min = int(self.sleep_start_time.split(":")[1])
self.i_sleep_end_time_hour = int(self.sleep_end_time.split(":")[0])
self.i_sleep_end_time_min = int(self.sleep_end_time.split(":")[1])
self.date_timer = QTimer(self)
self.date_timer.timeout.connect(self.check_brightness_by_date_timer)
# self.date_timer.start(1*60*1000)
try:
self.date_timer.start(BRIGHTNESS_TIMER_INTERVAL)
except Exception as e:
log.debug(e)
self.lcd1602 = LCD1602("LCD_TAG_VERSION_INFO", "FPGA LED SERVER", Version, 5000)
self.lcd1602.start()
self.default_launch_type_int = 0
self.default_launch_params_str = ""
self.launch_default_type()
# test frame brightness adjust
# self.test_timer = QTimer(self)
# self.test_timer.timeout.connect(self.test_timer_function)
# self.test_timer.start(3*1000)
'''target_gamma_table_list = [
"gammaTable_r{}".format(str(0)),
"gammaTable_g{}".format(str(0)),
"gammaTable_b{}".format(str(0))
]
for fpga in self.fpga_list:
ret, reg_value = self.fpga_cmd_center.read_fpga_register(fpga.i_id, "gammaTable_r{}".format(str(0)))
# log.debug("%s : %s", "gammaTable_r{}".format(str(0)), str(reg_value))
ret, reg_value = self.fpga_cmd_center.read_fpga_register(fpga.i_id, "gammaTable_g{}".format(str(0)))
# log.debug("%s : %s", "gammaTable_g{}".format(str(0)), str(reg_value))
ret, reg_value = self.fpga_cmd_center.read_fpga_register(fpga.i_id, "gammaTable_b{}".format(str(0)))
# log.debug("%s : %s", "gammaTable_b{}".format(str(0)), str(reg_value))'''
def closeEvent(self, event):
log.debug("Close All Program!")
QApplication.closeAllWindows()
def launch_default_type(self):
try:
with open(os.getcwd() + "/static/default_launch_type.dat", "r") as launch_type_config_file:
tmp = launch_type_config_file.readline()
log.debug("launch_type_config : %s", tmp)
self.default_launch_type_int = int(tmp.split(":")[0])
self.default_launch_params_str = tmp.split(":")[1]
log.debug("self.default_launch_type_int : %d", self.default_launch_type_int)
log.debug("self.default_launch_params_str : %s", self.default_launch_params_str)
except Exception as e:
log.debug(e)
if self.default_launch_type_int == play_type.play_single:
try:
QTimer.singleShot(5000, self.demo_start_play_single)
except Exception as e:
log.debug(e)
elif self.default_launch_type_int == play_type.play_playlist:
try:
QTimer.singleShot(5000, self.demo_start_playlist)
except Exception as e:
log.debug(e)
elif self.default_launch_type_int == play_type.play_hdmi_in:
try:
QTimer.singleShot(5000, self.demo_start_hdmi_in)
except Exception as e:
log.debug(e)
elif self.default_launch_type_int == play_type.play_cms:
try:
QTimer.singleShot(5000, self.demo_start_cms)
except Exception as e:
log.debug(e)
def demo_start_play_single(self):
log.debug("demo_start_play_single")
for btn in self.ui_funcs_select_frame.btn_list:
log.debug("btn : %s", btn.text())
if btn.text() == 'Media_Files':
btn.click()
break
file_uri = internal_media_folder + '/' + self.default_launch_params_str
res = self.media_engine.get_video_resolution(file_uri)
if res is not None:
_active_width, _active_height = res
self.media_engine.single_play(file_uri, active_width=_active_width, active_height=_active_height)
def demo_start_playlist(self):
log.debug("demo_start_playlist")
for btn in self.ui_funcs_select_frame.btn_list:
log.debug("btn : %s", btn.text())
if btn.text() == 'Media_Files':
btn.click()
break
playlist = internal_media_folder + PlaylistFolder + self.default_launch_params_str
self.media_engine.play_playlist(playlist)
def demo_start_hdmi_in(self):
log.debug("demo_start_hdmi_in")
for btn in self.ui_funcs_select_frame.btn_list:
log.debug("btn : %s", btn.text())
if btn.text() == 'HDMI_In':
btn.click()
break
# self.media_engine.hdmi_in_play()
def demo_start_cms(self):
log.debug("demo_start_cms")
for btn in self.ui_funcs_select_frame.btn_list:
log.debug("btn : %s", btn.text())
if btn.text() == 'CMS':
btn.click()
break
self.right_frame_page_list[3].cms_start_btn.click()
def utc_test(self):
log.debug("self.utc_test_count : %d", self.utc_test_count)
self.utc_test_count += 1
s_utc_temp = str(random.randint(1000, 9999))
for i in range(2, 4): # send cmd to id 2/3
start_time = time.time()
ret = self.fpga_cmd_center.write_fpga_register(i, "UTC", s_utc_temp)
log.debug("write time : %f", time.time() - start_time)
log.debug("write fpga id:%d UTC ret : %d", i, ret)
for i in range(2, 4): # read cmd to id 2/3
start_time = time.time()
ret, id_utc = self.fpga_cmd_center.read_fpga_register(i, "UTC")
log.debug("read time : %f", time.time() - start_time)
# log.debug("read fpga id:%d UTC ret : %d, id%d_UTC : %s", i, ret, i, id_utc)
# log.debug("len(s_utc_temp) : %d", len(s_utc_temp))
# log.debug("len(id2_utc) : %d", len(str(id2_utc)))
if ret == 0:
if s_utc_temp == str(id_utc):
log.debug("read OK")
else:
log.debug("UTC read/write failed!")
else:
log.debug("UTC read/write failed!")
def init_ui_total(self):
self.setWindowTitle("GIS FPGA LED Server " + Version )
self.setWindowOpacity(1.0) # 窗口透明度
self.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5())
log.debug("self.screen.size() : %s", self.screen.size())
self.resize(self.screen.size())
self.left_top_frame = QFrame(self)
self.left_top_frame_layout = QVBoxLayout()
self.left_top_frame.setLayout(self.left_top_frame_layout)
self.left_bottom_frame = QFrame(self)
self.left_bottom_frame_layout = QVBoxLayout()
self.left_bottom_frame.setLayout(self.left_bottom_frame_layout)
self.right_frame = QFrame(self) # right frame with stack layout
self.splitter_left_vertical_frame = QSplitter(Qt.Vertical)
self.splitter_left_vertical_frame.addWidget(self.left_top_frame)
self.splitter_left_vertical_frame.addWidget(self.left_bottom_frame)
self.splitter_horizontal_frame = QSplitter(Qt.Horizontal)
self.splitter_horizontal_frame.addWidget(self.splitter_left_vertical_frame)
self.splitter_horizontal_frame.addWidget(self.right_frame)
self.main_window_layout = QGridLayout()
self.main_window_layout.addWidget(self.splitter_horizontal_frame)
self.main_window_widget = QWidget(self)
self.main_window_widget.setLayout(self.main_window_layout)
self.setCentralWidget(self.main_window_widget)
''' handle right frame layout '''
self.right_layout = QStackedLayout()
self.right_frame.setLayout(self.right_layout)
self.init_system_and_software_info()
self.init_page_selector()
'''Initial each page in stack layout of right frame'''
self.init_pages_on_right_frame()
self.right_layout.setCurrentIndex(0)
def init_page_selector(self):
self.ui_funcs_select_frame = UiFuncFrame(self, self.left_top_frame,
Page_Select_Btn_Name_List,
self.slot_right_frame_page_changed)
def init_system_and_software_info(self):
self.ui_sys_sw_info_frame = UiSystemSoftware(self, self.left_bottom_frame)
def init_pages_on_right_frame(self):
for k, v in Page_Map.items():
if k == "FPGA_List" or k == "Led_Settings":
page = v(self, self.right_frame, k, media_engine=self.media_engine, fpga_list=self.fpga_list)
elif k == "Test":
page = v(self, self.right_frame, k, media_engine=self.media_engine,
fpga_cmd_center=self.fpga_cmd_center, fpga_list=self.fpga_list)
else:
page = v(self, self.right_frame, k, media_engine=self.media_engine)
self.right_frame_page_list.append(page)
self.right_layout.addWidget(page)
def slot_right_frame_page_changed(self, tag: str):
log.debug("tag : %s", tag)
try:
for i in range(len(self.right_frame_page_list)):
if self.right_frame_page_list[i].name == tag:
self.right_layout.setCurrentIndex(i)
self.right_frame_page_index = i
break
except Exception as e:
log.error(e)
def get_fpga_total_num(self):
num = 0
for i in range(FPGA_START_ID, 255):
ret, id_utc = self.fpga_cmd_center.read_fpga_register(i, "UTC")
if ret != 0:
num = i - 2
break
log.debug("fpga num : %d", num)
return num
def get_fpga_panel_way(self):
for i in range(FPGA_START_ID, FPGA_START_ID + self.fpga_total_num):
ret, i_panel_way = self.fpga_cmd_center.read_fpga_register(i, "panelWay")
log.debug("id : %d, i_panel_way : %d", ret, i_panel_way)
@staticmethod
def load_fpga_json_file():
log.debug("load_fpga_json_file")
with open(os.getcwd() + "/ori_dataFPGA.json", "r") as jsonFile:
python_dict = json.load(fp=jsonFile)
log.debug("python_dict : %s", python_dict)
# print("type(python_dict) : ", type(python_dict))
python_dict["fpgaID"][2]["UTC"] = str(1111)
log.debug("python_dict : %s", python_dict)
def init_fpga_json_file(self):
data = dict()
data["frameWidth"] = '0'
data["frameHeight"] = '0'
data["softwareVersion"] = 'LC_G3_240220_D1'
data["lcdVersion"] = 'LS240305001'
data["fpgaID"] = []
params = {}
for i in range(FPGA_START_ID, FPGA_START_ID + self.fpga_total_num):
params = {}
for j in range(len(FPGAJsonParams.params_list)):
log.debug("read id: %d, %s", i, FPGAJsonParams.params_list[j])
if FPGAJsonParams.params_list[j] == "stringVersion":
ret, reg_value = self.fpga_cmd_center.read_fpga_register_bytes(
i, FPGAJsonParams.params_list[j])
if ret == 0:
str_value = reg_value.decode().replace('\u0000', '')
for fpga in self.fpga_list:
if fpga.i_id == i:
fpga.set_version(str_value)
else:
str_value = "unknown"
else:
ret, str_value = self.fpga_cmd_center.read_fpga_register(i, FPGAJsonParams.params_list[j])
if ret == 0:
params[FPGAJsonParams.params_list[j]] = str_value
else:
params[FPGAJsonParams.params_list[j]] = "unknown"
data["fpgaID"].append(params)
params = None
with open("dataFPGA.json", "w") as jsonFile:
json.dump(data, jsonFile, indent=2)
log.debug('write json')
def set_fpga_test_register(self):
for i in range(FPGA_START_ID, FPGA_START_ID + len(self.fpga_list)):
for test_item, value in fpga_test_value[i - 2].items():
if value is not None:
ret = self.fpga_cmd_center.write_fpga_register(i, test_item, value)
if ret < 0:
log.debug("write register failed!")
if i == 2:
for n in range(0, 4):
self.fpga_cmd_center.write_fpga_register(i, 'numberOfPixel_p{}'.format(str(n)), str(960))
self.fpga_cmd_center.write_fpga_register(i, 'startX_p{}'.format(str(n)), str(159))
self.fpga_cmd_center.write_fpga_register(i, 'startY_p{}'.format(str(n)), str(48 - ((n + 1) * 12)))
self.fpga_cmd_center.write_fpga_register(i, 'portWidth_p{}'.format(str(n)), str(80))
self.fpga_cmd_center.write_fpga_register(i, 'portHeight_p{}'.format(str(n)), str(12))
elif i == 3:
for n in range(0, 4):
self.fpga_cmd_center.write_fpga_register(i, 'numberOfPixel_p{}'.format(str(n)), str(960))
self.fpga_cmd_center.write_fpga_register(i, 'startX_p{}'.format(str(n)), str(0))
self.fpga_cmd_center.write_fpga_register(i, 'startY_p{}'.format(str(n)), str((n * 12) + 11))
self.fpga_cmd_center.write_fpga_register(i, 'portWidth_p{}'.format(str(n)), str(80))
self.fpga_cmd_center.write_fpga_register(i, 'portHeight_p{}'.format(str(n)), str(12))
def init_fpga_gamma(self):
init_gamma_table_list()
# print("gamma_table_list[22] : ", gamma_table_list[22])
log.debug("len(gamma_table_list[22]) : %d", len(gamma_table_list[22]))
for fpga in self.fpga_list:
# for gamma_index in range(max_gamma_value):
for gamma_index in range(max_gamma_value):
if gamma_index < 2:
fpga.fpga_cmd_center.write_fpga_register_with_bytes(fpga.i_id,
'gammaTable_r{}'.format(str(gamma_index)),
gamma_table_list[22])
fpga.fpga_cmd_center.write_fpga_register_with_bytes(fpga.i_id,
'gammaTable_g{}'.format(str(gamma_index)),
gamma_table_list[22])
fpga.fpga_cmd_center.write_fpga_register_with_bytes(fpga.i_id,
'gammaTable_b{}'.format(str(gamma_index)),
gamma_table_list[22])
else:
fpga.fpga_cmd_center.write_fpga_register_with_bytes(fpga.i_id,
'gammaTable_r{}'.format(str(gamma_index)),
gamma_table_list[gamma_index])
fpga.fpga_cmd_center.write_fpga_register_with_bytes(fpga.i_id,
'gammaTable_g{}'.format(str(gamma_index)),
gamma_table_list[gamma_index])
fpga.fpga_cmd_center.write_fpga_register_with_bytes(fpga.i_id,
'gammaTable_b{}'.format(str(gamma_index)),
gamma_table_list[gamma_index])
def fpga_current_gain_changed(self):
''' check video params and send cmd to fpga '''
''' check r/g/b/ current gain '''
if self.media_engine.led_video_params.get_icled_type() == icled_type.anapex:
''' set current gain '''
log.debug("anapex set current gain")
i_r_gain_value = int(self.media_engine.led_video_params.get_led_red_gain())
i_g_gain_value = int(self.media_engine.led_video_params.get_led_green_gain())
i_b_gain_value = int(self.media_engine.led_video_params.get_led_blue_gain())
i_current_gain_value = i_r_gain_value << 16 | i_g_gain_value << 8 | i_b_gain_value
for fpga in self.fpga_list:
fpga.fpga_cmd_center.write_fpga_register(fpga.i_id, "currentGain",
str(i_current_gain_value))
def fpga_gamma_index_changed(self):
''' set fpga gamma '''
log.debug("fpga_gamma_index_changed")
for fpga in self.fpga_list:
fpga.fpga_cmd_center.write_fpga_register(fpga.i_id, 'currentGammaTable',
str(int(self.media_engine.led_video_params.get_led_gamma()*10)))
def media_engine_status_changed(self, status: int, play_src: str):
log.debug("status : %s, play_src : %s", TAG_PlayStatus_Dict.get(status), play_src)
self.lcd1602.add_data("media_engine_status", TAG_PlayStatus_Dict.get(status), play_src)