Esempio n. 1
0
        if Date == "":
            Date = location["Date"]
        elif Date != location["Date"]:
            Date = Date + " & " + location["Date"]

        Administered_Dose1_Pop_Pct = location["Administered_Dose1_Pop_Pct"]
        Administered_Dose2_Pop_Pct = location["Administered_Dose2_Pop_Pct"]

        if location["Location"] == "NY":
            magtag.set_text(
                f"{Location}: {Administered_Dose1_Pop_Pct}%",
                index=1,
                auto_refresh=False,
            )
            dose1_ny_progress_bar.progress = Administered_Dose1_Pop_Pct / 100.0
            dose2_ny_progress_bar.progress = Administered_Dose2_Pop_Pct / 100.0
        elif location["Location"] == "US":
            magtag.set_text(
                f"{Location}: {Administered_Dose1_Pop_Pct}%",
                index=2,
                auto_refresh=False,
            )
            dose1_us_progress_bar.progress = Administered_Dose1_Pop_Pct / 100.0
            dose2_us_progress_bar.progress = Administered_Dose2_Pop_Pct / 100.0

response = requests.get(TIME_URL)
print("-" * 40)
print(response.text)
print("-" * 40)
Esempio n. 2
0
    # Update the key refresh timer
    timer = time.localtime(time.time()).tm_sec
    # timer resets on :00/:30
    if timer > 30:
        countdown = 60 - timer
    else:
        countdown = 30 - timer
    print('NTP Countdown: {}%'.format(countdown))
    # change the timer bar's color if text is about to refresh
    progress_bar.fill = 0xFFFFFF
    if countdown < 5:
        progress_bar.fill = 0xFF0000

    # update the progress_bar with countdown
    countdown = map_range(countdown, 0, 30, 0.0, 1.0)
    progress_bar.progress = countdown

    # poll the touchscreen
    p = ts.touch_point
    # if the touchscreen was pressed
    if p:
        for i, b in enumerate(buttons):
            if b.contains(p):
                b.selected = True
                for name, secret in secrets['totp_keys']:
                    # check if button name is the same as a key name
                    if b.name == name:
                        current_button = name
                        # Generate OTP
                        otp = generate_otp(unix_time // 30, secret)
                        display_otp_key(name, otp)
Esempio n. 3
0
BAR_X = magtag.graphics.display.width // 2 - BAR_WIDTH // 2
BAR_Y = 66

# Create a new progress_bar object at (x, y)
progress_bar = ProgressBar(BAR_X,
                           BAR_Y,
                           BAR_WIDTH,
                           BAR_HEIGHT,
                           1.0,
                           bar_color=0x999999,
                           outline_color=0x000000)

magtag.graphics.splash.append(progress_bar)

timestamp = None

while True:
    # We will use deep sleep once it's available in CircuitPython
    if (not timestamp or
        (time.monotonic() - timestamp) > 24 * 60 * 60):  # once per day...
        try:
            value = magtag.fetch()
            print("Response is", value)
            time.sleep(5)  # wait for display
            progress_bar.progress = value / 100.0
            magtag.refresh()
        except (ValueError, RuntimeError) as e:
            print("Some error occurred, retrying! -", e)
        timestamp = time.monotonic()
import displayio
from adafruit_progressbar import ProgressBar

# Make the display context
splash = displayio.Group(max_size=10)
board.DISPLAY.show(splash)

# set progress bar width and height relative to board's display
width = board.DISPLAY.width - 40
height = 30

x = board.DISPLAY.width // 2 - width // 2
y = board.DISPLAY.height // 3

# Create a new progress_bar object at (x, y)
progress_bar = ProgressBar(x, y, width, height, 1.0)

# Append progress_bar to the splash group
splash.append(progress_bar)

current_progress = 0.0
while True:
    # range end is exclusive so we need to use 1 bigger than max number that we want
    for current_progress in range(0, 101, 1):
        print("Progress: {}%".format(current_progress))
        progress_bar.progress = current_progress / 100  # convert to decimal
        time.sleep(0.01)
    time.sleep(0.3)
    progress_bar.progress = 0.0
    time.sleep(0.3)
Esempio n. 5
0
                      width=BUTTON_WIDTH,
                      height=BUTTON_HEIGHT,
                      style=Button.SHADOWROUNDRECT,
                      selected_outline=0xff0000,
                      selected_fill=0xa0a0a0,
                      fill_color=WHITE,
                      outline_color=0x222222)
buttons.append(button_white)  # adding this button to the buttons group

# Add all of the main buttons to the splash Group
for b in buttons:
    pyportal.splash.append(b.group)

# Append progress_bar to the splash group
pyportal.splash.append(progress_bar)
progress_bar.progress = BRIGHTNESS

while True:
    touch = pyportal.touchscreen.touch_point
    if touch:
        for i, button in enumerate(buttons):
            if button.contains(touch):
                print('button%d pressed' % i)
                if i == 0 and BRIGHTNESS > 0.01 and ON:
                    BRIGHTNESS = BRIGHTNESS - 0.01
                    ring_1.brightness = BRIGHTNESS
                    ring_1.show()
                if i == 1 and BRIGHTNESS <= 0.99 and ON:
                    BRIGHTNESS = BRIGHTNESS + 0.01
                    ring_1.brightness = BRIGHTNESS
                    ring_1.show()
Esempio n. 6
0
# Create a new progress_bar object at (x, y)
progress_bar = ProgressBar(x,
                           y,
                           BAR_WIDTH,
                           BAR_HEIGHT,
                           1.0,
                           bar_color=0x666666,
                           outline_color=0xFFFFFF)

# Append progress_bar to the splash group
splash.append(progress_bar)

current_progress = (time.monotonic() % 101) / 100.0
print(current_progress)
progress_bar.progress = current_progress

# refresh the display
display.refresh()

prev_a = a_btn.value
while True:
    cur_a = a_btn.value
    # if a_btn was just pressed down
    if not cur_a and prev_a:
        current_progress += 0.20
        if current_progress > 1.0:
            current_progress = 0.0
        print(current_progress)
        progress_bar.progress = current_progress
Esempio n. 7
0
# set progress bar width and height relative to board's display
BAR_WIDTH = magtag.graphics.display.width - 80
BAR_HEIGHT = 30

BAR_X = magtag.graphics.display.width // 2 - BAR_WIDTH // 2
BAR_Y = 66

# Create a new progress_bar object at (x, y)
progress_bar = ProgressBar(BAR_X,
                           BAR_Y,
                           BAR_WIDTH,
                           BAR_HEIGHT,
                           1.0,
                           bar_color=0x999999,
                           outline_color=0x000000)

magtag.graphics.splash.append(progress_bar)

timestamp = None

try:
    value = magtag.fetch()
    print("Response is", value)
    progress_bar.progress = value[1] / 100.0
    magtag.refresh()
    magtag.exit_and_deep_sleep(24 * 60 * 60)  # one day
except (ValueError, RuntimeError) as e:
    print("Some error occurred, retrying! -", e)
    magtag.exit_and_deep_sleep(60)  # one minute
BAR_WIDTH = magtag.graphics.display.width - 80
BAR_HEIGHT = 30

BAR_X = magtag.graphics.display.width // 2 - BAR_WIDTH // 2
BAR_Y = 80

# Create a new progress_bar object at (x, y)
progress_bar = ProgressBar(BAR_X,
                           BAR_Y,
                           BAR_WIDTH,
                           BAR_HEIGHT,
                           1.0,
                           bar_color=0x999999,
                           outline_color=0x000000)

magtag.graphics.splash.append(progress_bar)

try:
    magtag.network.get_local_time()
    now = rtc.RTC().datetime
    progress_bar.progress = now.tm_yday / days_in_year(now)
    magtag.set_text("{:.2f}%".format(now.tm_yday / days_in_year(now) * 100.0),
                    index=1)

    print(now)
    magtag.exit_and_deep_sleep(24 * 60 * 60)  # one day

except (ValueError, RuntimeError) as e:
    print("Some error occurred, retrying after 1 minute! -", e)
    magtag.exit_and_deep_sleep(60)  # one  minute
                             outline_color=0x000000)

magtag.graphics.splash.append(progress_bar)
magtag.graphics.splash.append(progress_bar_1)
magtag.graphics.set_background("/bmps/background.bmp")

try:
    value = magtag.fetch().split("\n")[-2].split(",")
    print("Response is", value)

    vaccinated = int(value[-2]) / 331984513
    fully_vaccinated = int(value[-1]) / 331984513

    magtag.set_text(f"{value[0]} Vaccination Rates", 0, False)
    magtag.set_text(value[1], 1, False)
    magtag.set_text("Vaccinated: {:.2f}%".format(vaccinated * 100), 2, False)
    magtag.set_text("Fully Vaccinated: {:.2f}%".format(fully_vaccinated * 100),
                    3, False)

    progress_bar.progress = vaccinated
    progress_bar_1.progress = fully_vaccinated

    magtag.refresh()

    seconds_to_sleep = 24 * 60 * 60  # Sleep for one day
    print(f"Sleeping for {seconds_to_sleep} seconds")
    magtag.exit_and_deep_sleep(seconds_to_sleep)

except (ValueError, RuntimeError) as e:
    print("Some error occured, retrying! -", e)
            #  gets number of hours to add to total
            clock_check = clock / 3600
            #  logs the step count as of that hour
            steps_log = steps
            #  adds the hours to get a new hours total
            clock_count += round(clock_check)
            #  divides steps by hours to get steps per hour
            sph = steps_log / clock_count
            #  adds the sph to the display
            text_sph.text = '%d' % sph
            #  resets clock to count to the next hour again
            clock = 0
            mono = time.monotonic()

        #  adjusting countdown to step goal
        prog_bar.progress = float(countdown)

    #  displaying countdown to step goal
    if step_goal - steps > 0:
        steps_remaining = step_goal - steps
        steps_countdown.text = '%d Steps Remaining' % steps_remaining
    else:
        steps_countdown.text = 'Steps Goal Met!'

    #  adjusting screen brightness, a button decreases brightness
    if clue.button_a and a_state:
        mode -= 1
        a_state = False
        if mode < 0:
            mode = 0
            clue_display.brightness = bright_level[mode]