Exemple #1
0
def sensors(**args):
    while True:
        with bhi160.BHI160Orientation(**args) as s:
            yield s, "Orientation"
        with bhi160.BHI160Accelerometer(**args) as s:
            yield s, "Accel"
        with bhi160.BHI160Gyroscope(**args) as s:
            yield s, "Gyro"
        with bhi160.BHI160Magnetometer(**args) as s:
            yield s, "Magnetic"
Exemple #2
0
import leds
import os

from color import Color

disp = display.open()
sensor = 0

sensors = [
    # {"sensor": bhi160.BHI160Orientation(), "name": "Orientation"},
    {
        "sensor": bhi160.BHI160Accelerometer(),
        "name": "Accelerometer"
    },
    {
        "sensor": bhi160.BHI160Gyroscope(),
        "name": "Gyroscope"
    },
]

subtractors = [0.5, 128]

battery_color_good = [0, 230, 0]
battery_color_ok = [255, 215, 0]
battery_color_bad = [255, 0, 0]


def get_bat_color():
    """
    Function determines the color of the battery indicator. Colors can be set in config.
    Voltage threshold's are currently estimates as voltage isn't that great of an indicator for
Exemple #3
0
    color.RED,
    # Orange
    color.RED * 0.5 + color.YELLOW * 0.5,
    color.YELLOW,
    color.GREEN,
]

with contextlib.ExitStack() as cx:
    disp = cx.enter_context(display.open())

    args = {"sample_rate": 10, "sample_buffer_len": 20}

    sensor_iter = itertools.cycle([
        (cx.enter_context(bhi160.BHI160Orientation(**args)), "Orientation"),
        (cx.enter_context(bhi160.BHI160Accelerometer(**args)), "Accel"),
        (cx.enter_context(bhi160.BHI160Gyroscope(**args)), "Gyro"),
        (cx.enter_context(bhi160.BHI160Magnetometer(**args)), "Magnetic"),
    ])
    sensor, sensor_name = next(sensor_iter)

    for ev in simple_menu.button_events(timeout=0.1):
        # Pressing the bottom right button cycles through sensors
        if ev == buttons.BOTTOM_RIGHT:
            sensor, sensor_name = next(sensor_iter)

        samples = sensor.read()
        if not samples:
            continue

        sample = samples[-1]
        col = STATUS_COLORS[sample.status]
Exemple #4
0
accel_x_comp = DC
accel_x_trig = 0
accel_y_comp = GT
accel_y_trig = 7
accel_z_comp = DC
accel_z_trig = 0

# internal variables - do not change
start_time = 0
led_on = False
led_time = 0
blink_on = False
leds.set_powersave(eco=True)
disp = display.open()
pressed = buttons.read(buttons.TOP_RIGHT)
gyrodev = bhi160.BHI160Gyroscope(sample_rate=10)
acceldev = bhi160.BHI160Accelerometer(sample_rate=10)
gyro_str_format = "% 6d"
accel_str_format = "% 6.1f"
gyro_str = ""
accel_str = ""
act_gyro_str = ""
act_accel_str = ""

bufferdepth = int(sumtime / looptime)
gyro = ThreeAxisBuffer.ThreeAxisBuffer(bufferdepth, gyro_x_max, gyro_y_max,
                                       gyro_z_max)
accel = ThreeAxisBuffer.ThreeAxisBuffer(bufferdepth, accel_x_max, accel_y_max,
                                        accel_z_max)

null_sample = ThreeAxisBuffer.ThreeAxis(0, 0, 0)