25_aboutCocoPi.py 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. #!/usr/bin/env python
  2. #version : 2024.01.01
  3. #language : en
  4. from maix import *
  5. import socket
  6. import os
  7. import sys
  8. sys.path.append('/root/')
  9. import http.client
  10. from CocoPi import BUTTON
  11. import time
  12. key_A = BUTTON(14)
  13. key_B = BUTTON(8)
  14. key_C = BUTTON(13)
  15. key_D = BUTTON(7)
  16. #image.load_freetype("/root/preset/fonts/JetBrainsMono-Bold-7.ttf")
  17. image.load_freetype("/root/preset/fonts/CascadiaCodePL-Italic.ttf")
  18. def getWifiConnectState():
  19. cmd = "wifi_get_connection_info_test 1"
  20. res = os.popen(cmd).read()
  21. wifiInfo = {}
  22. if res.find('get connection infomation successfully!') != -1:
  23. wifiInfo["state"]=True
  24. wifiInfo["AP"] = res[res.find("Connected AP: ")+13:res.find("IP address: ")-1]
  25. wifiInfo["IP"] = res[res.find("IP address: ")+12:res.find("frequency")-1]
  26. wifiInfo["frequency"] = res[res.find("frequency: ")+10:res.find("RSSI")-1]
  27. wifiInfo["RSSI"] = res[res.find("RSSI: ")+6:res.find("link_speed")-1]
  28. wifiInfo["link_speed"] = res[res.find("link_speed: ")+10:res.find("IP address: ")-1]
  29. wifiInfo["noise"] = res[res.find("noise: ")+6:res.find("noise: ")+11]
  30. else:
  31. wifiInfo["state"]=False
  32. wifiInfo["AP"] = "N/A"
  33. wifiInfo["IP"] = "N/A"
  34. wifiInfo["frequency"] = "N/A"
  35. wifiInfo["RSSI"] = "N/A"
  36. wifiInfo["link_speed"] = "N/A"
  37. wifiInfo["noise"] = "N/A"
  38. return wifiInfo
  39. def getPrivateIp():
  40. st = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
  41. try:
  42. st.connect(("10.255.255.255",1))
  43. IP = st.getsockname()[0]
  44. except Exception:
  45. IP = "127.0.0.1"
  46. finally:
  47. st.close()
  48. return IP
  49. def getPublicIp():
  50. import requests
  51. url = 'https://myip.ipip.net'
  52. res = requests.get(url).text.split(" ")
  53. return res[1][3:]
  54. PublicIp=""
  55. PrivateIP=""
  56. baseInfo=[
  57. "---------------------------",
  58. " Design -- Create -- Share ",
  59. "---------------------------",
  60. " SYSTEM ",
  61. "***************************",
  62. "SystemName: CocoPi Linux",
  63. "SystemVersion: 2024.01.01",
  64. "---------------------------",
  65. " USERNAME: ",
  66. "---------------------------",
  67. " Internet ",
  68. "***************************",
  69. " ",
  70. " ",
  71. " ",
  72. " ",
  73. "---------------------------",
  74. "Python Version 3.8.5",
  75. "***************************",
  76. "Python Package Version",
  77. "***************************",
  78. "av 9.2.0",
  79. "beautifulsoup4 4.11.1",
  80. "certifi 2020.6.20",
  81. "cffi 1.14.3",
  82. "chardet 3.0.4",
  83. "click 7.1.2",
  84. "defusedxml 0.6.0",
  85. "et-xmlfile 1.0.1",
  86. "evdev 1.4.0",
  87. "Flask 1.1.2",
  88. "Flask-Login 0.5.0",
  89. "gpiod 1.4.0",
  90. "html5lib 1.1",
  91. "idna 2.10",
  92. "itsdangerous 1.1.0",
  93. "jdcal 1.4.1",
  94. "jieba 0.42.1",
  95. "Jinja2 2.11.2",
  96. "lxml 4.5.2",
  97. "maixpy3 0.5.4",
  98. "MarkupSafe 1.1.1",
  99. "numpy 1.19.2",
  100. "openpyxl 3.0.5",
  101. "Pillow 7.2.0",
  102. "pip 20.1.1",
  103. "plumbum 1.6.9",
  104. "ply 3.11",
  105. "pyasn1 0.4.8",
  106. "PyAudio 0.2.11",
  107. "pycparser 2.20",
  108. "pylibmodbus 0.5.0",
  109. "pyserial 3.4",
  110. "qrcode 6.1",
  111. "requests 2.24.0",
  112. "rpyc 5.0.1",
  113. "rsa 4.6",
  114. "schedule 0.6.0",
  115. "setuptools 47.1.0",
  116. "six 1.15.0",
  117. "smbus2 0.4.2",
  118. "soupsieve 2.3.1",
  119. "spidev 3.5",
  120. "SQLAlchemy 1.3.18",
  121. "urllib3 1.25.10",
  122. "websocket-client 1.5.1",
  123. "Werkzeug 1.0.1",
  124. "zbarlight 3.0",
  125. "---------------------------",
  126. ]
  127. ownerName=""
  128. try:
  129. with open( '/root/user/text/owner.txt', 'r' ) as f:
  130. ownerName=f.read()
  131. except:
  132. ownerName="N/A"
  133. baseInfo[8]="{: <28}".format("USERNAME: "+ownerName)
  134. canvas = image.new(size=(320, 240),color = (15,21,46),mode = "RGB")
  135. canvas.draw_string(12 , 100 , "Checking Wi-Fi connection", scale = 1, color = (255,255,255), thickness = 2)
  136. display.show(canvas)
  137. checkInternet=False
  138. try:
  139. if getWifiConnectState()["state"]==True:
  140. PublicIp=getPublicIp()
  141. PrivateIP=getPrivateIp()
  142. baseInfo[12]="{: <28}".format("PublicIP:"+PublicIp)
  143. baseInfo[13]="{: <28}".format("PrivateIP:"+PrivateIP)
  144. baseInfo[14]="{: <28}".format("WIFI AP:"+getWifiConnectState()["AP"])
  145. baseInfo[15]="{: <28}".format("WIFI RSSI:"+getWifiConnectState()["RSSI"])
  146. else:
  147. PublicIp="N/A"
  148. PrivateIP="N/A"
  149. baseInfo[12]="{: <28}".format("PublicIP: N/A")
  150. baseInfo[13]="{: <28}".format("PrivateIP: N/A")
  151. baseInfo[14]="{: <28}".format("WIFI AP: N/A")
  152. baseInfo[15]="{: <28}".format("WIFI RSSI: N/A")
  153. except:
  154. PublicIp="N/A"
  155. PrivateIP="N/A"
  156. baseInfo[12]="{: <28}".format("PublicIP: N/A")
  157. baseInfo[13]="{: <28}".format("PrivateIP: N/A")
  158. baseInfo[14]="{: <28}".format("WIFI AP: N/A")
  159. baseInfo[15]="{: <28}".format("WIFI RSSI: N/A")
  160. pass
  161. xPosition=48
  162. yPosition=160
  163. ySpeedMax=12
  164. yDirection=0
  165. yRealSpeed=0
  166. totalNum=0
  167. while True:
  168. canvas.clear()
  169. canvas = image.new(size=(320, 240),color = (15,21,46),mode = "RGB")
  170. if key_D.is_pressed():
  171. yDirection=-1
  172. elif key_B.is_pressed():
  173. yDirection=1
  174. else:
  175. yDirection=0
  176. if yDirection==1:
  177. if yRealSpeed<(ySpeedMax*yDirection):
  178. yRealSpeed=yRealSpeed+1
  179. else:
  180. yRealSpeed=yRealSpeed
  181. elif yDirection==-1:
  182. if yRealSpeed>(ySpeedMax*yDirection):
  183. yRealSpeed=yRealSpeed-1
  184. else:
  185. yRealSpeed=yRealSpeed
  186. else:
  187. if yRealSpeed>0:
  188. yRealSpeed=yRealSpeed-1
  189. elif yRealSpeed<0:
  190. yRealSpeed=yRealSpeed+1
  191. else:
  192. yRealSpeed=0
  193. yPosition=yPosition+yRealSpeed
  194. if yPosition>160:
  195. yPosition=160
  196. elif yPosition<-900:
  197. yPosition=-900
  198. else:
  199. yPosition=yPosition
  200. #canvas.draw_string(60 , 8 , "yPosition:"+str(yPosition)+"yRealSpeed:"+str(yRealSpeed), scale = 1, color = (255,255,255), thickness = 1)
  201. canvas.draw_image(image.open("/root/preset/img/cocorobo_152146.png"),xPosition+40 , yPosition-144,alpha=1)
  202. canvas.draw_image(image.open("/root/preset/img/cocorobo_text.jpg"),xPosition+32 , yPosition-20,alpha=1)
  203. for i in range(len(baseInfo)):
  204. if (yPosition+(i)*16)<260 and (yPosition+(i)*16)>-20:
  205. canvas.draw_string(xPosition , yPosition+i*16 , baseInfo[i], scale = 1, color = (255,255,255), thickness = 1)
  206. else:
  207. pass
  208. canvas.draw_image((image.open("/root/preset/img/left_ffffff_16x16.png")).rotate(90, adjust=0),6,6,alpha=1)
  209. canvas.draw_image((image.open("/root/preset/img/left_ffffff_16x16.png")).rotate(270, adjust=0),6,216,alpha=1)
  210. canvas.draw_image((image.open("/root/preset/img/exit_ff0000_24x24.png")).rotate(0, adjust=0),288,216,alpha=1)
  211. display.show(canvas)