save before reorient
This commit is contained in:
parent
016e459a1f
commit
f5eaa0603b
2 changed files with 107 additions and 27 deletions
64
itplus.py
Executable file
64
itplus.py
Executable file
|
@ -0,0 +1,64 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
from raspyrfm import *
|
||||||
|
import sensors
|
||||||
|
from sensors import rawsensor
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
import threading
|
||||||
|
|
||||||
|
|
||||||
|
#if raspyrfm_test(2, RFM69):
|
||||||
|
# print("Found RaspyRFM twin")
|
||||||
|
# rfm = RaspyRFM(2, RFM69) #when using the RaspyRFM twin
|
||||||
|
#elif raspyrfm_test(1, RFM69):
|
||||||
|
# print("Found RaspyRFM single")
|
||||||
|
# rfm = RaspyRFM(1, RFM69) #when using a single 868 MHz RaspyRFM
|
||||||
|
if raspyrfm_test(5, RFM69):
|
||||||
|
print("Found RaspyRFM mod")
|
||||||
|
rfm = RaspyRFM(5, RFM69) #when using the RaspyRFM twin
|
||||||
|
else:
|
||||||
|
print("No RFM69 module found!")
|
||||||
|
exit()
|
||||||
|
|
||||||
|
rfm.set_params(
|
||||||
|
Freq = 868.30, #MHz center frequency
|
||||||
|
# Datarate = 9.579, #kbit/s baudrate
|
||||||
|
Datarate = 17.241, #kbit/s baudrate
|
||||||
|
ModulationType = rfm69.FSK, #modulation
|
||||||
|
Deviation = 30, #kHz frequency deviation
|
||||||
|
SyncPattern = [0x2d, 0xd4], #syncword
|
||||||
|
Bandwidth = 150, #kHz bandwidth
|
||||||
|
RssiThresh = -105, #dBm RSSI threshold
|
||||||
|
)
|
||||||
|
|
||||||
|
class BaudChanger(threading.Thread):
|
||||||
|
baud = False
|
||||||
|
def __init__(self):
|
||||||
|
threading.Thread.__init__(self)
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
while True:
|
||||||
|
time.sleep(15)
|
||||||
|
if self.baud:
|
||||||
|
dr = 9.579
|
||||||
|
else:
|
||||||
|
dr = 17.241
|
||||||
|
print("Switch baudrate to " + str(dr) + " kbit/s")
|
||||||
|
rfm.set_params(Datarate = dr)
|
||||||
|
self.baud = not self.baud
|
||||||
|
|
||||||
|
#baudChanger = BaudChanger()
|
||||||
|
#baudChanger.daemon = True
|
||||||
|
#baudChanger.start()
|
||||||
|
|
||||||
|
while 1:
|
||||||
|
data = rfm.receive(12)
|
||||||
|
if data == None:
|
||||||
|
continue
|
||||||
|
|
||||||
|
obj = rawsensor.CreateSensor(data).GetData()
|
||||||
|
if not 'ID' in obj:
|
||||||
|
continue
|
||||||
|
print(obj)
|
||||||
|
|
|
@ -32,23 +32,25 @@ class TextBox:
|
||||||
self.size = size
|
self.size = size
|
||||||
self.img = Image.new("RGB", self.bounds)
|
self.img = Image.new("RGB", self.bounds)
|
||||||
self.draw = ImageDraw.Draw(self.img)
|
self.draw = ImageDraw.Draw(self.img)
|
||||||
|
self.offset = (int((self.size[0]-self.bounds[0])/2), int((self.size[1]-self.bounds[1])/2))
|
||||||
|
|
||||||
def draw_text(self, display, text, jitter_pos):
|
def draw_text(self, display, text, jitter_pos):
|
||||||
self.draw.rectangle((0, 0, self.img.width-1, self.img.height-1), self.background, self.color, 1)
|
self.draw.rectangle((0, 0, self.img.width-1, self.img.height-1), self.background, self.background, 1)
|
||||||
self.draw.text(jitter_pos, text, font=self.font, fill=self.color)
|
self.draw.text((jitter_pos[0],0), text, font=self.font, fill=self.color)
|
||||||
print(f"self:{str(self.__dict__)}")
|
y=self.pos[0]+self.offset[0]
|
||||||
display.image(self.img, y=self.pos[0], x=display.width-self.pos[1])
|
x=display.width-self.pos[1]-self.size[1]+self.offset[1]
|
||||||
|
display.image(self.img, x=x, y=y)
|
||||||
|
|
||||||
|
###
|
||||||
|
# CONFIGURATION
|
||||||
|
###
|
||||||
|
|
||||||
|
BAUDRATE = 1000000
|
||||||
BAUDRATE = 24000000
|
|
||||||
|
|
||||||
DISPLAY_SIZE=(320,240)
|
DISPLAY_SIZE=(320,240)
|
||||||
DAY_BRIGHT = 65535
|
|
||||||
NIGHT_BRIGHT = 4096
|
|
||||||
|
|
||||||
CLOCK_FORMAT = "%H:%M"
|
CLOCK_FORMAT = "%H:%M"
|
||||||
TEMP_FORMAT = "% 2.1f°C"
|
TEMP_FORMAT = "% 3.1f°C"
|
||||||
|
|
||||||
BKGND_COLOR=(0,0,0)
|
BKGND_COLOR=(0,0,0)
|
||||||
LINE_COLOR=(255,255,255)
|
LINE_COLOR=(255,255,255)
|
||||||
|
@ -60,8 +62,8 @@ now_parts=time.localtime()
|
||||||
time_str = time.strftime(CLOCK_FORMAT, now_parts)
|
time_str = time.strftime(CLOCK_FORMAT, now_parts)
|
||||||
temp_str = TEMP_FORMAT % -10.0
|
temp_str = TEMP_FORMAT % -10.0
|
||||||
|
|
||||||
clock_box=TextBox( (0,0), (300,90), JITTER, (255,255,255), BKGND_COLOR, time_str)
|
clock_box=TextBox( (10,10), (300,120), JITTER, (255,255,255), BKGND_COLOR, time_str)
|
||||||
temp_box =TextBox( (160,200), (160,40), JITTER, (255,0,0), BKGND_COLOR, temp_str)
|
temp_box =TextBox( (120,180), (190,50), JITTER, (255,0,0), BKGND_COLOR, temp_str)
|
||||||
|
|
||||||
# Configuration for CS and DC pins:
|
# Configuration for CS and DC pins:
|
||||||
CS_PIN = D8
|
CS_PIN = D8
|
||||||
|
@ -83,10 +85,10 @@ display = ili9341.ILI9341(spi,
|
||||||
rotation=270)
|
rotation=270)
|
||||||
|
|
||||||
|
|
||||||
backlight = pulseio.PWMOut(BL_PIN, duty_cycle=NIGHT_BRIGHT)
|
#backlight = pulseio.PWMOut(BL_PIN, duty_cycle=NIGHT_BRIGHT)
|
||||||
#backlight = digitalio.DigitalInOut(BL_PIN)
|
backlight = digitalio.DigitalInOut(BL_PIN)
|
||||||
#backlight.direction = digitalio.Direction.OUTPUT
|
backlight.direction = digitalio.Direction.OUTPUT
|
||||||
#backlight.value = True
|
backlight.value = True
|
||||||
|
|
||||||
|
|
||||||
if raspyrfm_test(5, RFM69):
|
if raspyrfm_test(5, RFM69):
|
||||||
|
@ -128,11 +130,10 @@ def update_temp():
|
||||||
|
|
||||||
temp_thread = threading.Thread(target=update_temp, name="Temp Thread")
|
temp_thread = threading.Thread(target=update_temp, name="Temp Thread")
|
||||||
|
|
||||||
#temp_thread.start()
|
temp_thread.start()
|
||||||
|
|
||||||
|
|
||||||
display.fill(color565(BKGND_COLOR))
|
#display.vline(0,clock_box.size[1],1,color565(LINE_COLOR))
|
||||||
display.vline(0,clock_box.size[1],1,color565(LINE_COLOR))
|
|
||||||
|
|
||||||
def jitter():
|
def jitter():
|
||||||
return (random.randint(0,JITTER), random.randint(0,JITTER))
|
return (random.randint(0,JITTER), random.randint(0,JITTER))
|
||||||
|
@ -140,29 +141,44 @@ def jitter():
|
||||||
# Main loop:
|
# Main loop:
|
||||||
jitter_pos = jitter()
|
jitter_pos = jitter()
|
||||||
|
|
||||||
|
old_time=""
|
||||||
|
old_temp=""
|
||||||
|
|
||||||
|
display.fill(color565(BKGND_COLOR))
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
|
check_pixel = display.read((0,0)
|
||||||
|
#display.reset()
|
||||||
|
#time.sleep(0.5)
|
||||||
|
|
||||||
now = time.time()
|
now = time.time()
|
||||||
now_parts = time.localtime(now)
|
now_parts = time.localtime(now)
|
||||||
|
|
||||||
time_str = time.strftime(CLOCK_FORMAT, now_parts)
|
time_str = time.strftime(CLOCK_FORMAT, now_parts)
|
||||||
temp_str = TEMP_FORMAT % mean_temp
|
temp_str = TEMP_FORMAT % mean_temp
|
||||||
|
|
||||||
clock_box.draw_text(display, time_str, jitter_pos)
|
if time_str != old_time:
|
||||||
|
clock_box.draw_text(display, time_str, jitter_pos)
|
||||||
|
old_time = time_str
|
||||||
|
|
||||||
if now_parts.tm_sec:# == 0:
|
if now_parts.tm_sec == 0:
|
||||||
jitter_pos = jitter()
|
jitter_pos = jitter()
|
||||||
|
|
||||||
if (now_parts.tm_min == 0) and (now_parts.tm_hour > 7 and now_parts.tm_hour < 19):
|
|
||||||
backlight.duty_cycle = DAY_BRIGHT
|
|
||||||
else:
|
|
||||||
backlight.duty_cycle = NIGHT_BRIGHT
|
|
||||||
|
|
||||||
|
# if (now_parts.tm_min == 0) and (now_parts.tm_hour > 7 and now_parts.tm_hour < 19):
|
||||||
|
# backlight.duty_cycle = DAY_BRIGHT
|
||||||
|
# else:
|
||||||
|
# backlight.duty_cycle = NIGHT_BRIGHT
|
||||||
|
if temp_str != old_temp:
|
||||||
|
time.sleep(0.1)
|
||||||
|
temp_box.draw_text(display, temp_str, jitter_pos)
|
||||||
|
old_temp = temp_str
|
||||||
|
|
||||||
while time.time() - now < DELAY:
|
while time.time() - now < DELAY:
|
||||||
time.sleep(0.1*DELAY)
|
time.sleep(0.1*DELAY)
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
clock_box.draw_text(display, "off" ,(0,0))
|
clock_box.draw_text(display, "off" ,(0,0))
|
||||||
|
temp_box.draw_text(display,"",(0,0))
|
||||||
shutdown=True
|
shutdown=True
|
||||||
# temp_thread.join()
|
temp_thread.join()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue