-
Notifications
You must be signed in to change notification settings - Fork 3
/
Pioneer600.py
executable file
·326 lines (268 loc) · 7.41 KB
/
Pioneer600.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
#!/usr/bin/python
# -*- coding:utf-8 -*-
# Tayfun ULU
# 2016
import RPi.GPIO as GPIO
import smbus
import spidev as SPI
import SSD1306
import time
from BMP180 import BMP180
import Image
import ImageDraw
import ImageFont
import os
import fcntl
import struct
import add_module
from DovizKurlari import DovizKurlari
KEY = 20
address = 0x20
ana_menu = 1
son_menu = 1
def beep_on():
bus.write_byte(address,0x7F&bus.read_byte(address))
def beep_off():
bus.write_byte(address,0x80|bus.read_byte(address))
def led_off():
bus.write_byte(address,0x10|bus.read_byte(address))
def led_on():
bus.write_byte(address,0xEF&bus.read_byte(address))
def oled(bir,iki,ucst=""):
# Draw a black filled box to clear the image.
draw.rectangle((0,0,width,height), outline=0, fill=0)
draw.text((x, top),str(bir), font=font1, fill=255)
draw.text((x, top+20),str(iki), font=font2, fill=255)
draw.text((x, top+40),str(ucst), font=font2, fill=255)
disp.image(image)
disp.display()
def MyInterrupt(KEY):
print("KEY PRESS")
def menu ():
global deger
global son_menu
global ana_menu
if deger == "up" :
son_menu = son_menu - 1
elif deger == 'down' :
son_menu = son_menu + 1
elif deger == "right" :
ana_menu = ana_menu + 1
son_menu = 1
elif deger == "left" :
ana_menu = ana_menu -1
son_menu = 1
if ana_menu == 8:
ana_menu = 1
if ana_menu == 0:
ana_menu = 7
# if son_menu == 14:
# son_menu = 1
# if son_menu ==0:
# son_menu =13
temp = bmp.read_temperature()
pressure = bmp.read_pressure()
altitude = bmp.read_altitude()
#bilgiler
if ana_menu == 1 :
if son_menu == 3:
son_menu = 1
if son_menu ==0:
son_menu =2
if son_menu == 1:
oled("< 1.Time >",time.strftime('%X'))
elif son_menu == 2 :
oled("< 1.Date >",time.strftime('%x'))
# Sensor Verileri
elif ana_menu == 2 :
if son_menu == 4:
son_menu = 1
if son_menu ==0:
son_menu =3
if son_menu ==1:
oled("< 2.Info >","Temperature",(str(round(temp,2))+" C"))
elif son_menu ==2:
oled("< 2.Info >","Pressure",round(pressure,2))
elif son_menu ==3:
oled("< 2.Info >","Altitude",round(altitude,2))
# Cihaz bilgileri
elif ana_menu == 3:
if son_menu == 5:
son_menu = 1
if son_menu ==0:
son_menu =4
if son_menu == 1 :
oled("< 3.Rpi Info >","CPU Temperature=",(add_module.getCPUtemperature()+" C"))
elif son_menu == 2 :
oled("< 3.Rpi Info >","Free RAM",(str(int(add_module.getRAMinfo()[2])/1024)+" MB"))
elif son_menu == 3 :
oled("< 3.Rpi Info >","CPU Usage",(str(add_module.getCPUuse())+" %"))
elif son_menu == 4 :
oled("< 3.Rpi Info >","Disk Usage",add_module.getDiskSpace()[3])
# ipler
elif ana_menu == 4 :
if son_menu == 3:
son_menu = 1
if son_menu ==0:
son_menu =2
if son_menu == 1 :
oled("< 4. Rpi IP's >","WLAN0",add_module.get_ip_address('wlan0'))
elif son_menu == 2 :
oled("< 4. Rpi IP's >","ETH0",add_module.get_ip_address('eth0'))
#finansal
elif ana_menu == 5 :
if son_menu == 3:
son_menu = 1
if son_menu ==0:
son_menu =2
if son_menu == 1 :
oled("< 5. Exch Rate >","Dolar / TL",DovizKurlari().DegerSor("USD",4))
elif son_menu == 2 :
oled("< 5. Exch Rate >","Euro / TL",DovizKurlari().DegerSor("EUR",4))
#kodi
elif ana_menu == 6 :
if son_menu == 3:
son_menu = 1
if son_menu ==0:
son_menu =2
if son_menu == 1 :
oled("< 6. KODI >","Open Kodi","Press Button")
if GPIO.input(KEY) == 0:
os.popen('sudo kodi &')
elif son_menu == 2 :
oled("< 6. KODI >","Close Kodi","Press Button")
if GPIO.input(KEY) == 0:
os.popen('sudo pkill kodi')
#aç kapa
elif ana_menu == 7 :
if son_menu == 7:
son_menu = 1
if son_menu ==0:
son_menu =6
elif son_menu == 1 :
oled("< 7. System >","Close App","Press Button")
if GPIO.input(KEY) == 0:
exit ()
elif son_menu == 2 :
oled("< 7. System >","Restart","Press Button")
if GPIO.input(KEY) == 0:
os.popen('sudo reboot')
elif son_menu == 3 :
oled("< 7. System >","Halt System","Press Button")
if GPIO.input(KEY) == 0:
os.popen('sudo halt')
elif son_menu == 4 :
oled("< 7. System >","Startx","Press Button")
if GPIO.input(KEY) == 0:
os.popen('startx &')
elif son_menu == 5 :
oled("< 7. System >","App Update","Press Button")
if GPIO.input(KEY) == 0:
oled("< 7. System >","Update ...")
os.popen('sudo apt-get update')
oled("< 7. System >","Upgrade ...")
os.popen('sudo apt-get upgrade -y')
oled("< 7. System >","Bitti")
elif son_menu == 6 :
oled("< 7. System >","Rpi Update","Press Button")
if GPIO.input(KEY) == 0:
oled("< 7. System >","Update ...")
note=os.popen('sudo rpi-update')
note = note.read()
if note.find("Your firmware is already up to date") != -1 :
oled("< 7. System >","Up to date")
#print ("Güncel")
time.sleep(1)
else :
oled("< 7. System >","Done")
time.sleep(1)
else :
print ("wrong something")
return (son_menu)
# Raspberry Pi pin configuration:
RST = 19
# Note the following are only used with SPI:
DC = 16
bus = 0
device = 0
# 128x64 display with hardware SPI:
disp = SSD1306.SSD1306(RST, DC, SPI.SpiDev(bus,device))
# Initialize library.
disp.begin()
# Clear display.
disp.clear()
disp.display()
# Load image based on OLED display height. Note that image is converted to 1 bit color.
imageOpen = Image.open(os.path.dirname(os.path.realpath(__file__)) +"/pioneer600.bmp").convert('1')
imageClose = Image.open(os.path.dirname(os.path.realpath(__file__)) +"/pioneer600_close.bmp").convert('1')
# Alternatively load a different format image, resize it, and convert to 1 bit color.
#image = Image.open('happycat.png').resize((disp.width, disp.height), Image.ANTIALIAS).convert('1')
# Display image.
disp.image(imageOpen)
disp.display()
time.sleep(2)
# Create blank image for drawing.
# Make sure to create image with mode '1' for 1-bit color.
width = disp.width
height = disp.height
image = Image.new('1', (width, height))
# Get drawing object to draw on image.
draw = ImageDraw.Draw(image)
# Draw a black filled box to clear the image.
draw.rectangle((0,0,width,height), outline=0, fill=0)
# Draw some shapes.
# First define some constants to allow easy resizing of shapes.
padding = 1
top = padding
x = padding
# Load default font.
# font = ImageFont.load_default()
font_dir = os.path.dirname(os.path.realpath(__file__)) +"/KeepCalm-Medium.ttf"
font1 = ImageFont.truetype(font_dir, 15)
font2 = ImageFont.truetype(font_dir, 14)
GPIO.setmode(GPIO.BCM)
GPIO.setup(KEY,GPIO.IN,GPIO.PUD_UP)
#GPIO.add_event_detect(KEY,GPIO.FALLING,MyInterrupt,200)
bmp = BMP180()
bus = smbus.SMBus(1)
print("Pioneer600 Test Program !!!")
try:
while True:
bus.write_byte(address,0x0F|bus.read_byte(address))
value = bus.read_byte(address) | 0xF0
if value != 0xFF:
led_on()
if (value | 0xFE) != 0xFF:
deger="left"
elif (value | 0xFD) != 0xFF:
deger="up"
elif (value | 0xFB) != 0xFF:
deger="down"
else :
deger="right"
while value != 0xFF:
bus.write_byte(address,0x0F|bus.read_byte(address))
value = bus.read_byte(address) | 0xF0
time.sleep(0.01)
led_off()
son_menu=menu()
time.sleep(0.1)
deger="YOK"
son_menu=menu()
# for keyboard interrupt
except (KeyboardInterrupt, SystemExit):
print ("Keyboard Interrupt")
# Clear display.
disp.image(imageClose)
disp.display()
time.sleep(2)
disp.clear()
disp.display()
except:
print ("ERROR")
# Clear display.
disp.image(imageClose)
disp.display()
time.sleep(2)
disp.clear()
disp.display()