Advertisement
Guest User

smallfont_test.py

a guest
Feb 23rd, 2015
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 10.06 KB | None | 0 0
  1. import RPi.GPIO as GPIO
  2. import time
  3. import psutil
  4. import datetime
  5. import math
  6.  
  7. runcount = 0
  8. sd = ""
  9. hdd = ""
  10.  
  11. LCD_CS = 2
  12. LCD_RST  = 3
  13. LCD_A0 = 4
  14. LCD_CLK = 27
  15. LCD_SI = 17
  16.  
  17. def main():
  18.     global runcount
  19.     global sd
  20.     global hdd
  21.     global hdd2
  22.     date = datetime.date.today().strftime("%m/%d/%Y")
  23.     time = datetime.datetime.now()
  24.     time = str("%02d" % time.hour) + ":" + str("%02d" % time.minute) + ":" + str("%02d" % time.second)
  25.  
  26.     cpu_perc = psutil.cpu_percent(interval=1)
  27.     #cpu_perc = str(cpu_perc)
  28.     cpu_perc = math.ceil(cpu_perc)
  29.     cpu = ""
  30.     per = 0
  31.     for i in range(40):
  32.         if (cpu_perc >= 0):
  33.             cpu+=str(chr(127))
  34.             per+=1
  35.         else:
  36.             cpu+=str(chr(128))
  37.         cpu_perc -= 2.5
  38.     i = 0
  39.     #print per
  40.    
  41.     ram_perc = psutil.virtual_memory().percent
  42.     #ram_perc = str(ram_perc.percent)
  43.     ram_perc = math.ceil(ram_perc)
  44.     ram = ""
  45.     per = 0
  46.     for i in range(40):
  47.         if (ram_perc >= 0):
  48.             ram+=str(chr(127))
  49.             per+=1
  50.         else:
  51.             ram+=str(chr(128))
  52.         ram_perc -= 2.5
  53.     i = 0
  54.     #print per
  55.  
  56.     if (runcount == 30):
  57.         sd_perc = psutil.disk_usage('/').percent
  58.         #sd_perc = str(sd_perc.percent)
  59.         sd_perc = math.ceil(sd_perc)
  60.         sd = ""
  61.         per = 0
  62.         for i in range(40):
  63.             if (sd_perc >= 0):
  64.                 sd+=str(chr(127))
  65.                 per+=1
  66.             else:
  67.                 sd+=str(chr(128))
  68.             sd_perc -= 2.5
  69.         i = 0
  70.         #print per
  71.        
  72.         hdd_perc = psutil.disk_usage('/media/Network/').percent
  73.         #hdd_perc = str(hdd_perc.percent)
  74.         hdd_perc = math.ceil(hdd_perc)
  75.         hdd = ""
  76.         per = 0
  77.         for i in range(40):
  78.             if (hdd_perc >= 0):
  79.                 hdd+=str(chr(127))
  80.                 per+=1
  81.             else:
  82.                 hdd+=str(chr(128))
  83.             hdd_perc -= 2.5
  84.         i = 0
  85.        
  86.         hdd2_perc = psutil.disk_usage('/media/_Network2/').percent
  87.         hdd2_perc = math.ceil(hdd2_perc)
  88.         hdd2 = ""
  89.         per = 0
  90.         for i in range(40):
  91.             if (hdd2_perc >= 0):
  92.                 hdd2+=str(chr(127))
  93.                 per+=1
  94.             else:
  95.                 hdd2+=str(chr(128))
  96.             hdd2_perc -= 2.5
  97.         i = 0
  98.         #print per
  99.         runcount = 1
  100.     if (runcount == 0):
  101.         for i in range(40):
  102.             sd = " --WAIT-- "
  103.             hdd = " --WAIT-- "
  104.             hdd2 = " --WAIT-- "
  105.                          
  106.     #lcd_ascii168_string(0,0,"                ")
  107.     lcd_ascii168_string(0,0,date)
  108.     #print date + " " + time
  109.     #lcd_ascii168_string(0,1,"                ")
  110.     lcd_ascii168_string(0,1,time)
  111.     lcd_ascii168_string(0,2,"                ")
  112.     #lcd_ascii168_string(0,3,"                ")
  113.     lcd_ascii168_string(0,3,"CPU [" + cpu + "]")
  114.     #print "CPU [" + cpu + "]"
  115.     #lcd_ascii168_string(0,4,"                ")
  116.     lcd_ascii168_string(0,4,"RAM [" + ram + "]")
  117.     #print "RAM [" + ram + "]"
  118.     #lcd_ascii168_string(0,5,"                ")
  119.     lcd_ascii168_string(0,5,"/   [" + sd + "]")
  120.     #print "/   [" + sd + "]"
  121.     #lcd_ascii168_string(0,6,"                ")
  122.     lcd_ascii168_string(0,6,"Z:/ [" + hdd + "]")
  123.     #print "Z:/ [" + hdd + "]"
  124.     lcd_ascii168_string(0,7,"X:/ [" + hdd2 +"]")
  125.  
  126. def io_init():
  127.     GPIO.setmode(GPIO.BCM)
  128.     GPIO.setwarnings(False)
  129.     GPIO.setup(LCD_CS, GPIO.OUT)
  130.     GPIO.setup(LCD_RST, GPIO.OUT)
  131.     GPIO.setup(LCD_A0, GPIO.OUT)
  132.     GPIO.setup(LCD_CLK, GPIO.OUT)
  133.     GPIO.setup(LCD_SI, GPIO.OUT)
  134.    
  135. def lcd_init():
  136.     GPIO.output(LCD_CS, True)
  137.     GPIO.output(LCD_RST, False)
  138.     GPIO.output(LCD_RST, True)
  139.     lcd_transfer_data(0xe2,0); #internal reset
  140.     lcd_transfer_data(0xa2,0); #voltage bias
  141.     lcd_transfer_data(0xa0,0); #ram address seg output
  142.     lcd_transfer_data(0xcf,0); #scan direction
  143.     lcd_transfer_data(0xa4,0); #display all points
  144.     lcd_transfer_data(0xa6,0); #normal/reverse
  145.     lcd_transfer_data(0x2f,0); #internal power
  146.     lcd_transfer_data(0x60,0); #start line
  147.     lcd_transfer_data(0x20,0); #contrast 20-27
  148.     lcd_transfer_data(0x81,0); #electronic volume
  149.     lcd_transfer_data(0x31,0); #Contrast Control
  150.     lcd_transfer_data(0xaf,0); #display on/off
  151.     lcd_clear()
  152.  
  153. def lcd_picture(xPos, yPos, char):
  154.     for i in range(0, 8):
  155.         lcd_set_page(yPos+i,xPos)
  156.         for j in range(129*i, 128*(i+1)):
  157.             lcd_transfer_data(PICTURE[char][j],1)
  158.  
  159. def lcd_ascii168_string(xPos, yPos, string):
  160.     stringLen = len(string)
  161.     xchar = xPos
  162.     for i in range(0, stringLen):
  163.         xPos_i = xPos+i*8
  164.         lcd_ascii168(xchar,yPos,ord(string[i])-32)
  165.         char = ord(string[i])-32
  166.         char = len(ASCII168[char])
  167.         xchar = xchar + char
  168.  
  169. def lcd_ascii168(xPos, yPos, char):
  170.     lcd_set_page(yPos,xPos)
  171.     x = len(ASCII168[char])
  172.     for i in range(x):
  173.         lcd_transfer_data(ASCII168[char][i],1)
  174.  
  175. def lcd_clear():
  176.     GPIO.output(LCD_CS, False)
  177.     for i in range(0, 8):
  178.         lcd_set_page(i,0)
  179.         for j in range(0, 129):
  180.             lcd_transfer_data(0x00,1)
  181.     GPIO.output(LCD_CS, True)
  182.  
  183. def lcd_set_page(page, column):
  184.     lsb = column & 0x0f
  185.     msb = column & 0xf0
  186.     msb = msb>>4
  187.     msb = msb | 0x10
  188.     page = page | 0xb0
  189.     lcd_transfer_data(page,0)
  190.     lcd_transfer_data(msb,0)
  191.     lcd_transfer_data(lsb,0)
  192.    
  193.  
  194. def lcd_transfer_data(value, SI):
  195.     GPIO.output(LCD_CS, False)
  196.     GPIO.output(LCD_CLK, True)
  197.     if(SI):
  198.         GPIO.output(LCD_A0, True)
  199.     else:
  200.         GPIO.output(LCD_A0, False)
  201.     lcd_byte(value)
  202.     GPIO.output(LCD_CS, True)
  203.  
  204.  
  205. def lcd_byte(bits):
  206.     tmp = bits;
  207.     #file = open("/home/pi/screen/io_log.log", "a")
  208.     for i in range(0, 8):
  209.         GPIO.output(LCD_CLK, False)
  210.         if(tmp & 0x80):
  211.             GPIO.output(LCD_SI, True)
  212.             #file.write("1")
  213.         else:
  214.             GPIO.output(LCD_SI, False)
  215.             #file.write("0")
  216.         tmp = (tmp<<1)
  217.         GPIO.output(LCD_CLK, True)
  218.     #file.close()
  219.  
  220. ASCII168=(
  221. (0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00),#" ",0
  222. (0x00,0x00,0x00,0x5f,0x5f,0x00,0x00,0x00),#"!",1
  223. (0x00,0x07,0x07,0x00,0x07,0x07,0x00,0x00),#""",2
  224. (0x00,0x14,0x7f,0x7f,0x14,0x7f,0x7f,0x14),#"#",3
  225. (0x00,0x24,0x2e,0x6a,0x7f,0x2b,0x3a,0x12),#"$",4
  226. (0x00,0x23,0x33,0x18,0x0c,0x66,0x62,0x00),#"%",5
  227. (0x00,0x36,0x7f,0x49,0x5f,0x36,0x60,0x50),#"&",6
  228. (0x00,0x00,0x80,0xe0,0x60,0x00,0x00,0x00),#",",7
  229. (0x00,0x00,0x1c,0x3e,0x63,0x41,0x00,0x00),#"(",8
  230. (0x00,0x00,0x41,0x63,0x3e,0x1c,0x00,0x00),#")",9
  231. (0x00,0x14,0x1c,0x3e,0x3e,0x1c,0x14,0x00),#"*",10
  232. (0x00,0x08,0x08,0x3e,0x3e,0x08,0x08,0x00),#"+",11
  233. (0x00,0x00,0x80,0xe0,0x60,0x00,0x00,0x00),#",",12
  234. (0x00,0x08,0x08,0x08,0x08,0x08,0x08,0x00),#"-",13
  235. (0x00,0x00,0x00,0x60,0x60,0x00,0x00,0x00),#".",14
  236. (0x00,0x20,0x30,0x18,0x0c,0x06,0x02,0x00),#"/",15
  237. (0x00,0x3e,0x7f,0x59,0x4d,0x7f,0x3e,0x00),#"0",16
  238. (0x00,0x40,0x42,0x7f,0x7f,0x40,0x40,0x00),#"1",17
  239. (0x00,0x42,0x63,0x71,0x59,0x4f,0x46,0x00),#"2",18
  240. (0x00,0x22,0x63,0x49,0x49,0x7f,0x36,0x00),#"3",19
  241. (0x00,0x18,0x1c,0x16,0x7f,0x7f,0x10,0x00),#"4",20
  242. (0x00,0x27,0x67,0x45,0x45,0x7d,0x39,0x00),#"5",21
  243. (0x00,0x3c,0x7e,0x4b,0x49,0x79,0x30,0x00),#"6",22
  244. (0x00,0x01,0x71,0x79,0x0d,0x07,0x03,0x00),#"7",23
  245. (0x00,0x36,0x7f,0x49,0x49,0x7f,0x36,0x00),#"8",24
  246. (0x00,0x06,0x4f,0x49,0x69,0x3f,0x1e,0x00),#"9",25
  247. (0x00,0x00,0x00,0x6c,0x6c,0x00,0x00,0x00),#":",26
  248. (0x00,0x00,0x80,0xec,0x6c,0x00,0x00,0x00),#";",27
  249. (0x00,0x08,0x1c,0x36,0x63,0x41,0x00,0x00),#"<",28
  250. (0x00,0x14,0x14,0x14,0x14,0x14,0x14,0x00),#"=",29
  251. (0x00,0x00,0x41,0x63,0x36,0x1c,0x08,0x00),#">",30
  252. (0x00,0x02,0x03,0x59,0x5d,0x07,0x02,0x00),#"?",31
  253. (0x00,0x3e,0x7f,0x41,0x5d,0x57,0x1e,0x00),#"@",32
  254. (0x00,0x7e,0x7f,0x09,0x09,0x7f,0x7e,0x00),#"A",33
  255. (0x00,0x7f,0x7f,0x49,0x49,0x7f,0x36,0x00),#"B",34
  256. (0x00,0x3e,0x7f,0x41,0x41,0x63,0x22,0x00),#"C",35
  257. (0x00,0x7f,0x7f,0x41,0x63,0x3e,0x1c,0x00),#"D",36
  258. (0x00,0x7f,0x7f,0x49,0x49,0x49,0x41,0x00),#"E",37
  259. (0x00,0x7f,0x7f,0x09,0x09,0x09,0x01,0x00),#"F",38
  260. (0x00,0x3e,0x7f,0x41,0x49,0x7b,0x3a,0x00),#"G",39
  261. (0x00,0x7f,0x7f,0x08,0x08,0x7f,0x7f,0x00),#"H",40
  262. (0x00,0x41,0x41,0x7f,0x7f,0x41,0x41,0x00),#"I",41
  263. (0x00,0x20,0x61,0x41,0x7f,0x3f,0x01,0x00),#"J",42
  264. (0x00,0x7f,0x7f,0x1c,0x36,0x63,0x41,0x00),#"K",43
  265. (0x00,0x7f,0x7f,0x40,0x40,0x40,0x40,0x00),#"L",44
  266. (0x00,0x7f,0x7f,0x06,0x1c,0x06,0x7f,0x7f),#"M",45
  267. (0x00,0x7f,0x7f,0x0c,0x18,0x7f,0x7f,0x00),#"N",46
  268. (0x00,0x3e,0x7f,0x41,0x41,0x7f,0x3e,0x00),#"O",47
  269. (0x00,0x7f,0x7f,0x09,0x09,0x0f,0x06,0x00),#"P",48
  270. (0x00,0x3e,0x7f,0x41,0x31,0x6f,0x5e,0x00),#"Q",49
  271. (0x00,0x7f,0x7f,0x09,0x19,0x7f,0x66,0x00),#"R",50
  272. (0x00,0x26,0x6f,0x49,0x49,0x7b,0x32,0x00),#"S",51
  273. (0x00,0x01,0x01,0x7f,0x7f,0x01,0x01,0x00),#"T",52
  274. (0x00,0x3f,0x7f,0x40,0x40,0x7f,0x3f,0x00),#"U",53
  275. (0x00,0x1f,0x3f,0x60,0x60,0x3f,0x1f,0x00),#"V",54
  276. (0x00,0x7f,0x7f,0x30,0x1c,0x30,0x7f,0x7f),#"W",55
  277. (0x00,0x63,0x77,0x1c,0x1c,0x77,0x63,0x00),#"X",56
  278. (0x00,0x07,0x0f,0x78,0x78,0x0f,0x07,0x00),#"Y",57
  279. (0x00,0x61,0x71,0x59,0x4d,0x47,0x43,0x00),#"Z",58
  280. (0x00,0x7f,0x7f,0x41,0x41,0x41,0x00,0x00),#"[",59
  281. (0x00,0x20,0x30,0x18,0x0c,0x06,0x02,0x00),#"/",60
  282. (0x00,0x00,0x41,0x41,0x41,0x7f,0x7f,0x00),#"]",61
  283. (0x00,0x02,0x03,0x01,0x01,0x03,0x02,0x00),#"^",62
  284. (0x00,0x08,0x08,0x08,0x08,0x08,0x08,0x00),#"-",63
  285. (0x00,0x02,0x06,0x0c,0x18,0x30,0x20,0x00),#"\",64
  286. (0x00,0x78,0x7c,0x14,0x14,0x7c,0x78,0x00),#"a",65
  287. (0x00,0x7c,0x7c,0x54,0x54,0x7c,0x28,0x00),#"b",66
  288. (0x00,0x38,0x7c,0x44,0x44,0x6c,0x28,0x00),#"c",67
  289. (0x00,0x7c,0x7c,0x44,0x44,0x7c,0x38,0x00),#"d",68
  290. (0x00,0x7c,0x7c,0x54,0x54,0x54,0x44,0x00),#"e",69
  291. (0x00,0x7c,0x7c,0x14,0x14,0x04,0x00,0x00),#"f",70
  292. (0x00,0x38,0x7c,0x44,0x54,0x74,0x70,0x00),#"g",71
  293. (0x00,0x7c,0x7c,0x10,0x10,0x7c,0x7c,0x00),#"h",72
  294. (0x00,0x00,0x44,0x7c,0x7c,0x44,0x00,0x00),#"i",73
  295. (0x00,0x20,0x64,0x44,0x7c,0x3c,0x04,0x00),#"j",74
  296. (0x00,0x7c,0x7c,0x10,0x38,0x6c,0x44,0x00),#"k",75
  297. (0x00,0x00,0x7c,0x7c,0x40,0x40,0x40,0x00),#"l",76
  298. (0x00,0x7c,0x7c,0x18,0x30,0x18,0x7c,0x7c),#"m",77
  299. (0x00,0x7c,0x7c,0x18,0x30,0x7c,0x7c,0x00),#"n",78
  300. (0x00,0x38,0x7c,0x44,0x44,0x7c,0x38,0x00),#"o",79
  301. (0x00,0x7c,0x7c,0x24,0x24,0x3c,0x18,0x00),#"p",80
  302. (0x00,0x38,0x7c,0x44,0x34,0x6c,0x58,0x00),#"q",81
  303. (0x00,0x7c,0x7c,0x14,0x34,0x7c,0x48,0x00),#"r",82
  304. (0x00,0x48,0x5c,0x54,0x54,0x74,0x24,0x00),#"s",83
  305. (0x00,0x04,0x04,0x7c,0x7c,0x04,0x04,0x00),#"t",84
  306. (0x00,0x3c,0x7c,0x40,0x40,0x7c,0x3c,0x00),#"u",85
  307. (0x00,0x1c,0x3c,0x60,0x60,0x3c,0x1c,0x00),#"v",86
  308. (0x00,0x7c,0x7c,0x30,0x18,0x30,0x7c,0x7c),#"w",87
  309. (0x00,0x44,0x6c,0x38,0x38,0x6c,0x44,0x00),#"x",88
  310. (0x00,0x0c,0x1c,0x70,0x70,0x1c,0x0c,0x00),#"y",89
  311. (0x00,0x44,0x64,0x74,0x5c,0x4c,0x44,0x00),#"z",90
  312. (0x00,0x08,0x08,0x3e,0x77,0x41,0x00,0x00),#"{",91
  313. (0x00,0x00,0x00,0x77,0x77,0x00,0x00,0x00),#"|",92
  314. (0x00,0x00,0x41,0x77,0x3e,0x08,0x08,0x00),#"}",93
  315. (0x00,0x06,0x03,0x01,0x02,0x04,0x06,0x03),#"~",94
  316. (0x3e,0x3e),#"\x7f",95
  317. (0x00,0x00),#"\x80",96
  318. )
  319.  
  320. io_init()
  321. lcd_init()
  322. lcd_clear()
  323.  
  324. #infinite loop through main
  325. while True:
  326.     main()
  327.     runcount += 1
  328.     time.sleep(.125)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement