Capen Inkplate

master
Oliver Kennedy 2024-03-20 16:50:19 -04:00
parent 05651f6ee3
commit 3531ca36aa
Signed by: okennedy
GPG Key ID: 3E5F9B3ABD3FDB60
9 changed files with 310 additions and 0 deletions

Binary file not shown.

48
Makefile Normal file
View File

@ -0,0 +1,48 @@
BOARD=soldered_inkplate6PLUS
GPIO=PCAL6416A
all: lib
lib: installed/ub_sched.py installed/ub_devices.py installed/conf_room_layout.py
main: lib
python3 pyboard.py --device /dev/ttyUSB0 -f cp conf_room/main.py :
screen /dev/ttyUSB0 115200
installed/ub_sched.py: conf_room/ub_sched.py
python3 pyboard.py --device /dev/ttyUSB0 -f cp conf_room/ub_sched.py :
cp conf_room/ub_sched.py installed/
installed/ub_devices.py: conf_room/ub_devices.py
python3 pyboard.py --device /dev/ttyUSB0 -f cp conf_room/ub_devices.py :
cp conf_room/ub_devices.py installed/
installed/conf_room_layout.py: conf_room/conf_room_layout.py
python3 pyboard.py --device /dev/ttyUSB0 -f cp conf_room/conf_room_layout.py :
cp conf_room/conf_room_layout.py installed/
test: lib
# ./pyboard.py --device /dev/ttyUSB0 -c 'from ub_sched import RoomSchedule, ROOM_CAPEN_212A; import ub_devices; ub_devices.connect(); print(RoomSchedule(ROOM_CAPEN_212A).fetch())'
./pyboard.py --device /dev/ttyUSB0 -c 'from conf_room_layout import refresh; refresh()'
ping:
./pyboard.py --device /dev/ttyUSB0 -c 'print("pong")' #--follow
connect_wifi: lib
./pyboard.py --device /dev/ttyUSB0 -c 'import ub_devices; ub_devices.connect();' #--follow
setup_board:
python3 -m esptool --port /dev/ttyUSB0 erase_flash
python3 -m esptool --port /dev/ttyUSB0 write_flash \
-z 0x1000 esp32spiram-20220117-v1.18.bin
python3 pyboard.py --device /dev/ttyUSB0 -f cp \
${GPIO}.py ${BOARD}.py image.py shapes.py gfx.py \
gfx_standard_font_01.py soldered_logo.py :
install_prereqs:
pip3 install esptool
connect_serial:
screen /dev/ttyUSB0 115200
.PHONY: all lib main test ping setup_board install_prereqs connect_serial connect_wifi

View File

@ -0,0 +1,110 @@
from soldered_inkplate6PLUS import Inkplate
import time
from ub_sched import Event
START_HOUR = 8
END_HOUR = 18
DISPLAY = Inkplate(Inkplate.INKPLATE_2BIT)
DISPLAY.begin()
BLACK = 0
MONTHS = [
"???",
"Jan.",
"Feb.",
"Mar.",
"Apr.",
"May ",
"Jun.",
"Jul.",
"Aug.",
"Sep.",
"Oct.",
"Nov.",
"Dec.",
]
WEEKDAYS = [
"Mon.",
"Tue.",
"Wed.",
"Thu.",
"Fri.",
"Sat.",
"Sun.",
]
def date_str():
(year, month, mday, hour, minute, second, weekday, yearday) = time.localtime()
# print(weekday, month, mday, year)
return
def drawText(x, y, s, size = DISPLAY.textSize, color = BLACK):
DISPLAY.GFX._very_slow_text(x, y, s, size, color)
def render_display(events):
(year, month, mday, hour, minute, second, weekday, yearday) = time.localtime()
display = DISPLAY
print("On a display of size", display.width(), display.height())
print("Xu Li... Do the thing!")
display.clearDisplay()
print("Drawing header")
drawText(20, 20, "Capen 212A", size = 4)
drawText(680, 30, "{} {} {}, {}".format(WEEKDAYS[weekday], MONTHS[month], mday, year), size = 3)
display.drawFastHLine(0, 60, display.width(), BLACK)
calendar_top = 60
calendar_left = 10
calendar_height = display.height() - calendar_top;
calendar_width = display.width() - 20;
hour_step = calendar_height / (END_HOUR - START_HOUR)
print("Drawing day planner")
for i in range(START_HOUR, END_HOUR):
y = int( (i - START_HOUR) * hour_step + calendar_top )
display.drawFastHLine(
int(calendar_left+40), y,
calendar_width-40,
BLACK
)
hour = i
ampm = "AM"
if hour >= 12:
ampm = "PM"
if hour > 12:
hour -= 12
drawText(10, y+2, "{} {}".format(hour, ampm), size = 1)
print("Drawing events")
for event in events:
if event.start.is_date(year, month, mday) or event.end.is_date(year, month, mday):
print("Drawing {}".format(event.event))
if (not event.start.is_date(year, month, mday)) or event.start.hour < START_HOUR:
low_hour = 0.0
else:
low_hour = event.start.hour + (event.start.minute / 60) - START_HOUR
if (not event.end.is_date(year, month, mday)) or event.end.hour >= END_HOUR:
high_hour = float(END_HOUR - START_HOUR)
else:
high_hour = event.end.hour + (event.end.minute / 60) - START_HOUR
x0 = calendar_left+50
y0 = int(low_hour * hour_step) + calendar_top + 10
w = calendar_width-60
h = int((high_hour - low_hour) * hour_step) - 20
radius = 8
print(low_hour, high_hour, "//", x0, y0, w, h)
display.fillRoundRect(x0, y0, w, h, radius, 1)
display.drawRoundRect(x0, y0, w, h, radius, 0)
drawText(x0+10, y0+10, event.event, size = 2)
else:
print("Skipping {}; not today".format(event.event))
print("Rendering")
display.display()

23
conf_room/main.py Normal file
View File

@ -0,0 +1,23 @@
import ub_devices
import ub_sched
from conf_room_layout import render_display
from time import sleep
sleep(2)
print("Main script!")
sleep(1)
print("Connecting to wifi")
ub_devices.connect()
room = ub_sched.RoomSchedule(ub_sched.ROOM_CAPEN_212A)
while True:
try:
print("Fetching events")
events = room.fetch()
render_display(events)
sleep(600)
except Exception as e:
print(e)
sleep(30)

24
conf_room/ub_devices.py Normal file
View File

@ -0,0 +1,24 @@
# Connection Settings for UB_Devices
# - Oliver Kennedy okennedy@buffalo.edu
# Based on...
# https://www.buffalo.edu/ubit/service-guides/connecting/resnet/boost-gaming.html
import network
import ntptime
from time import sleep
def connect():
nic = network.WLAN(network.STA_IF)
nic.active(True)
while not nic.isconnected():
print("Connecting to wifi...")
nic.connect('UB_Devices', 'goubbulls')
for i in range(1, 10):
if nic.isconnected():
break
sleep(1)
if not nic.isconnected():
print("Connection failed. Sleeping.")
sleep(5)
ntptime.settime()

104
conf_room/ub_sched.py Normal file
View File

@ -0,0 +1,104 @@
# Room Schedule Lookup
# - Oliver Kennedy okennedy@buffalo.edu
# - Adapted from a shell script by Grant Iraci
# https://gist.github.com/iracigt/181d8f0feafb07ec39b26d4869bffd0d
import urequests as request
import json
import time
# Other useful ROOM_IDs:
ROOM_DAVIS_113A = 1768
ROOM_DAVIS_338A = 1769
ROOM_DAVIS_113Y = 3199
ROOM_DAVIS_310 = 2941
ROOM_DAVIS_337 = 3065
ROOM_DAVIS_101 = 611
ROOM_DAVIS_1ST_FLOOR_ATRIUM = 2409
ROOM_DAVIS_2ND_FLOOR_LOUNGE = 2410
ROOM_CAPEN_212A = 3215
ROOM_ANY = -1
# Other useful BLDG_IDs:
BUILDING_DAVIS_HALL = 74
BUILDING_ANY_BUILDING = -1
UB_SCHED_URL = "https://spacerequest.buffalo.edu/EVNTWebApp/AnonymousServersApi.aspx/CustomBrowseEvents"
def dateoct_to_iso(dateoct):
(year, month, mday, hour, minute, second, weekday, yearday) = dateoct
return "{:04}-{:02}-{:02}T{:02}:{:02}:{:02}".format(year, month, mday, hour, minute, second)
def iso_to_datehex(iso):
(iday, itime) = iso.split("T")
(year, month, mday) = iday.split("-")
(hour, minute, second) = itime.split(":")
return (int(year), int(month), int(mday), int(hour), int(minute), int(second))
class EventTime:
def __init__(self, iso):
(iday, itime) = iso.split("T")
(year, month, mday) = iday.split("-")
(hour, minute, second) = itime.split(":")
self.year = int(year)
self.month = int(month)
self.mday = int(mday)
self.hour = int(hour)
self.minute = int(minute)
self.second = int(second)
def is_date(self, year, month, mday):
# print("{} == {} / {} == {} / {} == {}".format(self.year, year, self.month, month, self.mday, mday))
return (int(self.year) == int(year)) and (int(self.month) == int(month)) and (int(self.mday) == int(mday))
class Event:
def __init__(self, e):
self.event = e["EventName"]
self.start = EventTime(e["TimeBookingStart"])
self.end = EventTime(e["TimeBookingEnd"])
self.room = e["Room"]
self.creator = e["GroupName"]
class RoomSchedule:
def __init__(self, room, building = BUILDING_ANY_BUILDING):
self.BLDG_ID = building
self.ROOM_ID = room
def fetch(self):
req = {
"date": dateoct_to_iso(time.localtime()),
"data": {
"BuildingId": self.BLDG_ID,
"GroupTypeId": -1,
"GroupTypeId": -1,
"GroupId":-1,
"EventTypeId":-1,
"RoomId": self.ROOM_ID,
"StatusId":-1,
"ZeroDisplayOnWeb":0,
"HeaderUrl":"",
"Title":"",
"Format":1,
"Rollup":0,
"EncryptD":"https://spacerequest.buffalo.edu/EVNTWebApp/CustomBrowseEvents.aspx",
"PageSize":1000,
"DropEventsInPast":False
}
}
resp = request.post(
url=UB_SCHED_URL,
json=req,
headers={
"Accept": "application/json, text/javascript"
}
)
wrapper = resp.json()["d"]
bookings = [
Event(e)
for e in json.loads(wrapper)["MonthlyBookingResults"]
]
return bookings
if __name__ == '__main__':
room = RoomSchedule(ROOM_CAPEN_212A)
print(room.fetch())

1
installed/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*

0
installed/.gitpreserve Normal file
View File

0
pyboard.py Normal file → Executable file
View File