def takeoff(acft, apt, rwy, qnh_hPa, T_degC): # sTOFL = 37.5 * (W/S)_TO / (sigma*CLmaxTO*(T/W)_TO) = 37.5 W^2/(S*sigma*CLmaxTO*T) to_flap = acft.takeoffFlaps() # Airport density ratio qnh_Pa = qnh_hPa * 100.0 T_K = T_degC + 273.15 sigma = isa.sigma(qnh_Pa, T_K) rwy_vs_weight_flap = {} for f in to_flap: CLmaxTO = acft.CLmax(f) S = acft.getValue('S') delta = qnh_hPa / 1013.15 T = acft.Thrust(delta) MTOM = acft.getValue('MTOM') for r in rwy: weight_r = 0.0 TORA = r.length_ft TOP25 = TORA / 37.5 RTOW = sqrt(TOP25 * S * sigma * CLmaxTO * T) RTOW = acft.checkWeight(RTOW) # RTOW = unit.check(RTOW) if RTOW > weight_r: rwy_vs_weight_flap[r.id] = (RTOW, f) weight_r = RTOW module_logger.debug('rwyID FLTOM ({}) Flap'.format(unit.get())) for rwy_id in sorted(rwy_vs_weight_flap.keys()): weight, flap = rwy_vs_weight_flap[rwy_id] module_logger.debug('{} {:6.0f} {:2.0f}'.format(rwy_id, weight, flap)) return rwy_vs_weight_flap, 'FIELD'
def init_sensors(self): self.active_sensors = {} start_x = 10 start_y = 10 sensor_count = 0 align_right = False for sensor_name, sensor_config in self.sensors.items(): if not sensor_config['is_active']: continue if align_right: start_x = 170 else: start_x = 10 current_sensor = unit.get(sensor_config['unit'], sensor_config['port']) self.active_sensors[sensor_name] = { 'name': sensor_name, 'config': sensor_config, 'get_value': lambda s=current_sensor, c=sensor_config: self.pbhubAnalogRead(s, c['pbhub_address']) if 'pbhub_address' in c else getattr(s, c['value_key']), 'sensor': current_sensor, 'label_text': MyTextBox(start_x, start_y + 30, sensor_config['label'] + ' [' + sensor_config['measurement_unit'] + ']', lcd.FONT_Default, CoreApp.config['ui']['default_color']), 'label_value': MyTextBox(start_x, start_y, '-', lcd.FONT_DejaVu24, CoreApp.config['ui']['default_color']), } sensor_count = sensor_count + 1 if sensor_count % 2 == 0: start_y = start_y + 65 align_right = not align_right
def angle_start(obj): lcd.image(0, 0, '/flash/img/3-9.jpg', type=lcd.JPG) # np = machine.Neopixel(machine.Pin(15), 10) ledbar.setBrightness(0) ledbar.setColorAll(lcd.WHITE) # obj['np'] = np obj['angle'] = unit.get(unit.ANGLE, unit.PORTB) obj['prev'] = 0 dac = machine.DAC(machine.Pin(25)) dac.write(0) lcd.font(lcd.FONT_DejaVu24)
def nicePrint(apt, rwy, rwy_vs_weight_lb_flap): ofp_perf_data = 'AIRPORT: {} ALT {:5.0f} FT\n'.format( apt.id, apt.altitude) ofp_perf_data = ofp_perf_data + 'RWY LENGTH FT MAX WEIGHT {} FLAP\n'.format( unit.get().upper()) ofp_perf_data = ofp_perf_data + '-----------------------------------------\n' logger.info('AIRPORT: {} ALT {:5.0f} FT'.format(apt.id, apt.altitude)) logger.info('RWY LENGTH FT MAX WEIGHT {} FLAP'.format( unit.get().upper())) logger.info('-----------------------------------------') for r in rwy: weight_lb, flap = rwy_vs_weight_lb_flap[r.id] weight = unit.check(weight_lb) logger.info('{:3s} {:5.0f} {:6.0f} {:2.0f}'.format( r.id, r.length_ft, weight, flap)) ofp_perf_data = ofp_perf_data + '{:3s} {:5.0f} {:6.0f} {:2.0f}\n'.format( r.id, r.length_ft, weight, flap) return ofp_perf_data
def env_loop(obj): if i2c.is_ready(92): try: env = unit.get(unit.ENV, unit.PORTA) lcd.print("%.1f" % env.temperature+"'C", 210, 120) lcd.print("%.1f" % env.humidity+"%", 210, 138) lcd.print("%.1f" % env.pressure+"Pa", 208, 156) except: pass else: lcd.rect(205, 105, 70, 70, lcd.WHITE, lcd.WHITE) time.sleep(0.2)
from m5stack import * from m5ui import * from uiflow import * from m5mqtt import M5mqtt import unit setScreenColor(0x111111) neopixel_0 = unit.get(unit.NEOPIXEL, unit.PORTA, 84) waitSeconds = None fade = None color = None intensity = None waiting = None waitShorterTime = None waitLongTime = None i = None from numbers import Number # Describe this function... def restart(): global waitSeconds, fade, color, intensity, waiting, waitShorterTime, waitLongTime, i fade = False intensity = 0 waitSeconds = waitShorterTime waiting = False def fun_K2Light_(topic_data):
from m5stack import * from m5ui import * from uiflow import * import _thread import unit setScreenColor(0x2e2828) finger0 = unit.get(unit.FINGER, unit.PORTB) # rfid0 = unit.get(unit.RFID, unit.PORTA) uart = machine.UART(2, tx=17, rx=16) uart.init(115200, bits=8, parity=None, stop=1) uart_data = '' label1 = M5TextBox(37, 35, "Text", lcd.FONT_DejaVu24, 0xFFFFFF, rotate=0) label3 = M5TextBox(19, 134, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0) finger_id = 0 finger_access = 0 cmd_1 = 0 cmd_2 = 0 def finger0_cb(user_id, access): global finger_id, finger_access finger_id = user_id filter_access = access
Example from M5Stack: https://github.com/m5stack/UIFlow-Code/wiki/Unit#tof """ from m5stack import lcd from m5ui import M5TextBox, M5Title, setScreenColor from uiflow import wait_ms import time import unit import math lcd.clear() lcd.setRotation(3) distfield = M5TextBox(40, 20, "0", lcd.FONT_DejaVu40, 0x08feab) distlabel = M5TextBox(0, 0, "M5StickC VL53L0X", lcd.FONT_Small, 0xFFFFFF) tof = unit.get(unit.TOF, unit.PORTA) def mean(element): sumUnit = 0 for x in element: sumUnit += x return sumUnit/len(element) def variance(element): meanUnit = mean(element) variance = 0 for x in element: variance += (x - meanUnit)**2
def buttonB_wasPressed(): # global params global Pixel_Flag_index Pixel_Flag_index = Pixel_Flag_index + 1 if (Pixel_Flag_index > Flag_index_max): Pixel_Flag_index = 0 neopixel0.setBrightness(Pixel_brightness) pass run_cnt = 0 setScreenColor(0x111111) neopixel0 = unit.get(unit.NEOPIXEL, unit.PORTB, 64) label0 = M5TextBox(6, 11, "64 Pixel LED demo v2.1", lcd.FONT_DejaVu24, 0xFFFFFF, rotate=0) #lcd.set_fg(lcd.WHITE) GUI_label_BR = M5TextBox(6, 60, "Pixel brightness: 30", lcd.FONT_DejaVu18, 0xF0DE2A, rotate=0) GUI_label_IDX = M5TextBox(6,
from m5stack import * from m5ui import * from uiflow import * import wifiCfg import time import urequests import json import unit setScreenColor(0x000000) env1 = unit.get(unit.ENV, unit.PORTA) earth1 = unit.get(unit.EARTH, unit.PORTB) relay1 = unit.get(unit.RELAY, unit.PORTC) earth2 = unit.get(unit.EARTH, (36, 35)) relay13 = unit.get(unit.RELAY, (1, 2)) screen_is_on = None margin_top = None i = None watering_frequency = None watering_duration = None wifiCfg.autoConnect(lcdShow=True) wifiCfg.reconnect() wifiCfg.reconnect() tank = M5Rect(1, 196, 8, 1, 0x729fcf, 0x729fcf) icon = M5Img(36, 0, "res/icon.png", True) qr = M5Img(153, 140, "res/qr.jpg", True) temperature = M5Circle(5, 126, 5, 0x73d216, 0x000000) humidity = M5Circle(5, 143, 5, 0x73d216, 0x000000)
from m5ui import * from m5stack import * import unit import time from wifiCfg import wlan_sta, screenShow, doConnect, saveWiFi setScreenColor(0x000000) lcd.font(lcd.FONT_DejaVu24) while True: try: card = unit.get(unit.CARDKB, unit.PORTA) break except: lcd.setTextColor(lcd.RED, lcd.BLACK) lcd.print("CardKB not connect..", lcd.CENTER, lcd.CENTER) btnText('A', '<--- connect here') setScreenColor(0x000000) def show_title(): lcd.font(lcd.FONT_Comic) lcd.setTextColor(lcd.WHITE, lcd.ORANGE) lcd.rect(0, 0, 320, 30, lcd.ORANGE, lcd.ORANGE) lcd.print("Wi-Fi Config", lcd.CENTER, 2) lcd.setTextColor(lcd.WHITE, lcd.BLACK) show_title() label_ssid = M5TextBox(20, 70,
from m5stack import * from m5ui import * from uiflow import * import unit setScreenColor(0x000000) pir0 = unit.get(unit.PIR, unit.PORTB) circle0 = M5Circle(97, 76, 15, 0x000000, 0x000000) label0 = M5TextBox(135, 152, "Z", lcd.FONT_DejaVu18, 0xFFFFFF, rotate=0) label1 = M5TextBox(168, 127, "Z", lcd.FONT_DejaVu24, 0xFFFFFF, rotate=0) label2 = M5TextBox(204, 93, "Z", lcd.FONT_DejaVu40, 0xFFFFFF, rotate=0) label3 = M5TextBox(245, 56, "Z", lcd.FONT_DejaVu56, 0xFFFFFF, rotate=0) circle1 = M5Circle(214, 76, 15, 0x000000, 0x000000) while True: if (pir0.state) == 1: circle0.setBgColor(0xff0000) circle1.setBgColor(0xff0000) label0.setColor(0x000000) label1.setColor(0x000000) label2.setColor(0x000000) label3.setColor(0x000000) speaker.tone(1600, 10) else: circle0.setBgColor(0x000000) circle1.setBgColor(0x000000) label0.setColor(0xffffff) label1.setColor(0xffffff) label2.setColor(0xffffff) label3.setColor(0xffffff)
from m5stack import * from m5ui import * from uiflow import * import wifiCfg import ntptime import i2c_bus import unit setScreenColor(0x222222) color0 = unit.get(unit.COLOR, unit.PORTA) distmm = None wifiCfg.doConnect('Name', 'Password') label2 = M5TextBox(92, 43, "D", lcd.FONT_DejaVu56, 0xFFFFFF, rotate=0) time = M5TextBox(34, 152, "00:00:00", lcd.FONT_DejaVu56, 0xFFFFFF, rotate=0) ntp = ntptime.client(host='de.pool.ntp.org', timezone=1) speaker.tone(800, 200) i2c0 = i2c_bus.easyI2C((21, 22), 0x52, freq=4000) while True: i2c0.write_u8(0x52, 0x00) distmm = (i2c0.read_data(1, i2c_bus.INT16BE))[-1] label2.setText(str((str(distmm) + str('mm')))) label0.setText(str(ntp.formatTime(':'))) wait_ms(2)
from m5stack import * from m5ui import * from uiflow import * import unit setScreenColor(0x111111) neopixel0 = unit.get(unit.NEOPIXEL, unit.PORTC, 15) circle0 = M5Circle(95, 90, 15, 0xFFFFFF, 0xFFFFFF) circle1 = M5Circle(221, 90, 15, 0xFFFFFF, 0xFFFFFF) import random R = None G = None B = None i = None while True: R = random.randint(0, 255) G = random.randint(0, 255) B = random.randint(0, 255) for i in range(1, 16): neopixel0.setColorFrom(1, i, (R << 16) | (G << 8) | B) wait(0.005) for i in range(1, 16): neopixel0.setColorFrom(1, i, 0x000000) wait(0.005) wait_ms(2)
from m5stack import * import i2c_bus import max30100 import time, sys from m5ui import * import unit setScreenColor(0x222222) label0 = M5TextBox(10, 10, "Heart Rate", lcd.FONT_DejaVu56, 0xFFFFFF, rotate=0) label1 = M5TextBox(50, 80, "0", lcd.FONT_DejaVu40, 0xFFFFFF, rotate=0) label2 = M5TextBox(50, 130, " ", lcd.FONT_DejaVu40, 0xFFFFFF, rotate=0) label3 = M5TextBox(10, 60, " ", lcd.FONT_DejaVu40, 0xFFFFFF, rotate=0) try: Heart = unit.get(unit.HEART, unit.PORTA) except Exception as e: label1.setColor(0xff0000) label1.setPosition(x=10, y=100) label1.setText("Please connect HEART unit!") while True: try: time.sleep(0.1) rate = Heart.getHeartRate() spo2 = Heart.getSpO2() label1.setText("BPM: " + str(rate)) label2.setText("Sp02: " + str(spo2) + "%") if rate > 100: label1.setColor(0xff0000) else:
def climb(acft, qnh_hPa, T_degC): # Preparing dictionary with RTOW for different configurations MTOM = acft.getValue('MTOM') weight_vs_flap = {} to_flap = acft.takeoffFlaps() for f in to_flap: weight_vs_flap[f] = Data(W=MTOM, flag='NO LIM') # Maybe flap 0 is not in takeoff setting, but I need it in enroute climb OEI if 0 not in to_flap: weight_vs_flap[0] = Data(W=MTOM, flag='NO LIM') # Retrieving main aircraft data delta = qnh_hPa / 1013.15 # sigma = isa.sigma(qnh_hPa * 100, T_degC + 273.15) neng = acft.getValue('number_of_engines') # Starting check on different climb OEI # FAR25.111 (OEI) # initial climb initial_ramp_angle = {2: 0.012, 3: 0.015, 4: 0.017} gear = 0 ground_effect = 1 for f in to_flap: CLmax = acft.CLmax(f) CLTO = CLmax / (1.2 * 1.2) # @ V2 = 1.2VS1g CDTO = acft.CD(CLTO, f, gear, ground_effect) E = CLTO / CDTO coeff = neng / (neng - 1.0) * (1. / E + initial_ramp_angle[neng]) RTOW = acft.Thrust(delta) / coeff if RTOW < weight_vs_flap[f].W: RTOW = acft.checkWeight(RTOW) # RTOW = unit.check(RTOW) flag = 'INITIAL' weight_vs_flap[f] = Data(RTOW, flag) # climb transition # FAR25.121 (OEI) climb_transition_angle = {2: 0, 3: 0.003, 4: 0.005} gear = 1 ground_effect = 1 for f in to_flap: CLmax = acft.CLmax(f) CLTO = CLmax / (1.1 * 1.1) # @ VLOF = 1.1VS1g CDTO = acft.CD(CLTO, f, gear, ground_effect) E = CLTO / CDTO coeff = neng / (neng - 1.0) * (1. / E + climb_transition_angle[neng]) RTOW = acft.Thrust(delta) / coeff if RTOW < weight_vs_flap[f].W: RTOW = acft.checkWeight(RTOW) # RTOW = unit.check(RTOW) flag = 'TRANSITION' weight_vs_flap[f] = Data(RTOW, flag) # second climb segment second_climb_segment_angle = {2: 0.024, 3: 0.027, 4: 0.03} gear = 0 for f in to_flap: CLmax = acft.CLmax(f) CLTO = CLmax / (1.2 * 1.2) # @ V2 = 1.2VS1g CDTO = acft.CD(CLTO, f, gear) E = CLTO / CDTO coeff = neng / (neng - 1.0) * (1. / E + second_climb_segment_angle[neng]) RTOW = acft.Thrust(delta) / coeff if RTOW < weight_vs_flap[f].W: RTOW = acft.checkWeight(RTOW) # RTOW = unit.check(RTOW) flag = '2ND SEGMENT' weight_vs_flap[f] = Data(RTOW, flag) # enroute climb enroute_climb_angle = {2: 0.012, 3: 0.015, 4: 0.017} gear = 0 f = 0 CLmax = acft.CLmax(f) CLTO = CLmax / (1.25 * 1.25) # @ 1.25*VS1g CDTO = acft.CD(CLTO, f, gear) E = CLTO / CDTO coeff = neng / (neng - 1.0) * (1. / E + enroute_climb_angle[neng]) RTOW = acft.Thrust(delta) / coeff if RTOW < weight_vs_flap[f].W: RTOW = acft.checkWeight(RTOW) # RTOW = unit.check(RTOW) flag = 'ENROUTE' weight_vs_flap[f] = Data(RTOW, flag) # SID 3.3% OEI climb gradient sid_climb_angle = {2: 0.033, 3: 0.033, 4: 0.033} gear = 0 for f in to_flap: CLmax = acft.CLmax(f) CLTO = CLmax / (1.2 * 1.2) # @ V2 = 1.2VS1g CDTO = acft.CD(CLTO, f, gear) E = CLTO / CDTO coeff = neng / (neng - 1.0) * (1.0 / E + sid_climb_angle[neng]) RTOW = acft.Thrust(delta) / coeff if RTOW < weight_vs_flap[f].W: RTOW = acft.checkWeight(RTOW) # RTOW = unit.check(RTOW) flag = '3.3% SID' weight_vs_flap[f] = Data(RTOW, flag) module_logger.debug('f WAT ({}) FLAG'.format(unit.get())) module_logger.debug('----------------------') for f in sorted(weight_vs_flap.keys()): module_logger.debug('{:2d} {:6.0f} {}'.format(f, weight_vs_flap[f].W, weight_vs_flap[f].flag)) max_allowed_weight, flap_max_allowed_weight, flag_max_weight = findMaxAllowedWeight( weight_vs_flap) if flag_max_weight == 'NO LIM': max_allowed_weight = MTOM flap_max_allowed_weight = 'N/A' return max_allowed_weight, flap_max_allowed_weight, flag_max_weight
rotate=0) label1 = m5ui.M5TextBox(25, 70, "dynamic mode", lcd.FONT_DejaVu24, 0xFFFFFF, rotate=0) label2 = m5ui.M5TextBox(100, 130, "Text", lcd.FONT_DejaVu24, 0xFFFFFF, rotate=0) label3 = m5ui.M5TextBox(10, 191, "Text", lcd.FONT_DejaVu18, 0xFFFFFF, rotate=0) vfunc = unit.get(unit.V_FUNCTION, unit.PORTB) motion = vfunc.init(vfunc.MOTION) def buttonA_wasPressed(): motion.setScanInterval(1, 2) btnA.wasPressed(buttonA_wasPressed) def buttonB_wasPressed(): motion.setScanInterval(0, 0) btnB.wasPressed(buttonB_wasPressed)
from m5stack import * from m5ui import * from uiflow import * import unit setScreenColor(0x111111) neopixel0 = unit.get(unit.NEOPIXEL, unit.PORTA, 30) circle0 = M5Circle(95, 90, 15, 0xFFFFFF, 0xFFFFFF) circle1 = M5Circle(221, 90, 15, 0xFFFFFF, 0xFFFFFF) import random R = None G = None B = None i = None while True: R = random.randint(0, 255) G = random.randint(0, 255) B = random.randint(0, 255) for i in range(1, 31): neopixel0.setColorFrom(1,i,(R << 16) | (G << 8) | B) wait(0.005) for i in range(1, 31):
import wifiCfg from m5mqtt import M5mqtt import json import time import unit import machine from numbers import Number def Wifi_reconnect(): while (wifiCfg.wlan_sta.isconnected()) != 1: wifiCfg.reconnect() label0.setText('Wifi connected') data = Noneial #rfid init rfid0 = unit.get(unit.RFID, unit.PORTA) uart = None t1 = None t2 = None student_checkag=[] #存人数的列表 #mqtt initial m5mqtt = M5mqtt('random', 'industrial.api.ubidots.com', 1883, 'BBFF-HXOoqxfhftjZSub2lDqbK019M3KHFg', '', 300) #Label and tile set setScreenColor(0x000000) label0 = M5TextBox(69, 33, "Running System", lcd.FONT_Comic,0x89eee1, rotate=0) label1 = M5TextBox(40, 86, "Name :", lcd.FONT_DejaVu18,0xff66d2, rotate=0) label2 = M5TextBox(76, 124, "ID :", lcd.FONT_DejaVu18,0xff66d2, rotate=0)
from m5stack import * from m5ui import * from uiflow import * import time import unit setScreenColor(0x111111) ncir0 = unit.get(unit.NCIR, unit.PORTA) label0 = M5TextBox(40, 7, "M5COVID BASTION", lcd.FONT_DejaVu18, 0xFFFFFF, rotate=0) label1 = M5TextBox(21, 74, "BodyTempValue:", lcd.FONT_DejaVu18, 0xFFFFFF, rotate=0) label2 = M5TextBox(200, 76, "0", lcd.FONT_DejaVu18, 0xFFFFFF, rotate=0) label3 = M5TextBox(5, 208, "Test readings Body temp", lcd.FONT_DejaVu24, 0xFFFFFF, rotate=0) while True: label2.setText(str(ncir0.temperature))
def motion_start(obj): lcd.image(0, 0, '/flash/img/3-6.jpg', type=lcd.JPG) obj['pir'] = unit.get(unit.PIR, unit.PORTB)
from m5stack import * from m5ui import * from uiflow import * import unit setScreenColor(0x111111) servo0 = unit.get(unit.SERVO, unit.PORTA) title0 = M5Title(title="Servo Tester", x=3, fgcolor=0xFFFFFF, bgcolor=0x0000FF) label0 = M5TextBox(20, 50, "Mode : ", lcd.FONT_DejaVu24, 0xFFFFFF, rotate=0) label1 = M5TextBox(20, 90, "Servo Output :", lcd.FONT_DejaVu24, 0xFFFFFF, rotate=0) txtMode = M5TextBox(110, 50, "Manual", lcd.FONT_DejaVu24, 0xf7ff00, rotate=0) txtServoOut = M5TextBox(205, 90, "90", lcd.FONT_DejaVu24, 0xf7ff00, rotate=0) menuMode = M5TextBox(135, 213, "MODE", lcd.FONT_Default, 0xfffc00, rotate=0) menuMinus = M5TextBox(52, 213, "-10", lcd.FONT_Default, 0x00ff3b, rotate=0) menuPlus = M5TextBox(237, 213, "+10", lcd.FONT_Default, 0xff0000, rotate=0) servoOut = None mode = None servoStep = None def modeManual(): global servoOut, mode, servoStep servo0.write_angle(servoOut) wait(0.2)
def exrgb_start(obj): lcd.image(0, 0, '/flash/img/3-7.jpg', type=lcd.JPG) obj['rgb'] = unit.get(unit.NEOPIXEL, unit.PORTB, 9) obj['rgb'].setBrightness(125)
from m5stack import * from m5ui import * from uiflow import * import unit import machine #初始化M5 remoteInit() #设置屏幕颜色 setScreenColor(0x222222) #从Unit获取数据 env2 = unit.get(unit.ENV, unit.PORTA) light4 = unit.get(unit.LIGHT, unit.PORTB) pir2 = unit.get(unit.PIR, unit.PORTC) #设置标签 Light = M5TextBox(180, 90, "Light", lcd.FONT_Default,0xFFFFFF, rotate=0) Temperat = M5TextBox(179, 28, "Temperature", lcd.FONT_Default,0xFFFFFF, rotate=0) label0 = M5TextBox(72, 28, "Temperature", lcd.FONT_Default,0xFFFFFF, rotate=0) label1 = M5TextBox(74, 90, "Light", lcd.FONT_Default,0xFFFFFF, rotate=0) label3 = M5TextBox(182, 204, "Text", lcd.FONT_Default,0xFFFFFF, rotate=0) label2 = M5TextBox(75, 150, "PIR", lcd.FONT_Default,0xFFFFFF, rotate=0) label4 = M5TextBox(75, 205, "Text", lcd.FONT_Default,0xFFFFFF, rotate=0) PIR = M5TextBox(181, 148, "PIR", lcd.FONT_Default,0xFFFFFF, rotate=0) #初始化标签 uart = None Temperature = None Times = None counter_1 = None
label1.setText('Status Info: connecting...') m5mqtt.start() wait(0.1) label1.setText('Hi, SmartDevice MQTT start') lcd.font(lcd.FONT_Comic) m5mqtt.publish(str('test_ESP32_smartdevice'), str('smart device is now online')) #----------get time #rtc = machine.RTC() #rtc.ntp_sync(server="1.europe.pool.ntp.org", tz="CET-1CEST") #rtc.ntp_sync(server="hr.pool.ntp.org", tz="CET-1CEST") #rtc.synced() #env0 = unit.get(unit.ENV, unit.PORTA) try: env0 = unit.get(unit.ENV, unit.PORTA) label3.setText("Sensor: OK") except: i2c = i2c_bus.get(i2c_bus.M_BUS) label3.setText("Sensor: N.A.") ENV_insert = 1 while ENV_insert: if i2c.is_ready(IIC_Address_ENV): ENV_insert = 0 env0 = unit.get(unit.ENV, unit.PORTA) label3.setText("Sensor: OK!") wait_ms(200) pass while True: if btnC.isPressed():
def landing(acft, apt, rwy, qnh_hPa, T_degC): # Preparing dictionary with RTOW for different configurations weight_vs_flap = {} land_flap = acft.landingFlaps() for f in land_flap: weight_vs_flap[f] = Data(W=1.0e8, flag='None') # Retrieving main aircraft data delta = qnh_hPa / 1013.15 sigma = isa.sigma(qnh_hPa * 100, T_degC + 273.15) neng = acft.getValue('number_of_engines') # FAR25.119 (AEO) initial_ramp_angle = {2: 0.032, 3: 0.032, 4: 0.032} gear = 1 for f in land_flap: CLmax = acft.CLmax(f) CLLND = CLmax / (1.3 * 1.3) # @ Vapp = 1.3VS1g CDLND = acft.CD(CLLND, f, gear) E = CLLND / CDLND coeff = (1. / E + initial_ramp_angle[neng]) RTOW = acft.Thrust(delta) / coeff if RTOW < weight_vs_flap[f].W: RTOW = acft.checkWeight(RTOW) # RTOW = unit.check(RTOW) flag = 'BALKED AEO' weight_vs_flap[f] = Data(RTOW, flag) # FAR25.121 (OEI) initial_ramp_angle = {2: 0.021, 3: 0.024, 4: 0.027} gear = 1 for f in land_flap: CLmax = acft.CLmax(f) CLLND = CLmax / (1.5 * 1.5) # @ Vapp = 1.5VS1g CDLND = acft.CD(CLLND, f, gear) E = CLLND / CDLND coeff = neng / (neng - 1.0) * (1. / E + initial_ramp_angle[neng]) RTOW = acft.Thrust(delta) / coeff if RTOW < weight_vs_flap[f].W: RTOW = acft.checkWeight(RTOW) # RTOW = unit.check(RTOW) flag = 'BALKED OEI' weight_vs_flap[f] = Data(RTOW, flag) # MISSED APPROACH IFR GRADIENT (AEI) initial_ramp_angle = {2: 0.025, 3: 0.025, 4: 0.025} gear = 1 for f in land_flap: CLmax = acft.CLmax(f) CLLND = CLmax / (1.3 * 1.3) # @ Vapp = 1.3VS1g CDLND = acft.CD(CLLND, f, gear) E = CLLND / CDLND coeff = (1. / E + initial_ramp_angle[neng]) RTOW = acft.Thrust(delta) / coeff if RTOW < weight_vs_flap[f].W: RTOW = acft.checkWeight(RTOW) # RTOW = unit.check(RTOW) flag = 'IFR MISSED APPROACH' weight_vs_flap[f] = Data(RTOW, flag) module_logger.debug('f PLLM ({}) FLAG'.format(unit.get())) module_logger.debug('----------------------') for f in sorted(weight_vs_flap.keys()): module_logger.debug('{:2d} {:6.0f} {}'.format(f, weight_vs_flap[f].W, weight_vs_flap[f].flag)) max_allowed_weight, flap_max_allowed_weight, flag_max_weight = findMaxAllowedWeight( weight_vs_flap) module_logger.debug( 'Landing Weight Limitation: ' + '{:6.0f} F{:2.0f} {}'.format( max_allowed_weight, flap_max_allowed_weight, flag_max_weight)) return max_allowed_weight, flap_max_allowed_weight, flag_max_weight
btnA.wasPressed(buttonA_wasPressed) while 1: try: print('i2c0.scan results:') print(i2c0.scan()) wait_ms(10) print('i2c device available ?:') print(i2c0.available()) #i2c0.write_u8(0x01, 0xAA) wait_ms(20) rgb.setColorAll(0x001133) #rfid0 = unit.get(unit.RFID, unit.PORTA) # not fit to ATOM rfid0 = unit.get(unit.RFID, unit.PORTA) # fit ATOM? #rfid0 = unit.get(unit.RFID, unit.(25,21)) # fit ATOM? #Connect this Unit to GROVE PORTA on M5Core, IIC adress is 0x28. #need improve for unit disconnected case print('RFID module is connected!' + "\r\n") break except: print( 'RFID module was not detected! Please Check! Main code will not run!!!' + "\r\n") #rgb.setColorAll(0xFF0000) rgb.set_screen([ 0, 0, 0xFF0000, 0, 0, 0, 0xFFFFFF, 0, 0xFF0000, 0, 0xFFFFFF, 0, 0xFF0000, 0, 0xFFFFFF, 0, 0xFF0000, 0, 0xFFFFFF, 0, 0, 0, 0xFF0000, 0, 0 ])
def draw_co2(self, co2, mhz19temp): def draw_env(self, temp, hum, pres): def redraw(): # MH-Z19B control functions # see https://revspace.nl/MHZ19 class mhz19blib(object): def __init__(self): self.buff = bytearray(9) self.serial = machine.UART(1, tx=0, rx=26) self.serial.init(9600, bits=8, parity=None, stop=1) def checksum_chk(self): sum = 0 for a in self.buff[1:8]: sum = (sum + a) & 0xff c_sum = 0xff - sum + 1 if c_sum == self.buff[8]: return True else: print("c_sum un match!!") return False def ABCdisable(self): #print('send ABC disable command') self.serial.write(b'\xff\x01\x79\x00\x00\x00\x00\x00\x86') # auto caliblation off utime.sleep(0.1) self.serial.readinto(self.buff) def readSensor(self): #print('send read CO2 command') self.serial.write(b'\xff\x01\x86\x00\x00\x00\x00\x00\x79') # co2測定値リクエスト utime.sleep(0.1) len = self.serial.readinto(self.buff) #print('read '+str(len)+'bytes ', self.buff) # co2測定値リクエストの応答 if (len < 9) or (self.buff[0] != 0xff) or not self.checksum_chk() or (self.buff[0] != 0xff) or (self.buff[1] != 0x86) : print('read broken frame(' + str(len) + '): ', self.buff) len = self.serial.readinto(self.buff) print('drop broken frame(' + str(len) + '): ', self.buff) return None return [self.buff[2] * 256 + self.buff[3], self.buff[4] - 40] # メインプログラムはここから(この上はプログラム内関数) # 画面初期化 if lcd.winsize() == (80,160) : # M5StickC/Plus機種判定 m5type = 0 print('>> M5Type = M5StickC') elif lcd.winsize() == (136,241) : m5type = 1 print('>> M5Type = M5StickCPlus') # ユーザー設定ファイル読み込み co2_set_filechk() # センサー初期化 mhz19b = mhz19blib() if S_CO2HAT else None env2 = unit.get(unit.ENV2, unit.PORTA) if S_ENV2 else None # ネットワーク設定 import wifiCfg wifiCfg.autoConnect(lcdShow=True) ntp = ntptime.client(host='jp.pool.ntp.org', timezone=9) # 画面アップデート set_muteLCD(lcd_mute) draw_lcd() # 時刻表示/LED制御スレッド、ambient通知スレッド起動 _thread.start_new_thread(disp_thread, ()) _thread.start_new_thread(am_thread, ()) # ボタン検出スレッド起動 btnA.wasPressed(buttonA_wasPressed) btnB.wasPressed(buttonB_wasPressed) # ABC disable if mhz19b is not None : mhz19b.ABCdisable() # タイムカウンタ初期値設定 co2sensor_tc = utime.time() env2sensor_tc = utime.time() # メインルーチン while True : if env2 is not None : if (utime.time() - env2sensor_tc) >= env2sensor_interval : env2sensor_tc = utime.time() temp = env2.temperature hum = env2.humidity pres = env2.pressure draw_temp() #print("env2:", temp, hum, pres) if mhz19b is not None : if (utime.time() - co2sensor_tc) >= co2sensor_interval : data = mhz19b.readSensor() if data is not None : co2sensor_tc = utime.time() co2 = data[0] mzhtemp = data[1] draw_co2() #print(str(co2) + ' ppm / ' + str(temp) + 'C / ' + str(sensor_tc)) if (co2 is not None) and ((utime.time() - co2sensor_tc) >= TIMEOUT) : # co2応答が一定時間無い場合はCO2値表示のみオフ co2 = None draw_co2() utime.sleep(1) gc.collect()