Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import RPi.GPIO as GPIO
- import time
- import psutil
- import datetime
- import math
- runcount = 0
- sd = ""
- hdd = ""
- LCD_CS = 2
- LCD_RST = 3
- LCD_A0 = 4
- LCD_CLK = 27
- LCD_SI = 17
- def main():
- global runcount
- global sd
- global hdd
- global hdd2
- date = datetime.date.today().strftime("%m/%d/%Y")
- time = datetime.datetime.now()
- time = str("%02d" % time.hour) + ":" + str("%02d" % time.minute) + ":" + str("%02d" % time.second)
- cpu_perc = psutil.cpu_percent(interval=1)
- #cpu_perc = str(cpu_perc)
- cpu_perc = math.ceil(cpu_perc)
- cpu = ""
- per = 0
- for i in range(40):
- if (cpu_perc >= 0):
- cpu+=str(chr(127))
- per+=1
- else:
- cpu+=str(chr(128))
- cpu_perc -= 2.5
- i = 0
- #print per
- ram_perc = psutil.virtual_memory().percent
- #ram_perc = str(ram_perc.percent)
- ram_perc = math.ceil(ram_perc)
- ram = ""
- per = 0
- for i in range(40):
- if (ram_perc >= 0):
- ram+=str(chr(127))
- per+=1
- else:
- ram+=str(chr(128))
- ram_perc -= 2.5
- i = 0
- #print per
- if (runcount == 30):
- sd_perc = psutil.disk_usage('/').percent
- #sd_perc = str(sd_perc.percent)
- sd_perc = math.ceil(sd_perc)
- sd = ""
- per = 0
- for i in range(40):
- if (sd_perc >= 0):
- sd+=str(chr(127))
- per+=1
- else:
- sd+=str(chr(128))
- sd_perc -= 2.5
- i = 0
- #print per
- hdd_perc = psutil.disk_usage('/media/Network/').percent
- #hdd_perc = str(hdd_perc.percent)
- hdd_perc = math.ceil(hdd_perc)
- hdd = ""
- per = 0
- for i in range(40):
- if (hdd_perc >= 0):
- hdd+=str(chr(127))
- per+=1
- else:
- hdd+=str(chr(128))
- hdd_perc -= 2.5
- i = 0
- hdd2_perc = psutil.disk_usage('/media/_Network2/').percent
- hdd2_perc = math.ceil(hdd2_perc)
- hdd2 = ""
- per = 0
- for i in range(40):
- if (hdd2_perc >= 0):
- hdd2+=str(chr(127))
- per+=1
- else:
- hdd2+=str(chr(128))
- hdd2_perc -= 2.5
- i = 0
- #print per
- runcount = 1
- if (runcount == 0):
- for i in range(40):
- sd = " --WAIT-- "
- hdd = " --WAIT-- "
- hdd2 = " --WAIT-- "
- #lcd_ascii168_string(0,0," ")
- lcd_ascii168_string(0,0,date)
- #print date + " " + time
- #lcd_ascii168_string(0,1," ")
- lcd_ascii168_string(0,1,time)
- lcd_ascii168_string(0,2," ")
- #lcd_ascii168_string(0,3," ")
- lcd_ascii168_string(0,3,"CPU [" + cpu + "]")
- #print "CPU [" + cpu + "]"
- #lcd_ascii168_string(0,4," ")
- lcd_ascii168_string(0,4,"RAM [" + ram + "]")
- #print "RAM [" + ram + "]"
- #lcd_ascii168_string(0,5," ")
- lcd_ascii168_string(0,5,"/ [" + sd + "]")
- #print "/ [" + sd + "]"
- #lcd_ascii168_string(0,6," ")
- lcd_ascii168_string(0,6,"Z:/ [" + hdd + "]")
- #print "Z:/ [" + hdd + "]"
- lcd_ascii168_string(0,7,"X:/ [" + hdd2 +"]")
- def io_init():
- GPIO.setmode(GPIO.BCM)
- GPIO.setwarnings(False)
- GPIO.setup(LCD_CS, GPIO.OUT)
- GPIO.setup(LCD_RST, GPIO.OUT)
- GPIO.setup(LCD_A0, GPIO.OUT)
- GPIO.setup(LCD_CLK, GPIO.OUT)
- GPIO.setup(LCD_SI, GPIO.OUT)
- def lcd_init():
- GPIO.output(LCD_CS, True)
- GPIO.output(LCD_RST, False)
- GPIO.output(LCD_RST, True)
- lcd_transfer_data(0xe2,0); #internal reset
- lcd_transfer_data(0xa2,0); #voltage bias
- lcd_transfer_data(0xa0,0); #ram address seg output
- lcd_transfer_data(0xcf,0); #scan direction
- lcd_transfer_data(0xa4,0); #display all points
- lcd_transfer_data(0xa6,0); #normal/reverse
- lcd_transfer_data(0x2f,0); #internal power
- lcd_transfer_data(0x60,0); #start line
- lcd_transfer_data(0x20,0); #contrast 20-27
- lcd_transfer_data(0x81,0); #electronic volume
- lcd_transfer_data(0x31,0); #Contrast Control
- lcd_transfer_data(0xaf,0); #display on/off
- lcd_clear()
- def lcd_picture(xPos, yPos, char):
- for i in range(0, 8):
- lcd_set_page(yPos+i,xPos)
- for j in range(129*i, 128*(i+1)):
- lcd_transfer_data(PICTURE[char][j],1)
- def lcd_ascii168_string(xPos, yPos, string):
- stringLen = len(string)
- xchar = xPos
- for i in range(0, stringLen):
- xPos_i = xPos+i*8
- lcd_ascii168(xchar,yPos,ord(string[i])-32)
- char = ord(string[i])-32
- char = len(ASCII168[char])
- xchar = xchar + char
- def lcd_ascii168(xPos, yPos, char):
- lcd_set_page(yPos,xPos)
- x = len(ASCII168[char])
- for i in range(x):
- lcd_transfer_data(ASCII168[char][i],1)
- def lcd_clear():
- GPIO.output(LCD_CS, False)
- for i in range(0, 8):
- lcd_set_page(i,0)
- for j in range(0, 129):
- lcd_transfer_data(0x00,1)
- GPIO.output(LCD_CS, True)
- def lcd_set_page(page, column):
- lsb = column & 0x0f
- msb = column & 0xf0
- msb = msb>>4
- msb = msb | 0x10
- page = page | 0xb0
- lcd_transfer_data(page,0)
- lcd_transfer_data(msb,0)
- lcd_transfer_data(lsb,0)
- def lcd_transfer_data(value, SI):
- GPIO.output(LCD_CS, False)
- GPIO.output(LCD_CLK, True)
- if(SI):
- GPIO.output(LCD_A0, True)
- else:
- GPIO.output(LCD_A0, False)
- lcd_byte(value)
- GPIO.output(LCD_CS, True)
- def lcd_byte(bits):
- tmp = bits;
- #file = open("/home/pi/screen/io_log.log", "a")
- for i in range(0, 8):
- GPIO.output(LCD_CLK, False)
- if(tmp & 0x80):
- GPIO.output(LCD_SI, True)
- #file.write("1")
- else:
- GPIO.output(LCD_SI, False)
- #file.write("0")
- tmp = (tmp<<1)
- GPIO.output(LCD_CLK, True)
- #file.close()
- ASCII168=(
- (0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00),#" ",0
- (0x00,0x00,0x00,0x5f,0x5f,0x00,0x00,0x00),#"!",1
- (0x00,0x07,0x07,0x00,0x07,0x07,0x00,0x00),#""",2
- (0x00,0x14,0x7f,0x7f,0x14,0x7f,0x7f,0x14),#"#",3
- (0x00,0x24,0x2e,0x6a,0x7f,0x2b,0x3a,0x12),#"$",4
- (0x00,0x23,0x33,0x18,0x0c,0x66,0x62,0x00),#"%",5
- (0x00,0x36,0x7f,0x49,0x5f,0x36,0x60,0x50),#"&",6
- (0x00,0x00,0x80,0xe0,0x60,0x00,0x00,0x00),#",",7
- (0x00,0x00,0x1c,0x3e,0x63,0x41,0x00,0x00),#"(",8
- (0x00,0x00,0x41,0x63,0x3e,0x1c,0x00,0x00),#")",9
- (0x00,0x14,0x1c,0x3e,0x3e,0x1c,0x14,0x00),#"*",10
- (0x00,0x08,0x08,0x3e,0x3e,0x08,0x08,0x00),#"+",11
- (0x00,0x00,0x80,0xe0,0x60,0x00,0x00,0x00),#",",12
- (0x00,0x08,0x08,0x08,0x08,0x08,0x08,0x00),#"-",13
- (0x00,0x00,0x00,0x60,0x60,0x00,0x00,0x00),#".",14
- (0x00,0x20,0x30,0x18,0x0c,0x06,0x02,0x00),#"/",15
- (0x00,0x3e,0x7f,0x59,0x4d,0x7f,0x3e,0x00),#"0",16
- (0x00,0x40,0x42,0x7f,0x7f,0x40,0x40,0x00),#"1",17
- (0x00,0x42,0x63,0x71,0x59,0x4f,0x46,0x00),#"2",18
- (0x00,0x22,0x63,0x49,0x49,0x7f,0x36,0x00),#"3",19
- (0x00,0x18,0x1c,0x16,0x7f,0x7f,0x10,0x00),#"4",20
- (0x00,0x27,0x67,0x45,0x45,0x7d,0x39,0x00),#"5",21
- (0x00,0x3c,0x7e,0x4b,0x49,0x79,0x30,0x00),#"6",22
- (0x00,0x01,0x71,0x79,0x0d,0x07,0x03,0x00),#"7",23
- (0x00,0x36,0x7f,0x49,0x49,0x7f,0x36,0x00),#"8",24
- (0x00,0x06,0x4f,0x49,0x69,0x3f,0x1e,0x00),#"9",25
- (0x00,0x00,0x00,0x6c,0x6c,0x00,0x00,0x00),#":",26
- (0x00,0x00,0x80,0xec,0x6c,0x00,0x00,0x00),#";",27
- (0x00,0x08,0x1c,0x36,0x63,0x41,0x00,0x00),#"<",28
- (0x00,0x14,0x14,0x14,0x14,0x14,0x14,0x00),#"=",29
- (0x00,0x00,0x41,0x63,0x36,0x1c,0x08,0x00),#">",30
- (0x00,0x02,0x03,0x59,0x5d,0x07,0x02,0x00),#"?",31
- (0x00,0x3e,0x7f,0x41,0x5d,0x57,0x1e,0x00),#"@",32
- (0x00,0x7e,0x7f,0x09,0x09,0x7f,0x7e,0x00),#"A",33
- (0x00,0x7f,0x7f,0x49,0x49,0x7f,0x36,0x00),#"B",34
- (0x00,0x3e,0x7f,0x41,0x41,0x63,0x22,0x00),#"C",35
- (0x00,0x7f,0x7f,0x41,0x63,0x3e,0x1c,0x00),#"D",36
- (0x00,0x7f,0x7f,0x49,0x49,0x49,0x41,0x00),#"E",37
- (0x00,0x7f,0x7f,0x09,0x09,0x09,0x01,0x00),#"F",38
- (0x00,0x3e,0x7f,0x41,0x49,0x7b,0x3a,0x00),#"G",39
- (0x00,0x7f,0x7f,0x08,0x08,0x7f,0x7f,0x00),#"H",40
- (0x00,0x41,0x41,0x7f,0x7f,0x41,0x41,0x00),#"I",41
- (0x00,0x20,0x61,0x41,0x7f,0x3f,0x01,0x00),#"J",42
- (0x00,0x7f,0x7f,0x1c,0x36,0x63,0x41,0x00),#"K",43
- (0x00,0x7f,0x7f,0x40,0x40,0x40,0x40,0x00),#"L",44
- (0x00,0x7f,0x7f,0x06,0x1c,0x06,0x7f,0x7f),#"M",45
- (0x00,0x7f,0x7f,0x0c,0x18,0x7f,0x7f,0x00),#"N",46
- (0x00,0x3e,0x7f,0x41,0x41,0x7f,0x3e,0x00),#"O",47
- (0x00,0x7f,0x7f,0x09,0x09,0x0f,0x06,0x00),#"P",48
- (0x00,0x3e,0x7f,0x41,0x31,0x6f,0x5e,0x00),#"Q",49
- (0x00,0x7f,0x7f,0x09,0x19,0x7f,0x66,0x00),#"R",50
- (0x00,0x26,0x6f,0x49,0x49,0x7b,0x32,0x00),#"S",51
- (0x00,0x01,0x01,0x7f,0x7f,0x01,0x01,0x00),#"T",52
- (0x00,0x3f,0x7f,0x40,0x40,0x7f,0x3f,0x00),#"U",53
- (0x00,0x1f,0x3f,0x60,0x60,0x3f,0x1f,0x00),#"V",54
- (0x00,0x7f,0x7f,0x30,0x1c,0x30,0x7f,0x7f),#"W",55
- (0x00,0x63,0x77,0x1c,0x1c,0x77,0x63,0x00),#"X",56
- (0x00,0x07,0x0f,0x78,0x78,0x0f,0x07,0x00),#"Y",57
- (0x00,0x61,0x71,0x59,0x4d,0x47,0x43,0x00),#"Z",58
- (0x00,0x7f,0x7f,0x41,0x41,0x41,0x00,0x00),#"[",59
- (0x00,0x20,0x30,0x18,0x0c,0x06,0x02,0x00),#"/",60
- (0x00,0x00,0x41,0x41,0x41,0x7f,0x7f,0x00),#"]",61
- (0x00,0x02,0x03,0x01,0x01,0x03,0x02,0x00),#"^",62
- (0x00,0x08,0x08,0x08,0x08,0x08,0x08,0x00),#"-",63
- (0x00,0x02,0x06,0x0c,0x18,0x30,0x20,0x00),#"\",64
- (0x00,0x78,0x7c,0x14,0x14,0x7c,0x78,0x00),#"a",65
- (0x00,0x7c,0x7c,0x54,0x54,0x7c,0x28,0x00),#"b",66
- (0x00,0x38,0x7c,0x44,0x44,0x6c,0x28,0x00),#"c",67
- (0x00,0x7c,0x7c,0x44,0x44,0x7c,0x38,0x00),#"d",68
- (0x00,0x7c,0x7c,0x54,0x54,0x54,0x44,0x00),#"e",69
- (0x00,0x7c,0x7c,0x14,0x14,0x04,0x00,0x00),#"f",70
- (0x00,0x38,0x7c,0x44,0x54,0x74,0x70,0x00),#"g",71
- (0x00,0x7c,0x7c,0x10,0x10,0x7c,0x7c,0x00),#"h",72
- (0x00,0x00,0x44,0x7c,0x7c,0x44,0x00,0x00),#"i",73
- (0x00,0x20,0x64,0x44,0x7c,0x3c,0x04,0x00),#"j",74
- (0x00,0x7c,0x7c,0x10,0x38,0x6c,0x44,0x00),#"k",75
- (0x00,0x00,0x7c,0x7c,0x40,0x40,0x40,0x00),#"l",76
- (0x00,0x7c,0x7c,0x18,0x30,0x18,0x7c,0x7c),#"m",77
- (0x00,0x7c,0x7c,0x18,0x30,0x7c,0x7c,0x00),#"n",78
- (0x00,0x38,0x7c,0x44,0x44,0x7c,0x38,0x00),#"o",79
- (0x00,0x7c,0x7c,0x24,0x24,0x3c,0x18,0x00),#"p",80
- (0x00,0x38,0x7c,0x44,0x34,0x6c,0x58,0x00),#"q",81
- (0x00,0x7c,0x7c,0x14,0x34,0x7c,0x48,0x00),#"r",82
- (0x00,0x48,0x5c,0x54,0x54,0x74,0x24,0x00),#"s",83
- (0x00,0x04,0x04,0x7c,0x7c,0x04,0x04,0x00),#"t",84
- (0x00,0x3c,0x7c,0x40,0x40,0x7c,0x3c,0x00),#"u",85
- (0x00,0x1c,0x3c,0x60,0x60,0x3c,0x1c,0x00),#"v",86
- (0x00,0x7c,0x7c,0x30,0x18,0x30,0x7c,0x7c),#"w",87
- (0x00,0x44,0x6c,0x38,0x38,0x6c,0x44,0x00),#"x",88
- (0x00,0x0c,0x1c,0x70,0x70,0x1c,0x0c,0x00),#"y",89
- (0x00,0x44,0x64,0x74,0x5c,0x4c,0x44,0x00),#"z",90
- (0x00,0x08,0x08,0x3e,0x77,0x41,0x00,0x00),#"{",91
- (0x00,0x00,0x00,0x77,0x77,0x00,0x00,0x00),#"|",92
- (0x00,0x00,0x41,0x77,0x3e,0x08,0x08,0x00),#"}",93
- (0x00,0x06,0x03,0x01,0x02,0x04,0x06,0x03),#"~",94
- (0x3e,0x3e),#"\x7f",95
- (0x00,0x00),#"\x80",96
- )
- io_init()
- lcd_init()
- lcd_clear()
- #infinite loop through main
- while True:
- main()
- runcount += 1
- time.sleep(.125)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement