def should_have_printed_usage_instructions(monkeypatch) -> None: print_coloured_calls = [] mock_parse_argv(MODULE_NAME, 'Bluetooth', monkeypatch) monkeypatch.setattr(f"{MODULE_NAME}.print_coloured", lambda *a, **k: print_coloured_calls.append('')) Bluetooth().usage() assert len(print_coloured_calls) == 2
def should_have_executed(monkeypatch, argv: List[str], on: bool) -> None: def mock_execute_cmd(*args: tuple, **kwargs: dict) -> str: assert args[0] == ['blueutil', '-p', ('1' if on else '0')] return '\n' mock_parse_argv(MODULE_NAME, 'Bluetooth', monkeypatch, argv) monkeypatch.setattr(f"{MODULE_NAME}.execute_cmd", mock_execute_cmd) mute_logs(MODULE_NAME, monkeypatch) assert Bluetooth().execute() == ''
def execute(self) -> str: log('Hello!') automations = [ Bluetooth(['on']), Wifi(['on']), ] for automation in automations: automation.execute() return ''
def should_not_have_parsed_argv_with_wrong_or_no_option( monkeypatch, argv: List[str]) -> None: def mock_raise_error(*args: tuple, **kwargs: dict) -> None: assert kwargs['usage'] is not None raise SystemExit(0) # Controlled early exit monkeypatch.setattr(f"{MODULE_NAME}.raise_error", mock_raise_error) with pytest.raises(SystemExit) as e: Bluetooth(argv) assert e.type == SystemExit assert e.value.code == 0
def execute(self) -> str: log('Good night!') automations = [ Volume(['0.0']), Bluetooth(['off']), Wifi(['off']), Sleep(), ] for automation in automations: automation.execute() return ''
# LAB3 # Jimmy Hoang # William Gentry # Daniel Burr import sensor, image, math, time, pyb, motors, bluetooth from pyb import Pin, Timer, UART, LED, ADC from math import sqrt from motors import DCMotor, ServoMotor from bluetooth import Bluetooth ##### Global Variables and Initialization ##### ## uart uart = UART(1, 115200) bt = Bluetooth(uart) ## DC motor control dc_motor = DCMotor(tim_num=2, channel=4, frequency=100, pin="P5") dc_motor.set_control(in_a="P2", in_b="P3", en_a="P4", en_b="P8") dc_motor.set_current_sense(cs="P6", cs_dis="P9") dutycyclePW = 0 ## Servo motor control servo_max = 0.0019 servo_min = 0.0010 servo_center = (servo_max + servo_min) / 2 servo_offset = servo_max - servo_center servo_motor = ServoMotor(tim_num=4, channel=1, frequency=300, pin="P7") servo_motor.set_range(max_pw=servo_max, min_pw=servo_min) sec = servo_center
def should_have_parsed_argv(argv: List[str]) -> None: assert Bluetooth(argv).argv == argv
from tableur import ReadSpreadsheet from bluetooth import Bluetooth import time from pprint import pprint if __name__ == '__main__': stop = ["stop", "stop"] spreadsheet = ReadSpreadsheet("tableau.csv") bluetooth = Bluetooth("COM9", 9600) #bluetooth.send_data("start") print("Début de l'envoie") print("bon nom") print("Bonnes syllabes 2") for syllable, index in zip(spreadsheet.good_syllable, spreadsheet.index_good_syllable): a = 1 data_received = "" while a == 1: data_sent = syllable + "-" + str(index) bluetooth.send_data(data_sent) data_received = bluetooth.receive_data().strip() print("La donnée reçue est : " + data_received) print("La donnée envoyée est : " + syllable + "-" + str(index)) if data_received == data_sent: a = 0 else: a = 1
# from subprocess import call from time import sleep import Adafruit_MCP3008 try: from gpiozero import Button runningOnRaspi = True except: runningOnRaspi = False VOLUME_CHANNEL = 0 mcp = Adafruit_MCP3008.MCP3008(clk=13, cs=26, miso=25, mosi=9) mode = None radio = Radio() bluetooth = Bluetooth() def switchToBluetooth(): global mode if mode == "bluetooth": return mode = "bluetooth" print("Load Bluetooth") nextButton.when_pressed = None prevButton.when_pressed = None radio.stop() bluetooth.start()