SHARE
TWEET

screen_wiringx.py

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