]>
Commit | Line | Data |
---|---|---|
1 | #! /usr/bin/env python | |
2 | # This file is part of Project CoBolD. | |
3 | # | |
4 | # Project CoBolD is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License | |
5 | # as published by the Free Software Foundation, # either version 3 of the License, or (at your option) any later version. | |
6 | # | |
7 | # Project CoBolD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | |
8 | # without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
9 | # See the GNU General Public License for more details. | |
10 | # | |
11 | # You should have received a copy of the GNU General Public License along with Project CoBolD. If not, see <http://www.gnu.org/licenses/>. | |
12 | # | |
13 | # Author: Permondes | |
14 | # | |
15 | # Version: 0.0 | |
16 | ||
17 | import gi | |
18 | gi.require_version("Gtk", "3.0") | |
19 | from gi.repository import Gtk, Gdk | |
20 | from gpio import gpio | |
21 | ||
22 | # definition of GPIO5-Pins | |
23 | # key: pin-number | |
24 | # values: usable, class, tooltip | |
25 | gpio5 = {'GPIO5_1':[False, 'gpio3v3', '+3.3V'], | |
26 | 'GPIO5_2':[False, 'gpio5v', '+5V'], | |
27 | 'GPIO5_3':[False, 'gpioDNU', 'UEXT2-SDA'], | |
28 | 'GPIO5_4':[False, 'gpio5v', '+5V'], | |
29 | 'GPIO5_5':[False, 'gpioDNU', 'UEXT2-SCL'], | |
30 | 'GPIO5_6':[False, 'gpioGND', 'GND'], | |
31 | 'GPIO5_7':[True, 'gpioPinNotInitialized', 'PI15'], | |
32 | 'GPIO5_8':[False, 'gpioDNU', 'UART3-RX'], | |
33 | 'GPIO5_9':[False, 'gpioGND', 'GND'], | |
34 | 'GPIO5_10':[False, 'gpioDNU', 'UART3-TX'], | |
35 | 'GPIO5_11':[True, 'gpioPinNotInitialized', 'PI11'], | |
36 | 'GPIO5_12':[True, 'gpioPinNotInitialized', 'PI3'], | |
37 | 'GPIO5_13':[True, 'gpioPinNotInitialized', 'PI10'], | |
38 | 'GPIO5_14':[False, 'gpioGND', 'GND'], | |
39 | 'GPIO5_15':[True, 'gpioPinNotInitialized', 'PI7'], | |
40 | 'GPIO5_16':[True, 'gpioPinNotInitialized', 'PE6'], | |
41 | 'GPIO5_17':[False, 'gpio3v3', '+3.3V'], | |
42 | 'GPIO5_18':[True, 'gpioPinNotInitialized', 'PE5'], | |
43 | 'GPIO5_19':[False, 'gpioDNU', 'SPI2-MOSI'], | |
44 | 'GPIO5_20':[False, 'gpioGND', 'GND'], | |
45 | 'GPIO5_21':[False, 'gpioDNU', 'SPI2-MISO'], | |
46 | 'GPIO5_22':[True, 'gpioPinNotInitialized', 'PE4'], | |
47 | 'GPIO5_23':[False, 'gpioDNU', 'SPI2-SCK'], | |
48 | 'GPIO5_24':[False, 'gpioDNU', 'SPI2-CSO'], | |
49 | 'GPIO5_25':[False, 'gpioGND', 'GND'], | |
50 | 'GPIO5_26':[True, 'gpioPinNotInitialized', 'PH14'], | |
51 | 'GPIO5_27':[False, 'gpioDNU', 'UEXT1-SDA'], | |
52 | 'GPIO5_28':[False, 'gpioDNU', 'UEXT1-SCL'], | |
53 | 'GPIO5_29':[True, 'gpioPinNotInitialized', 'PE1'], | |
54 | 'GPIO5_30':[False, 'gpioGND', 'GND'], | |
55 | 'GPIO5_31':[True, 'gpioPinNotInitialized', 'PE8'], | |
56 | 'GPIO5_32':[True, 'gpioPinNotInitialized', 'PH13'], | |
57 | 'GPIO5_33':[True, 'gpioPinNotInitialized', 'PE9'], | |
58 | 'GPIO5_34':[False, 'gpioGND', 'GND'], | |
59 | 'GPIO5_35':[True, 'gpioPinNotInitialized', 'PE10'], | |
60 | 'GPIO5_36':[True, 'gpioPinNotInitialized', 'PH12'], | |
61 | 'GPIO5_37':[True, 'gpioPinNotInitialized', 'PE11'], | |
62 | 'GPIO5_38':[True, 'gpioPinNotInitialized', 'PH11'], | |
63 | 'GPIO5_39':[False, 'gpioGND', 'GND'], | |
64 | 'GPIO5_40':[True, 'gpioPinNotInitialized', 'PH10'] } | |
65 | ||
66 | class Handler: | |
67 | def initGPIO5(self, *args): | |
68 | ''' Initialize GPIO-5 ''' | |
69 | result = gpio.init() #Initialize module. Always called first | |
70 | ||
71 | if result < 0: # error | |
72 | statusErrorMessage('Error Initializing GPIO-5: %d' %result) | |
73 | ||
74 | else: # init the GPIO buttons | |
75 | for button, characteristics in gpio5.items(): | |
76 | button_object = builder.get_object(button) | |
77 | button_object.set_sensitive(characteristics[0]) | |
78 | ||
79 | button_context = button_object.get_style_context() | |
80 | button_context.add_class(characteristics[1]) | |
81 | ||
82 | button_object.set_tooltip_text(characteristics[2]) | |
83 | ||
84 | # deactivate init button as it has served its purpose | |
85 | builder.get_object('Init_GPIO5').set_sensitive(False) | |
86 | # all done | |
87 | statusMessage('GPIO-5 initialized') | |
88 | ||
89 | def onDestroy(self, *args): | |
90 | ''' close and clean up all ports ''' | |
91 | Gtk.main_quit() | |
92 | ||
93 | ||
94 | def initCoBolD(): | |
95 | ''' Prepare the base panel''' | |
96 | # deactivate not yet implemented functions | |
97 | for button in ["Audio_In", "Audio_Out", "CAN", "UEXT1", "UEXT2"]: | |
98 | builder.get_object(button).set_sensitive(False) | |
99 | ||
100 | # Statusbar Handling | |
101 | # | |
102 | def statusPush(message, statusclass): | |
103 | '''send Message to Statusline''' | |
104 | statusbar = builder.get_object('statusbar') | |
105 | context = statusbar.get_context_id("statusbar") | |
106 | style_context = statusbar.get_style_context() | |
107 | style_context.remove_class('statusbarMessage') | |
108 | style_context.remove_class('statusbarWarning') | |
109 | style_context.remove_class('statusbarError') | |
110 | style_context.add_class(statusclass) | |
111 | statusbar.push(context, message) | |
112 | # print(style_context.list_classes()) | |
113 | ||
114 | def statusMessage(message): | |
115 | '''send Message to Statusline''' | |
116 | statusPush(message,'statusbarMessage') | |
117 | ||
118 | def statusWarning(message): | |
119 | '''send Warning to Statusline''' | |
120 | statusPush(message,'statusbarWarning') | |
121 | ||
122 | def statusErrorMessage(message): | |
123 | ''' send Errormessage to Statusline''' | |
124 | statusPush(message,'statusbarError') | |
125 | ||
126 | def statusClear(): | |
127 | ''' Clear Statusline''' | |
128 | statusMessage('') | |
129 | ||
130 | # Main program | |
131 | builder = Gtk.Builder() | |
132 | builder.add_from_file("CoBolD_Base.glade") | |
133 | builder.connect_signals(Handler()) | |
134 | ||
135 | css_provider = Gtk.CssProvider() | |
136 | css_provider.load_from_path('cobold.css') | |
137 | Gtk.StyleContext().add_provider_for_screen(Gdk.Screen.get_default(), css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION) | |
138 | ||
139 | window = builder.get_object("cobold_panel") | |
140 | window.show_all() | |
141 | initCoBolD() | |
142 | Gtk.main() |