Can send image through HTTP
This commit is contained in:
parent
1a0377ad5d
commit
1c2f08f5aa
52
main.py
52
main.py
@ -28,6 +28,7 @@ from datetime import datetime, timedelta
|
|||||||
import io
|
import io
|
||||||
import locale
|
import locale
|
||||||
import logging
|
import logging
|
||||||
|
import math
|
||||||
import os.path
|
import os.path
|
||||||
import time
|
import time
|
||||||
|
|
||||||
@ -46,8 +47,13 @@ class WidgetPlacement:
|
|||||||
self.position = position
|
self.position = position
|
||||||
self.kwargs = kwargs
|
self.kwargs = kwargs
|
||||||
|
|
||||||
|
def byteToStr(v):
|
||||||
|
return chr((v & 0xF) + 97) + chr(((v >> 4) & 0xF) + 97)
|
||||||
|
|
||||||
def main(only_on_coming_evt=False, ignore_module=[], force_coming_event=True, expand_alerts=False, **config_args):
|
def wordToStr(v):
|
||||||
|
return byteToStr(v & 0xFF) + byteToStr((v >> 8) & 0xFF)
|
||||||
|
|
||||||
|
def main(only_on_coming_evt=False, ignore_module=[], force_coming_event=True, expand_alerts=False, send_to=None, **config_args):
|
||||||
image = Image.new('1', (480, 800), 255)
|
image = Image.new('1', (480, 800), 255)
|
||||||
#image = Image.new('L', (480, 800), 'white')
|
#image = Image.new('L', (480, 800), 'white')
|
||||||
draw = ImageDraw.Draw(image)
|
draw = ImageDraw.Draw(image)
|
||||||
@ -188,20 +194,42 @@ def main(only_on_coming_evt=False, ignore_module=[], force_coming_event=True, ex
|
|||||||
)
|
)
|
||||||
|
|
||||||
logging.info("image generated")
|
logging.info("image generated")
|
||||||
try:
|
if send_to is not None:
|
||||||
import epd7in5
|
import urllib.request
|
||||||
|
|
||||||
epd = epd7in5.EPD()
|
def do_req(url):
|
||||||
epd.init()
|
with urllib.request.urlopen(url, b""):
|
||||||
logging.info("initialized")
|
pass
|
||||||
|
|
||||||
epd.display(epd.getbuffer(image))
|
do_req(send_to + "EPDw_")
|
||||||
|
pixels = image.load()
|
||||||
|
width, height = image.size
|
||||||
|
buf = [0xFF] * (int(width/8) * height)
|
||||||
|
for y in range(height):
|
||||||
|
for x in range(width):
|
||||||
|
if pixels[x, y] == 0:
|
||||||
|
buf[int((y + (width - x - 1) * height) / 8)] &= ~(0x80 >> (y % 8))
|
||||||
|
for i in range(math.ceil(len(buf) / 500)):
|
||||||
|
data = ''.join([byteToStr(b) for b in buf[500*i:500*(i+1)]])
|
||||||
|
size = wordToStr(len(data))
|
||||||
|
do_req(send_to + data + size + "LOAD_")
|
||||||
|
do_req(send_to + "SHOW_")
|
||||||
|
|
||||||
logging.info("time to sleep")
|
else:
|
||||||
epd.sleep()
|
try:
|
||||||
|
import epd7in5
|
||||||
|
|
||||||
except:
|
epd = epd7in5.EPD()
|
||||||
image.save("screen.png")
|
epd.init()
|
||||||
|
logging.info("initialized")
|
||||||
|
|
||||||
|
epd.display(epd.getbuffer(image))
|
||||||
|
|
||||||
|
logging.info("time to sleep")
|
||||||
|
epd.sleep()
|
||||||
|
|
||||||
|
except:
|
||||||
|
image.save("screen.png")
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
import argparse
|
import argparse
|
||||||
@ -220,6 +248,7 @@ if __name__ == '__main__':
|
|||||||
help='How many minutes to keep the infos in cache')
|
help='How many minutes to keep the infos in cache')
|
||||||
parser.add_argument('--max-cache-timeout', type=int, default=120,
|
parser.add_argument('--max-cache-timeout', type=int, default=120,
|
||||||
help='Maximum time to serve the infos in cache in case of issue')
|
help='Maximum time to serve the infos in cache in case of issue')
|
||||||
|
parser.add_argument('--send-to', help='Send the request to a HTTP server')
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
@ -230,4 +259,5 @@ if __name__ == '__main__':
|
|||||||
args.expand_alerts,
|
args.expand_alerts,
|
||||||
cache_timeout=args.cache_timeout,
|
cache_timeout=args.cache_timeout,
|
||||||
max_cache_timeout=args.max_cache_timeout,
|
max_cache_timeout=args.max_cache_timeout,
|
||||||
|
send_to=args.send_to,
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user