Beispiel #1
0
def cmd_system_info(cmd: dict) -> tuple:
    """ gets common information about the system and the environment """
    i = {}
    i['software.name'] = 'ezPiC'
    i['software.version'] = VERSION
    i['command.source'] = cmd['SRC']

    try:
        i['sys.version'] = sys.version
        i['sys.platform'] = sys.platform
        i['sys.implementation.name'] = sys.implementation.name
        #i['sys.maxsize'] = sys.maxsize
    except:
        pass

    try:
        import platform
        i['platform.node'] = platform.node()
        i['platform.system'] = platform.system()
        i['platform.release'] = platform.release()
        i['platform.version'] = platform.version()
        i['platform.machine'] = platform.machine()
        i['platform.processor'] = platform.processor()
        i['platform.architecture'] = platform.architecture()
        i['platform.dist'] = platform.dist()
        i['platform.python_version'] = platform.python_version()
    except:
        pass

    try:
        import micropython
        i['micropython.mem_info'] = micropython.mem_info()
        i['micropython.opt_level'] = micropython.opt_level()
    except:
        pass

    try:
        import gc
        i['gc.mem_free'] = gc.mem_free()
    except:
        pass

    return (0, i)
Beispiel #2
0
import micropython as micropython

# check we can get and set the level
micropython.opt_level(0)
print(micropython.opt_level())
micropython.opt_level(1)
print(micropython.opt_level())

# check that the optimisation levels actually differ
micropython.opt_level(0)
exec('print(__debug__)')
micropython.opt_level(1)
exec('print(__debug__)')
exec('assert 0')

# check that level 3 doesn't store line numbers
micropython.opt_level(3)
exec(
    'try:\n xyz\nexcept NameError as er:\n import sys\n sys.print_exception(er)'
)
Beispiel #3
0
import micropython
micropython.opt_level(2)

import comutils
import blobstar, astro_sensor, time_location, captive_portal, pole_finder, star_finder, pole_movement
import exclogger
import pyb, uos, uio, gc, sys
import time, math, ujson, ubinascii
import network
import sensor, image

red_led   = pyb.LED(1)
green_led = pyb.LED(2)
blue_led  = pyb.LED(3)
ir_leds   = pyb.LED(4)

class PolarScope(object):

    def __init__(self, debug = False, simulate_file = None, use_leds = True):
        exclogger.init()
        self.highspeed = False
        self.daymode = False
        self.simulate = False
        self.cam = astro_sensor.AstroCam(simulate = simulate_file)
        self.cam.init(gain_db = 32, shutter_us = 1000000)
        self.time_mgr = time_location.TimeLocationManager()
        self.has_time = False

        self.debug = debug
        self.use_leds = use_leds
        self.sleeping = False
Beispiel #4
0
import micropython as micropython

# check that level 3 doesn't store line numbers
# the expected output is that any line is printed as "line 1"
micropython.opt_level(3)
exec(
    'try:\n xyz\nexcept NameError as er:\n import sys\n sys.print_exception(er)'
)
Beispiel #5
0
from micropython import opt_level
print('{} opt_level: {}'.format(__name__, opt_level()))

# noinspection PyUnresolvedReferences
from gc import collect
collect()
from time import sleep, sleep_ms
collect()
from wifi import WiFi
collect()
from messaging import Messaging
collect()


# noinspection PyUnresolvedReferences
class RunLoop:
    SLEEP_MS_DEFAULT = 20
    LED_TOGGLE_DEFAULT = 500

    def __init__(self, config, verbose=0):
        self.verbose = verbose
        # ------------------------------------------------------------------------------------------------------------ #
        self.exit = False
        self.config = config
        # ------------------------------------------------------------------------------------------------------------ #
        self.sleep_ms = self.SLEEP_MS_DEFAULT
        # ------------------------------------------------------------------------------------------------------------ #
        # Initialise required services
        # ------------------------------------------------------------------------------------------------------------ #
        if self.config['pinout']['led'] is None:
            from led import MockLed
Beispiel #6
0
from micropython import opt_level
print('{} opt_level: {}'.format(__name__, opt_level()))
from machine import Pin
# noinspection PyUnresolvedReferences
from time import ticks_ms, ticks_diff

# noinspection PyUnresolvedReferences,PyArgumentList
class Led:
    DEFAULT_PULSE_WIDTH = 1000
    STATE_OFF = 0
    STATE_ON = 1
    STATE_TOGGLE = 2
    def __init__(self, pin, on_level, verbose=0):
        self.verbose = verbose
        self.pulse_width = Led.DEFAULT_PULSE_WIDTH
        self.gpio_pin = pin
        self.on_level = on_level
        self.pin = Pin(self.gpio_pin, Pin.OUT)
        self._enabled = True
        self.state = None
        self.saved_state = None
        self.start = None
        self.off(poll=True)
    def __repr__(self):
        return '<Led: On pin {} at {:x}>'.format(self.gpio_pin, id(self))
    def enable(self, flag):
        self._enabled = flag
        if flag is False:
            self.start = None
    def enabled(self):
import micropython
micropython.opt_level(0)
import gc
import pyb

try:
    import exclogger, guidepulser
except:
    red_led = pyb.LED(1)
    while True:
        red_led.on()
        print("ERROR: wrong firmware")
        pyb.delay(200)
        red_led.off()
        pyb.delay(200)

from pyb import I2C

if __name__ == "__main__":
    i2c = I2C(2, I2C.MASTER)
    devs = i2c.scan()
    is_guider = 0x38 in devs
    mem_start = gc.mem_free()
    if is_guider:
        #print("starting autoguider (mem free: %u)" % mem_start)
        import autoguider
        #print("imported module, mem free: %u" % gc.mem_free())
        device = autoguider.AutoGuider(debug=False)
    else:
        #print("starting polarscope (mem free: %u)" % mem_start)
        import polarscope
Beispiel #8
0
"""
    POVPi Client 
    boot.py
"""

# This file is executed on every boot (including wake-boot from deepsleep)
#import esp
# esp.osdebug(None)
# import webrepl
# webrepl.start()
import micropython as mp

mp.opt_level(3)
                df = mx - r

            if df == 0:
                h = 0
            else:
                h = (((b - r) / df) + 2) % 6

            if mx == 0:
                s = 0
            else:
                s = df / mx

    return h, s, mx  # 0-6 : 0-1 : 0-255 - range of output value(small transform for hsv)


micropython.opt_level(3)  # Set maxium optimization level
sensor.reset()
sensor.set_pixformat(sensor.RGB565)  # Set pixel format to RGB
sensor.set_framesize(sensor.QVGA)  # Optimised solution for quality
sensor.skip_frames(time=3000)  # Wait for calibrate
sensor.set_auto_gain(False)  # Disable auto gain control
sensor.set_auto_whitebal(False)  # Disable white balance
sensor.set_auto_exposure(False)  # Disable auto exposure correction

W = sensor.width()  # Get width of camera
H = sensor.height()  # Get height of camera

lcx = int(W / 2)
lcy = int(H / 2)
last_height = 20
last_width = 120
Beispiel #10
0
# This file is executed on every boot (including wake-boot from deepsleep)
#import esp
#esp.osdebug(None)

from micropython import opt_level
opt_level(4)

# noinspection PyUnresolvedReferences
from gc import collect
collect()
# noinspection PyUnresolvedReferences
from webrepl import start
collect()
from application import application
collect()

start()
collect()
application()
collect()
Beispiel #11
0
import micropython as micropython

# check we can get and set the level
micropython.opt_level(0)
print(micropython.opt_level())
micropython.opt_level(1)
print(micropython.opt_level())

# check that the optimisation levels actually differ
micropython.opt_level(0)
exec('print(__debug__)')
micropython.opt_level(1)
exec('print(__debug__)')
exec('assert 0')

# check that level 3 doesn't store line numbers
# the expected output is that any line is printed as "line 1"
micropython.opt_level(3)
exec('try:\n xyz\nexcept NameError as er:\n import sys\n sys.print_exception(er)')
Beispiel #12
0
"""
Provides platform-agnostic exported symbols which may be provided in different ways on different platforms.
For example, the const() symbol provides for values which are treated as constant by the micropython bytecode
compiler, but the agnostic library enables python3 to use const() but just provides it as a dummy identity function
Similarly, os, io, and time are provided by uos, uio and utime on micropython, and re-exporting them from agnostic
allows them to be used without lots of platform-detection logic strewn through other libraries.
"""

assert hasattr(sys, "implementation"), "FATAL: Cannot run in Python 2"

# number of bytes at which to reset
LOW_MEMORY = 13000

if sys.implementation.name == "micropython":
    from micropython import const, opt_level
    opt_level(1)  # removes debug symbols?
    from machine import reset as reboot
    """
    from esp import deepsleep
    def reboot():
        deepsleep(1) # sleep for 1 microsecond
    """
    import gc
    from utime import sleep, ticks_ms, ticks_diff
    import uos as os
    import uio as io

    def reboot_collect():
        report_collect()
        if gc.mem_free() > LOW_MEMORY:
            print("MEMORY OK")
    Render mandelbrot on Odroid Go
    It's for loboris MicroPython port!
    
    Based on code from https://github.com/pypyjs/pypyjs-examples/
"""
import sys
import time

import display
import machine
import micropython
from machine import SPI
from micropython import const
from odroidgo.screen import screen

micropython.opt_level(99)


def mandelbrot(tft, width, height, left, right, top, bottom, iterations):
    for y in range(height):
        for x in range(width):
            z = complex(0, 0)
            c = complex(left + x * (right - left) / width,
                        top + y * (bottom - top) / height)
            norm = abs(z)**2
            for count in range(iterations):
                if norm <= 4:
                    z = z * z + c
                    norm = abs(z * z)
                else:
                    break
Beispiel #14
0
import displayio
import busio
import digitalio
import adafruit_bme280
from adafruit_display_text import label
#from adafruit_st7735 import ST7735
#from adafruit_ili9341 import ILI9341
from adafruit_bitmap_font import bitmap_font
from adafruit_display_shapes.roundrect import RoundRect
import adafruit_gps
import time
import gc
from micropython import const, opt_level
from microcontroller import cpu
import terminalio
opt_level(3)
gc.enable()
gc.collect()
i2c = busio.I2C(board.B6, board.B7)
bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c, address=0x76)
bme280.sea_level_pressure = 1011.92
bme280.mode = adafruit_bme280.MODE_NORMAL
bme280.standby_period = adafruit_bme280.STANDBY_TC_500
bme280.iir_filter = adafruit_bme280.IIR_FILTER_X16
bme280.overscan_pressure = adafruit_bme280.OVERSCAN_X16
bme280.overscan_humidity = adafruit_bme280.OVERSCAN_X1
bme280.overscan_temperature = adafruit_bme280.OVERSCAN_X2
uart = busio.UART(board.A2, board.A3, baudrate=9600, timeout=10)
gps = adafruit_gps.GPS(uart, debug=False)
gps.send_command(const(b"PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0"))
gps.send_command(const(b"PMTK220,1000"))