コード例 #1
0
def test():

	color = divoom_image.BMP_BLUE

	SYMBOL = "BTCUSDT"

	json_url = urllib.urlopen("https://www.binance.com/api/v3/ticker/24hr?symbol="+SYMBOL)
	data = json.loads(json_url.read())
	
	
	if float(data["priceChange"]) < 0:
		arrow = u"\u2193"
		color = divoom_image.BMP_RED
	elif float(data["priceChange"]) == 0:
		arrow = u"\u2194"
	else:
		arrow = u"\u2191"
		color = divoom_image.BMP_GREEN
	
	
	TEXT = arrow+str(int(round(float(data["lastPrice"]))))
	
	
	img = divoom_image.draw_text_to_image(text=TEXT, color=color, size=(70, 10))
	sliced_images = divoom_image.horizontal_slices(img)
	# create divoom packages
	raw_data_packages = []
	# thing.create_off_package() #brightness
	for img in sliced_images:
		raw_data_packages.append(divoom_image.to_divoom_data(img))
	# create BT divoom packages

	pkgs = thing.create_animation_packages(raw_data_packages, 1)
	for i in range(0, len(pkgs)):
		dev.send(pkgs[i])
コード例 #2
0
 def draw_text(self, text="HELLO WORLD"):
     img = divoom_image.draw_text_to_image(text=text, color=divoom_image.BMP_YELLOW, size=(70, 10))
     sliced_images = divoom_image.horizontal_slices(img)
     # create divoom packages
     raw_data_packages = []
     for img in sliced_images:
         raw_data_packages.append(divoom_image.to_divoom_data(img))
     # create BT divoom packages
     pkgs = self.protocol.create_animation_packages(raw_data_packages, 1)
     for i in range(0, len(pkgs)):
         self.device.send(pkgs[i])
コード例 #3
0
def old_to_new(old_img, new_img, way=1):

    sliced_images = divoom_image.scroll_between(old_img, new_img, way)
    pkgs = []
    # prepare the data before sending it
    for img in sliced_images:
        img_raw_bytes = divoom_image.to_divoom_data(img)
        img_bytes = thing.create_image_package(img_raw_bytes)
        pkgs.append(img_bytes)
    # send single images to divoom
    for pkg in pkgs:
        dev.send(pkg)
        time.sleep(0.1)
コード例 #4
0
def hello_world():
    img = divoom_image.draw_text_to_image(text="HELLO WORLD",
                                          color=divoom_image.BMP_YELLOW,
                                          size=(70, 10))
    sliced_images = divoom_image.horizontal_slices(img)
    # create divoom packages
    raw_data_packages = []
    for img in sliced_images:
        raw_data_packages.append(divoom_image.to_divoom_data(img))
    # create BT divoom packages
    pkgs = thing.create_animation_packages(raw_data_packages, 1)
    for i in range(0, len(pkgs)):
        dev.send(pkgs[i])
コード例 #5
0
    def test_image_and_back_example7(self):
        img = Image.open(self.TESTDATA_DIR + "example7.bmp")
        divoom_data = divoom_image.to_divoom_data(img)
        img2 = divoom_image.divoom_to_image(divoom_data)

        #replace all non-unique keys
        img2data = list(img2.getdata())
        for idx, item in enumerate(img2data):
            if item == 1:  # red is 9 & 1
                img2data[idx] = 9

        self.assertEquals(len(img.getdata()), len(img2.getdata()))
        self.assertItemsEqual(img.getdata(), img2data)
コード例 #6
0
def scroll_sequence():
    img_1 = Image.open(imagename("example7.bmp"))
    img_2 = Image.open(imagename("example9.bmp"))
    img_3 = Image.open(imagename("firework6.bmp"))
    img_4 = Image.open(imagename("example3.bmp"))
    img_5 = Image.open(imagename("example5.bmp"))

    dev.send(thing.create_temp_package())
    time.sleep(1)
    first_img_raw_bytes = divoom_image.to_divoom_data(img_1)
    first_img_bytes = thing.create_image_package(first_img_raw_bytes)
    dev.send(first_img_bytes)
    time.sleep(4)

    old_to_new(img_1, img_2, 1)
    time.sleep(1)
    old_to_new(img_2, img_3, 2)
    time.sleep(1)
    old_to_new(img_3, img_4, 3)
    time.sleep(1)
    old_to_new(img_4, img_5, 4)
コード例 #7
0
    def scroll_sequence(self):
        img_1 = Image.open("images/example7.bmp")
        img_2 = Image.open("images/example9.bmp")
        img_3 = Image.open("images/firework6.bmp")
        img_4 = Image.open("images/example3.bmp")
        img_5 = Image.open("images/example5.bmp")

        self.device.send(self.protocol.create_temp_package())
        time.sleep(1)
        first_img_raw_bytes = divoom_image.to_divoom_data(img_1)
        first_img_bytes = self.protocol.create_image_package(first_img_raw_bytes)
        self.device.send(first_img_bytes)
        time.sleep(4)

        self.old_to_new(img_1, img_2, 1)
        time.sleep(1)
        self.old_to_new(img_2, img_3, 2)
        time.sleep(1)
        self.old_to_new(img_3, img_4, 3)
        time.sleep(1)
        self.old_to_new(img_4, img_5, 4)
コード例 #8
0
 def test_image_and_back_black(self):
     img = Image.open(self.TESTDATA_DIR + "black.bmp")
     divoom_data = divoom_image.to_divoom_data(img)
     img2 = divoom_image.divoom_to_image(divoom_data)
     self.assertEquals(len(img.getdata()), len(img2.getdata()))
     self.assertItemsEqual(img.getdata(), img2.getdata())