scrolling text functionality added

This commit is contained in:
Neythen 2021-05-14 11:31:14 +01:00
parent 4374934237
commit d9df697ca7
8 changed files with 77 additions and 48 deletions

View File

@ -1 +1 @@
08/05/2021 07:09:36
14/05/2021 06:29:45

1 08/05/2021 07:09:36 14/05/2021 06:29:45

View File

@ -1,22 +1,22 @@
name,current,opening
MSFT,252.46,252.15
NFLX,503.84,504.62
GOOG,2398.69,2400
TSLA,672.08,665.8
AAPL,130.21,130.85
INTC,57.67,57.7
TXN,187.76,186.7
HPQ,35.57,34.99
HOG,49.71,48.96
LUV,61.66,60.68
WMT,140.2,141.63
BJ,45.86,46.59
ETSY,165.51,163.93
G,47.13,47.11
GDDY,81.06,81.78
GNRC,327.38,319.52
PEP,145.56,145.23
STM,37.33,37.31
YELP,39.46,38.86
XRAY,68.47,67.39
ZTS,171.55,169.19
MSFT,243.03,241.8
NFLX,486.66,489.13
GOOG,2261.97,2261.09
TSLA,571.69,601.545
AAPL,124.97,124.58
INTC,54.01,54.04
TXN,178.99,179.99
HPQ,32.39,32
HOG,46.25,45.35
LUV,59.93,58.97
WMT,138.24,136.23
BJ,45.99,45.63
ETSY,156.59,163.3368
G,44.51,43.84
GDDY,79.29,80.92
GNRC,293.36,294.17
PEP,146.37,144.24
STM,34.81,35.28
YELP,38.14,37.39
XRAY,66.61,65.83
ZTS,170.85,168.37

1 name current opening
2 MSFT 252.46 243.03 252.15 241.8
3 NFLX 503.84 486.66 504.62 489.13
4 GOOG 2398.69 2261.97 2400 2261.09
5 TSLA 672.08 571.69 665.8 601.545
6 AAPL 130.21 124.97 130.85 124.58
7 INTC 57.67 54.01 57.7 54.04
8 TXN 187.76 178.99 186.7 179.99
9 HPQ 35.57 32.39 34.99 32
10 HOG 49.71 46.25 48.96 45.35
11 LUV 61.66 59.93 60.68 58.97
12 WMT 140.2 138.24 141.63 136.23
13 BJ 45.86 45.99 46.59 45.63
14 ETSY 165.51 156.59 163.93 163.3368
15 G 47.13 44.51 47.11 43.84
16 GDDY 81.06 79.29 81.78 80.92
17 GNRC 327.38 293.36 319.52 294.17
18 PEP 145.56 146.37 145.23 144.24
19 STM 37.33 34.81 37.31 35.28
20 YELP 39.46 38.14 38.86 37.39
21 XRAY 68.47 66.61 67.39 65.83
22 ZTS 171.55 170.85 169.19 168.37

BIN
final.ppm

Binary file not shown.

Binary file not shown.

View File

@ -137,6 +137,16 @@ def Brightness():
LastCommand = 'Change Brightness'
return hello()
@app.route("/Display_text", methods=['POST'])
def Display_text():
text = request.form['text']
f = open('csv/scroll_text.csv', 'w+')
f.write(text)
f.close()
ticker.sendline('T')
return hello()
@app.route("/Ticker", methods=['POST'])
def Ticker():
if request.method == 'POST':

View File

@ -15,7 +15,7 @@ import csv
import requests
import pexpect
from rgbmatrix import RGBMatrix, RGBMatrixOptions
from rgbmatrix.graphics import *
def getInput(Block=False):
if Block or select.select([sys.stdin], [], [], 0) == ([sys.stdin], [], []):
@ -98,7 +98,7 @@ class StockTicker():
self.setImage(image, offset_x = offset_x, offset_y = offset_y)
time.sleep(delay)
def scrollImageTransition(self, image_files, offset_x = 0, offset_y = 0):
def scrollImageTransition(self, image_files, offset_x = 0, offset_y = 0, stocks = True):
# use two image files and switch between them with a seemless transition
current_img = 1
@ -106,18 +106,16 @@ class StockTicker():
while True:
if current_img == 1:
self.getFullStockImage(1)
if stocks: self.getFullStockImage(1)
image1 = self.openImage(image_files[0])
image2 = self.openImage(image_files[1])
elif current_img == 2:
self.getFullStockImage(2)
if stocks: self.getFullStockImage(2)
image1 = self.openImage(image_files[1])
image2 = self.openImage(image_files[0])
img_width, img_height = image1.size
print('wh:', self.matrix.width, self.matrix.height)
while offset_x > -img_width:
@ -157,6 +155,29 @@ class StockTicker():
current_img = 1
offset_x = 0
def displayText(self):
f = open('csv/scroll_text.csv', 'r')
CSV = csv.reader(f)
text, r, g, b = next(CSV)
f.close()
font = ImageFont.load("./fonts/texgyre-27.pil")
width, height = self.get_text_dimensions(text, font)
print(text)
print('dims:', width, height)
img = Image.new('RGB', (width + 10, 32))
d = ImageDraw.Draw(img)
d.text((4, 0), text, fill=(int(r), int(g), int(b)), font=font)
img.save('scroll_text.ppm')
self.scrollImageTransition(['scroll_text.ppm', 'scroll_text.ppm'], offset_x = 128, offset_y = 0, stocks = False)
#Using change between min and day price give appropriate arrow
#and set the overall change colour
@ -173,7 +194,7 @@ class StockTicker():
return Arrow, CHANGE
def get_text_dimensions(self, text_string, font):
canvas = Image.new('RGB', (100,100))
canvas = Image.new('RGB', (10000,100))
draw = ImageDraw.Draw(canvas)
monospace = font
@ -219,7 +240,8 @@ class StockTicker():
for im in image_list:
new_im.paste(im, (x_offset,0))
x_offset += im.size[0]
print('width:', im.size[0])
return new_im
def resetMatrix(self):
@ -274,7 +296,7 @@ class StockTicker():
finalDisplayImage.save('final1.ppm')
#Send the final stitched image to the display for set amount of time
def displayMatrix(self):
def displayStocks(self):
#os.system("sudo ./demo -D1 final.ppm -t " + str(displayTime) +" -m "+ str(speedDisplay) +" --led-gpio-mapping=adafruit-hat --led-rows=32 --led-cols=256")
#os.system("sudo ./demo -D1 final.ppm -t " + str(self.displayTime) +" -m "+ str(self.speedDisplay) +" --led-gpio-mapping=adafruit-hat --led-rows=64 --led-cols=64 --led-slowdown-gpio=4 ")
self.scrollImageTransition(['final.ppm', 'final.ppm'], offset_x = 0, offset_y = 0)
@ -340,7 +362,7 @@ class StockTicker():
if msg == 'S':
self.getFullStockImage(1)
self.displayMatrix()
self.displayStocks()
elif msg == 's':
@ -355,30 +377,21 @@ class StockTicker():
elif msg in ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']:
self.brightness = min(1.0, float(msg)/10 + 0.1)
elif msg == 'T':
self.displayText()
if __name__ == '__main__':
#print(sys.stdin.readlines())
stock_ticker = StockTicker()
csv_path = os.path.join(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'csv'), 'settings.csv')
f = open(csv_path)
CSV = csv.reader(f)
for row in CSV:
speed, brightness = row
print(speed, brightness)
#stock_ticker.process_msg(brightness)
#stock_ticker.process_msg(speed)
#stock_ticker.displayText()
#stock_ticker.displayStocks()
#t = time.time()
#api_caller = pexpect.spawn("sudo -E python3 api_caller.py")
#print('time to call api', time.time()-t)
#stock_ticker.getFullStockImage(1)
#stock_ticker.displayMatrix()
while True:

View File

@ -29,6 +29,12 @@
<input type="submit" value="Brightness"style="height:30px">
</form>
<p>Display scrolling text. Enter the message followed by the rgb values seperated by commas. e.g. hello world!,255,255,0</p>
<form action="/Display_text" method="POST">
<input name="text" placeholder="hello world!,255,255,0"style="height:24px">
<input type="submit" value="Display"style="height:30px">
</form>
<br><br>
<h3>Tickers to display</h3>
<p>To change the tickers displayed please upload a CSV (comma separated value) file with 11 tickers on each row e.g</p>