From 424e9c1272107191fd17f165c66f0b728a47dfad Mon Sep 17 00:00:00 2001 From: trav Date: Wed, 24 Aug 2022 01:15:04 -0400 Subject: [PATCH] works and almost ready for PRIME TIME --- carousel.py | 231 ++++++++++++++++++++++++++++++++++------------------ ssbpost.sh | 2 +- 2 files changed, 154 insertions(+), 79 deletions(-) diff --git a/carousel.py b/carousel.py index 0a5fec9..e2d59a2 100755 --- a/carousel.py +++ b/carousel.py @@ -68,7 +68,6 @@ try: # draw.text((2, 280), 'EBB', font = font18, fill = 255) draw.text((2, 300), 'Scuttlebooth 2', font = font18, fill = 255) epd.display(epd.getbuffer(Limage)) - time.sleep(2) epd.sleep() except: print('traceback.format_exc():\n%s' % traceback.format_exc()) @@ -78,21 +77,21 @@ except: @buttonshim.on_press(buttonshim.BUTTON_A) def button_a(button, pressed): global button_flag - buttonshim.set_pixel(0xFF, 0x00, 0x00) + # buttonshim.set_pixel(0xFF, 0x00, 0x00) button_flag = "button_1" @buttonshim.on_press(buttonshim.BUTTON_B) def button_b(button, pressed): global button_flag - buttonshim.set_pixel(0x00, 0x00, 0xFF) + # buttonshim.set_pixel(0x00, 0x00, 0xFF) button_flag = "button_2" @buttonshim.on_press(buttonshim.BUTTON_C) def button_c(button, pressed): global button_flag - buttonshim.set_pixel(0x00, 0x00, 0xFF) + # buttonshim.set_pixel(0x00, 0x00, 0xFF) button_flag = "button_3" @buttonshim.on_press(buttonshim.BUTTON_D) @@ -131,12 +130,38 @@ def get_concat_h_blank(im1, im2, color=(0, 0, 0)): dst.paste(im2, (im1.width, 0)) return dst +def pulse(speed): + time.sleep(1) + for scale in range(0, speed): + if scale >= 1: + scale = scale / speed + buttonshim.set_pixel(0x00, 0x00, int(0xff * scale)) + for scale in range(speed, 0,-1): + if scale >= 1: + scale = scale / speed + buttonshim.set_pixel(0x00, 0x00, int(0xff * scale)) + time.sleep(1) + for scale in range(0, speed): + if scale >= 1: + scale = scale / speed + buttonshim.set_pixel(0x00, int(0xff * scale), 0x00) + for scale in range(speed, 0,-1): + if scale >= 1: + scale = scale / speed + buttonshim.set_pixel(0x00, int(0xff * scale), 0x00) + time.sleep(1) + for scale in range(0, speed): + if scale >= 1: + scale = scale / speed + buttonshim.set_pixel(int(0xff * scale), int(0xff * scale), 0x00) + for scale in range(speed, 0,-1): + if scale >= 1: + scale = scale / speed + buttonshim.set_pixel(int(0xff * scale), int(0xff * scale), 0x00) + time.sleep(1) + ## MAIN LOOP ## while True: - # chill for a bit, keep track of how long we're chilling - time.sleep(2) - print("time:", timeIndex, "/", intervalTime, "index", dbIndex, "/", dbCount, "sync time:", syncIndex, "/", syncTime) - #iterate through syncTime and image time syncIndex+=2 timeIndex+=2 @@ -145,10 +170,11 @@ while True: if syncIndex >= syncTime: #light up red while syncing db buttonshim.set_pixel(0xFF, 0x00, 0x00) - refreshdb.fresh() + # refreshdb.fresh() + print ("uhhhhhhh skipping ssb refresh because broken also solpunk one stuck in customs rn :'(") #db count may have changed - for item in db: - dbCount = item.doc_id + # for item in db: + # dbCount = item.doc_id syncIndex = 0 buttonshim.set_pixel(0x00, 0x00, 0x00) @@ -182,7 +208,6 @@ while True: bmp = Image.open(flierPath) Limage.paste(bmp) epd.display(epd.getbuffer(Limage)) - time.sleep(2) timeIndex+=2 epd.sleep() @@ -220,30 +245,40 @@ while True: #take fullsize photos + pulse(20) + try: - result = subprocess.call(['raspistill', '-rot', '180', '-o', jpgpath1, '-vf', '-hf', '-w', '600', '-h', '800', '-t', '1000']) + result = subprocess.call(['raspistill', '-rot', '180', '-o', jpgpath1, '--brightness', '55', '--contrast', '1.25','-vf', '-hf', '-w', '600', '-h', '800', '-t', '20']) except: print('traceback.format_exc():\n%s' % traceback.format_exc()) exit() + + pulse(20) + try: - result = subprocess.call(['raspistill', '-rot', '180', '-o', jpgpath2, '-vf', '-hf', '-w', '600', '-h', '800', '-t', '1000']) + result = subprocess.call(['raspistill', '-rot', '180', '-o', jpgpath2, '--brightness', '55', '--contrast', '1.25','-vf', '-hf', '-w', '600', '-h', '800', '-t', '20']) except: print('traceback.format_exc():\n%s' % traceback.format_exc()) exit() + + pulse(20) + try: - result = subprocess.call(['raspistill', '-rot', '180', '-o', jpgpath3, '-vf', '-hf', '-w', '600', '-h', '800', '-t', '1000']) + result = subprocess.call(['raspistill', '-rot', '180', '-o', jpgpath3, '--brightness', '55', '--contrast', '1.25', '-vf', '-hf', '-w', '600', '-h', '800', '-t', '20']) except: print('traceback.format_exc():\n%s' % traceback.format_exc()) exit() + buttonshim.set_pixel(0x00, 0x00, 0xff) + #create half-size bmps for cycling through half1 = Image.open(jpgpath1) half2 = Image.open(jpgpath2) half3 = Image.open(jpgpath3) newsize = (300, 400) half1 = half1.resize(newsize) - half2 = half1.resize(newsize) - half3 = half1.resize(newsize) + half2 = half2.resize(newsize) + half3 = half3.resize(newsize) half1 = half1.convert("1") half1.save(bmpath1) half2 = half2.convert("1") @@ -331,12 +366,6 @@ while True: if button_flag == "button_1": button_flag == "null" - - #add each photo to the db - addtoDB.addToDB(bmpath1,dbPath,composite) - addtoDB.addToDB(bmpath2,dbPath,composite) - addtoDB.addToDB(bmpath3,dbPath,composite) - #add the photo strip to ssb key = addtoDB.addToSSB(composite,dbPath,0) @@ -346,7 +375,7 @@ while True: qr = qrcode.QRCode( version = 1, error_correction = qrcode.constants.ERROR_CORRECT_H, - box_size = 5, + box_size = 6, border = 1, ) # Add data @@ -359,13 +388,13 @@ while True: # generate full composite for printing - color=(0, 0, 0) - dst = Image.new('RGB', (600, 2890)) + color=(255, 255, 255) + dst = Image.new('RGB', (600, 2833), color) dst.paste(concaz, (0, 0)) whereQRinstructionsAre = imagesPath + 'ssbqrinstgurct.jpg' qrInstruct = Image.open(whereQRinstructionsAre) - dst.paste(qrInstruct, (0,2675)) - dst.paste(img, (385,2657)) + dst.paste(qrInstruct, (0,2575)) + dst.paste(img, (342,2575)) # whereInstructionsPlusQRis = imagesPath + 'instructionsPlusQR.jpg' # get_concat_h_blank(qrInstruct, img, (255, 255, 255)).save(whereInstructionsPlusQRis) # instr = Image.open(whereInstructionsPlusQRis) @@ -377,6 +406,12 @@ while True: # save the full composite image for printing dst.save(FULLcomposite) + #add each photo to the db + addtoDB.addToDB(bmpath1,dbPath,FULLcomposite) + addtoDB.addToDB(bmpath2,dbPath,FULLcomposite) + addtoDB.addToDB(bmpath3,dbPath,FULLcomposite) + + # concatenate existing composite image with the instructions+QR composite for full composite image for print # get_concat_v(concaz, instr).save(FULLcomposite) @@ -388,8 +423,6 @@ while True: exit() - - #update dbCount for item in db: dbCount = item.doc_id @@ -406,19 +439,29 @@ while True: - - - - - #post only locally and print if button_flag == "button_2": + #led to thinking mode + buttonshim.set_pixel(0x00, 0x00, 0xFF) button_flag == "null" - #add that file to the db. -1 tells addtoDB not to post to ssb. - addtoDB.addFile(bmpath,dbPath,-1) + + + #add each photo to the db + addtoDB.addToDB(bmpath1,dbPath,composite) + addtoDB.addToDB(bmpath2,dbPath,composite) + addtoDB.addToDB(bmpath3,dbPath,composite) + #update dbCount for item in db: dbCount = item.doc_id + + # print concaz that we already generated + try: + result = subprocess.call('lp ' + composite, shell=True) + except: + print('traceback.format_exc():\n%s' % traceback.format_exc()) + exit() + exitPhotoMode = True #display the image to clear the menu (also display text "posted") font18 = ImageFont.truetype('/usr/share/fonts/truetype/wqy/wqy-microhei.ttc', 24) @@ -429,26 +472,53 @@ while True: draw.text((2, 260), 'to this device only', font = font18, fill = 255) epd.display(epd.getbuffer(Limage)) + + + #just print if button_flag == "button_3": + #led to thinking mode + buttonshim.set_pixel(0x00, 0x00, 0xFF) button_flag == "null" - #nothin! loop around... exitPhotoMode still false + + # print concaz that we already generated + try: + result = subprocess.call('lp ' + composite, shell=True) + except: + print('traceback.format_exc():\n%s' % traceback.format_exc()) + exit() + + exitPhotoMode = True #reshoot if (button_flag == "button_4"): + # delete images + os.remove(bmpath1) + os.remove(bmpath2) + os.remove(bmpath3) + os.remove(jpgpath1) + os.remove(jpgpath2) + os.remove(jpgpath3) + # reset buttonflag and loop around to take pic again button_flag == "null" - exitPhotoMode = True - os.remove(bmpath) - os.remove(jpgpath) - #exit photo mode + #delete images and exit photo mode if (button_flag == "button_5"): button_flag == "null" + buttonshim.set_pixel(0x00, 0x00, 0xff) exitPhotoMode = True - os.remove(bmpath) - os.remove(jpgpath) + #delete the images we took + os.remove(bmpath1) + os.remove(bmpath2) + os.remove(bmpath3) + os.remove(jpgpath1) + os.remove(jpgpath2) + os.remove(jpgpath3) + # display next image + timeIndex = intervalTime + #led off @@ -462,13 +532,15 @@ while True: #move to the next image elif button_flag == "button_2": - print ("next image") - timeIndex = intervalTime - button_flag = "null" + buttonshim.set_pixel(0x00, 0x00, 0xFF) + print ("next image") + timeIndex = intervalTime + button_flag = "null" #go back to the previous image elif button_flag == "button_3": + buttonshim.set_pixel(0x00, 0x00, 0xFF) print ("previous image") #we go back 2 because we have to account for calling timeIndex = intervalTime iterates forward by 1 dbIndex-=2 @@ -479,7 +551,8 @@ while True: #delete current image - elif button_flag == "button_4": + elif button_flag == "button_5": + buttonshim.set_pixel(0x00, 0x00, 0xFF) button_flag = "null" #can't delete the default image @@ -493,7 +566,7 @@ while True: draw.text((2, 0), 'Are you sure', font = font18, fill = 255) draw.text((2, 40), 'you want to delete', font = font18, fill = 255) draw.text((2, 80), 'the current image?', font = font18, fill = 255) - draw.text((2, 120), 'Press button 4', font = font18, fill = 255) + draw.text((2, 120), 'Press button 5', font = font18, fill = 255) draw.text((2, 160), 'again to confirm.', font = font18, fill = 255) draw.text((2, 200), 'Press any other', font = font18, fill = 255) draw.text((2, 240), 'button for no.', font = font18, fill = 255) @@ -508,7 +581,7 @@ while True: time.sleep(.05) #sounds like delete time - if button_flag == "button_4": + if button_flag == "button_5": Fruit = Query() #results = db.search(Fruit.path == flierPath) db.remove(Fruit.path == flierPath) @@ -525,37 +598,39 @@ while True: button_flag = "null" buttonshim.set_pixel(0x00, 0x00, 0xFF) -#weather button! - elif button_flag == "button_5": +#reprint current set of pics + elif button_flag == "button_4": + button_flag = "null" + print ("button flag set to null...") + buttonshim.set_pixel(0x00, 0x00, 0xFF) - #ACTUALLY PARSE THE JSON DUH, THIS IS BROKEN + #grab the entry at dbIndex, newFlier is a dict + print ("getting db at") + print (dbIndex) + newFlier = db.get(doc_id=dbIndex) - #get the weather - #proc = subprocess.Popen(["wget", "http://wttr.in/btv_FnQT.png"], stdout=subprocess.PIPE) - proc = subprocess.Popen(["wget", "http://wttr.in/btv_FQT.png"], stdout=subprocess.PIPE) - (out, err) = proc.communicate() + #if that's an empty spot in the db we gotta keep lookin (probably wouldn't be in this case buuut whatever, this prevents errors) + while newFlier == None: + dbIndex+=1 + newFlier = db.get(doc_id=dbIndex) - #convert - size = 400, 300 - #too pixely - #im = Image.open("btv_FnQT.png") - #im = im.rotate(90, Image.NEAREST, "expand=1") + # get composite from db + flierPath = newFlier["composite"] - #sideways, no rotate - im = Image.open("btv_FQT.png") + if flierPath == None: + print ("no flier here...") - im.thumbnail(size, Image.BICUBIC) - im = im.convert("1") - im.save("btv.bmp") + # print composite + try: + result = subprocess.call('lp ' + flierPath, shell=True) + print ("printing...") + except: + print('traceback.format_exc():\n%s' % traceback.format_exc()) + exit() - #display the weather - epd.init() - Limage = Image.new('1', (epd4in2.EPD_HEIGHT, epd4in2.EPD_WIDTH), 255) # 255: clear the frame - bmp = Image.open("btv.bmp") - Limage.paste(bmp) - epd.display(epd.getbuffer(Limage)) - time.sleep(3) - timeIndex+=2 - epd.sleep() - button_flag = "null" - buttonshim.set_pixel(0x00, 0x00, 0x00) + buttonshim.set_pixel(0x00, 0x00, 0x00) + button_flag = "null" + + # chill for a bit, keep track of how long we're chilling + time.sleep(2) + print("time:", timeIndex, "/", intervalTime, "index", dbIndex, "/", dbCount, "sync time:", syncIndex, "/", syncTime) diff --git a/ssbpost.sh b/ssbpost.sh index ca5d837..08c421c 100755 --- a/ssbpost.sh +++ b/ssbpost.sh @@ -10,4 +10,4 @@ blobID=$(cat $1 | ssb-server blobs.add) #publish blob #key=$(ssb-server publish --type post --text "![upload.bmp($blobID)]" -ssb-server publish --type post --text "![photo.bmp]($blobID)" --mentions.0.name photo.bmp --mentions.0.type image/bmp +ssb-server publish --type post --text "a new photo from #dweb-camp 2022! ![photo.bmp]($blobID)" --mentions.0.name photo.bmp --mentions.0.type image/bmp