1.0 Alpha

This commit is contained in:
Zahkc 2023-07-23 19:03:06 +10:00 committed by GitHub
parent 8069a1cfa5
commit 5816616c33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 136 additions and 76 deletions

4
Activities/Games/test.py Normal file
View File

@ -0,0 +1,4 @@
x = "test"
def printit():
print(x)

65
Activities/States/home.py Normal file
View File

@ -0,0 +1,65 @@
import time
import menu
import alarm
import board
import entity
import animate
import selector
import displayio
import buttonBus
import adafruit_imageload
class home:
root = displayio.Group()
entity = entity.entity()
select = selector.selector([[5,0],[40,0],[70,0],[90,0],[0,220],[110,220]])
def __init__(self, root, entity):
self.root = root
self.entity = entity
self.entity.show(root[2])
bg, bgPallette = adafruit_imageload.load("/Sprites/Backgrounds/bg1.bmp", bitmap=displayio.Bitmap, palette=displayio.Palette)
bgTile = displayio.TileGrid(bg, pixel_shader=bgPallette)
self.root[0].append(bgTile)
self.select.showSelector(self.root[5])
def do(self, x):
global wakeTime
if x == -1:
pass
elif x == 0:
pass
elif x == 1:
pass
elif x == 2:
pass
elif x == 3:
pass
elif x == 4:
self.select.hideSelector(self.root[5])
menu.toggleMenu(self.root[4], self.root[5], "test", "test")
elif x == 5:
buttonBus.button1.deinit()
pin_alarm = alarm.pin.PinAlarm(pin=board.D1, value=True, pull=True)
time.sleep(0.5)
alarm.exit_and_deep_sleep_until_alarms(pin_alarm)
def looper(self):
animate.doAnimate(self.root[2], 0.5, 10)
if buttonBus.getSelectedButton() == 0:
self.select.lastPos()
time.sleep(0.2)
return True
elif buttonBus.getSelectedButton() == 1:
self.do(self.select.getSPos())
time.sleep(0.2)
return True
elif buttonBus.getSelectedButton() == 2:
self.select.nextPos()
time.sleep(0.2)
return True

88
code.py
View File

@ -1,13 +1,15 @@
import os
import sys
import time import time
import json import json
import alarm import alarm
import board import board
import displayio
import bitmaptools
import adafruit_imageload
import storage import storage
import displayio
import supervisor import supervisor
import bitmaptools
import microcontroller import microcontroller
import adafruit_imageload
import menu import menu
import entity import entity
@ -15,6 +17,20 @@ import animate
import selector import selector
import buttonBus import buttonBus
def importer(path):
sys.path.append(path)
for entry in os.listdir(path):
if entry[-3:] == ".py":
string = f'import {entry}'[:-3]
exec (string)
elif "." not in entry:
importer(path+'/'+entry)
importer("/Activities")
sam = "xyz"
test.printit()
#screen /dev/ttyACM0 115200 #screen /dev/ttyACM0 115200
#setup #setup
@ -37,56 +53,27 @@ selectorGroup = displayio.Group()
board.DISPLAY.show(root) board.DISPLAY.show(root)
entity = entity.entity() root.insert(0, bgGroup)
entity.importSave() root.insert(1, bgItemGroup)
entity.show(haioGroup) root.insert(2, haioGroup)
root.insert(3, fgItemGroup)
root.insert(4, menuGroup)
root.insert(5, selectorGroup)
bg, bgPallette = adafruit_imageload.load("/Sprites/Backgrounds/bg1.bmp", bitmap=displayio.Bitmap, palette=displayio.Palette)
bgTile = displayio.TileGrid(bg, pixel_shader=bgPallette)
bgGroup.append(bgTile)
root.append(bgGroup)
root.append(bgItemGroup)
root.append(haioGroup)
root.append(fgItemGroup)
root.append(menuGroup)
root.append(selectorGroup)
select = selector.selector([[5,0],[40,0],[70,0],[90,0],[0,220],[110,220]])
select.showSelector(selectorGroup)
wakeTime = time.monotonic() wakeTime = time.monotonic()
entity = entity.entity()
entity.importSave()
#Load Settings #Load Settings
with open("/Save/settings.json", "r") as reader: with open("/Save/settings.json", "r") as reader:
settings = json.loads(reader.read()) settings = json.loads(reader.read())
timeoutAmount = settings["timeout"] timeoutAmount = settings["timeout"]
timeout = round(time.monotonic() + timeoutAmount, 1) timeout = round(time.monotonic() + timeoutAmount, 1)
nextWake = max(entity.character["nextEventTime"], entity.character["nextEvloutionTime"], entity.character["death"]) - entity.character["age"] nextWake = max(entity.character["nextEventTime"], entity.character["nextEvloutionTime"], entity.character["death"]) - entity.character["age"]
#Menu Activites
def do(x):
global wakeTime
if x == 0:
entity.character["age"] += int(time.monotonic() - wakeTime)
wakeTime = time.monotonic()
print(entity.character["age"])
pass
elif x == 1:
pass
elif x == 2:
pass
elif x == 3:
pass
elif x == 4:
menu.toggleMenu(root)
elif x == 5:
buttonBus.button1.deinit()
pin_alarm = alarm.pin.PinAlarm(pin=board.D1, value=True, pull=True)
time.sleep(0.5)
alarm.exit_and_deep_sleep_until_alarms(pin_alarm)
def checkTimeout(): def checkTimeout():
# print("Time: " + str(round(time.monotonic(), 1)) + " Timeout: " + str(timeout)) # print("Time: " + str(round(time.monotonic(), 1)) + " Timeout: " + str(timeout))
@ -98,20 +85,11 @@ def checkTimeout():
time.sleep(0.5) time.sleep(0.5)
alarm.exit_and_deep_sleep_until_alarms(pin_alarm) alarm.exit_and_deep_sleep_until_alarms(pin_alarm)
home = home.home(root, entity)
#System Loop #System Loop
while True: while True:
checkTimeout() checkTimeout()
animate.doAnimate(haioGroup, 0.5, 10) if home.looper():
if buttonBus.getSelectedButton() == 0:
select.lastPos()
time.sleep(0.2)
timeout = round(time.monotonic() + timeoutAmount, 1)
elif buttonBus.getSelectedButton() == 1:
do(select.getSPos())
time.sleep(0.2)
timeout = round(time.monotonic() + timeoutAmount, 1)
elif buttonBus.getSelectedButton() == 2:
select.nextPos()
time.sleep(0.2)
timeout = round(time.monotonic() + timeoutAmount, 1) timeout = round(time.monotonic() + timeoutAmount, 1)

12
lib/G.py Normal file
View File

@ -0,0 +1,12 @@
import displayio
root = displayio.Group()
bgGroup = displayio.Group()
bgItemGroup = displayio.Group()
haioGroup = displayio.Group()
fgItemGroup = displayio.Group()
menuGroup = displayio.Group()
selectorGroup = displayio.Group()
sam = "xyz"

View File

@ -1,28 +1,27 @@
import board
import adafruit_max1704x
import time import time
import terminalio import board
import selector
import buttonBus
import displayio import displayio
import terminalio
import adafruit_max1704x
from adafruit_display_shapes.rect import Rect from adafruit_display_shapes.rect import Rect
from adafruit_display_text import bitmap_label, wrap_text_to_lines from adafruit_display_text import bitmap_label, wrap_text_to_lines
menuToggle = True
battery = adafruit_max1704x.MAX17048(board.I2C()) battery = adafruit_max1704x.MAX17048(board.I2C())
def toggleMenu(splash): def toggleMenu(menuGroup, selectorGroup, label1, method1):
global menuToggle
global battery global battery
if menuToggle:
battery.reset()
time.sleep(0.05) # bselect = selector.selector([[10, 60],[10, 80]])
timeText = bitmap_label.Label(terminalio.FONT, text="Time: " + str(time.monotonic()), scale=1, color=0x000000, x=25, y=60) # bselect.showSelector(selectorGroup)
batText = bitmap_label.Label(terminalio.FONT, text="Battery: " + str(round(battery.cell_percent)) + "%", scale=1, color=0x000000, x=25, y=80)
menuGroup = displayio.Group() battery.reset()
menuGroup.append(Rect(10, 10, 115, 220, fill=0xFFFFFF, outline=0x000000, stroke=2)) time.sleep(0.05)
menuGroup.append(bitmap_label.Label(terminalio.FONT, text="Menu", scale=2, color=0x000000, x=30, y=30)) timeText = bitmap_label.Label(terminalio.FONT, text="Time: " + str(time.monotonic()), scale=1, color=0x000000, x=25, y=60)
menuGroup.append(timeText) batText = bitmap_label.Label(terminalio.FONT, text="Battery: " + str(round(battery.cell_percent)) + "%", scale=1, color=0x000000, x=25, y=80)
menuGroup.append(batText) menuGroup.append(Rect(10, 10, 115, 220, fill=0xFFFFFF, outline=0x000000, stroke=2))
splash.append(menuGroup) menuGroup.append(bitmap_label.Label(terminalio.FONT, text="Menu", scale=2, color=0x000000, x=30, y=30))
else: menuGroup.append(timeText)
splash.pop() menuGroup.append(batText)
menuToggle ^= True

View File

@ -6,13 +6,15 @@ spos = -1
class selector: class selector:
def __init__(self, positions): def __init__(self, positions):
global spos
self.size = len(positions) self.size = len(positions)
self.positions = positions self.positions = positions
spos = -1
def showSelector(self, selectorGroup): def showSelector(self, selectorGroup):
global spos global spos
if spos == -1: if spos == -1:
selectorGroup.insert(0,select) selectorGroup.append(select)
spos += 1 spos += 1
def hideSelector(self, selectorGroup): def hideSelector(self, selectorGroup):