def deraLict(): noNotGd = Sub.select().where(Sub.status == placed).count() if noNotGd > 0: print("main: found un-gcoded stuff, fixing") gList = Sub.select().where(Sub.status == placed) for name in gList: makeGcode(name)
def main(): #change when parking lot is generated for visual. center = Image.open('center.png') backing = Image.new('RGBA', (board_l, board_h), color=(255, 255, 255, 255)) draw = ImageDraw.Draw(backing) center_l, center_h = center.size centerPos_l = int((board_l / 2) - (center_l / 2)) centerPos_h = int((board_h / 2) - (center_h / 2)) backing.alpha_composite(center, (centerPos_l, centerPos_h)) nameToPlace = (Sub.select().where(Sub.status >= 0)) for sub in nameToPlace: print("placing: " + sub.userName) font = ImageFont.truetype(fontFile, sub.fontSize) draw.text((sub.positionX, sub.positionY), sub.userName, (0, 0, 0), font=font) #write the test image of the board print("printing output") backing.save("test.png")
def gSend(): # Initialize s = serial.Serial(serialLoc, speed) #maybe open this in BTS main, pass it into gSend print("burning: initializing grbl...") s.write(b'\r\n\r\n') # Wait for grbl to initialize and flush startup text in serial input time.sleep(2) s.flushInput() #search db for entry, in order names = Sub.select().where(Sub.status == gcode) #header gBurn(homeCmd + unitsCmd + modeCmd + feedCmd, s) for name in names: print("burner: " + name.userName) gBurn(name.gCode, s, True) name.status = burnt name.save() #footer gBurn(stopCmd + pulloffCmd, s) print('burner: done burning!') s.close() return True
def enterDb(entry): print("pubSub: entering " + entry) dateInfo = datetime.utcnow() dbEntry = Sub.create( userName = entry, entryTime = dateInfo ) dbEntry.save()
def unParsify(): output = open(outputFile, "a") nameToMake = (Sub.select().where(Sub.status >= placed).order_by( Sub.entryTime)) for sub in nameToMake: print("gcodifying: " + sub.userName) output.write("(Block-name: " + sub.userName + ")\n") output.write(sub.gCode) output.close()
def makeDb(): fileName = open("subscriberListTest.txt") count = 0 for entry in fileName: entry = entry.strip() dateTime = datetime.utcnow() count += 1 dbEntry = Sub.create(userName=entry, entryTime=dateTime) dbEntry.save() print("dbmaker: " + entry) time.sleep(random.randint(10, 100)) #up to 10 seconds for testing print("dbMaker: done, you f**k.") fileName.close() return count
def runBurner(): global gDone while not threadQuit: tomGreen = Sub.select().where(Sub.status == gcode).count() if tomGreen > 0: if tomGreen >= 10: LED_Grn.blink() else: LED_Grn.on() if streamerToggle: gDone = False gSend() gDone = True else: LED_Grn.off()
def main(): fileName = open("subscriberListTest.txt") print("making:") for entry in fileName: entry = entry.strip() dateTime = datetime.utcnow() dbEntry = Sub.create( userName=entry, entryTime=dateTime, status=2, # userName = '******', fontSize=72, positionX=1000, positionY=1000) print(entry) time.sleep(0.2) dbEntry.save() print("done, you f**k.") fileName.close()
def runPlace(): while not threadQuit: noNotPlaced = Sub.select().where(Sub.status == entered).count() if noNotPlaced > 0: placeNames()
def placeNames(): try: center = Image.open(centerFile) except: print("placer: couldn't open center PNG") #sys exit, shut down threads? backing = Image.new('RGBA', (board_l, board_h), color=(255, 255, 255, 255)) draw = ImageDraw.Draw(backing) #overlay center keepout print("placer: making virtual backing, secretly") center_l, center_h = center.size centerPos_l = int((board_l / 2) - (center_l / 2)) centerPos_h = int((board_h / 2) - (center_h / 2)) backing.alpha_composite(center, (centerPos_l, centerPos_h)) #create backing image based on db nameWasPlaced = (Sub.select().where(Sub.status >= placed)) for place in nameWasPlaced: font = ImageFont.truetype(ttfFont, place.fontSize) draw.text((place.positionX, place.positionY), place.userName, (0, 0, 0), font=font) #check database for names to place nameToPlace = (Sub.select().where(Sub.status == entered).order_by( Sub.entryTime)) for sub in nameToPlace: LED_TYel.on() totalEntries = Sub.select().where(Sub.status >= placed).count() fontSize = fscale(fontMin, fontMax, totalEntries, curve) blurRad = int(fontSize / bScale) #pixel radius of blur fail = True print("placer: " + sub.userName) #this should be a function for font choice based on number of existing names #the database population function/module/program should do this font = ImageFont.truetype(ttfFont, fontSize) l, h = font.getsize(sub.userName) l += (blurRad * 2) h += (blurRad * 2) textBox = Image.new('RGBA', (l, h), color=(255, 255, 255, 255)) draw1 = ImageDraw.Draw(textBox) draw1.text((blurRad, blurRad), sub.userName, (0, 0, 0), font=font) textBox = textBox.filter(ImageFilter.GaussianBlur(radius=blurRad)) while fail == True: #instead just do a random location for test board_l2 = board_l - l board_h2 = board_h - h pixOffset = border * pixMM Rboard_l = random.randint((0 + pixOffset), (board_l2 - pixOffset)) Rboard_h = random.randint((0 + pixOffset), (board_h2 - pixOffset)) fail = False #look for collision for i in range(0, l, 1): for j in range(0, h, 1): shift_l = i + Rboard_l shift_h = j + Rboard_h r, g, b, a = backing.getpixel((shift_l, shift_h)) r1, g1, b1, a1 = textBox.getpixel((i, j)) #compare backing to text for overlap if (r, g, b, a) != (255, 255, 255, 255) and ( r1, g1, b1, a1) != (255, 255, 255, 255): print("placer: :failfish:") LED_TYel.blink() fail = True break if fail == True: break #now overlay that onto the board draw.text((Rboard_l + blurRad, Rboard_h + blurRad), sub.userName, (0, 0, 0), font=font) #update db with good location #sub.transaction(lock_type=None) sub.positionX = Rboard_l + blurRad sub.positionY = Rboard_h + blurRad sub.fontSize = fontSize sub.status = placed sub.save() LED_TYel.off() makeGcode(sub)