试着去理解一只鹬

2024-04-25 09:53:13 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图理解下面的IF语句以及res的作用。你知道吗

   if sentence is not None:
                # gps successfully parsed a message from module
                # see if we have valid coordinates
                res = check_for_valid_coordinates(gps)

下面是完整的代码。它只是运行函数吗?你知道吗

GPS_TIMEOUT_SECS=10
# init I2C to P21/P22
i2c = machine.I2C(0, mode=I2C.MASTER, pins=('P22', 'P21'))
# write to address of GPS
GPS_I2CADDR = const(0x10)
raw = bytearray(1)
i2c.writeto(GPS_I2CADDR, raw)
# create MicropyGPS instance
gps = MicropyGPS()
# store results here.
last_data = {}
print("Start reading GPS data...")
def check_for_valid_coordinates(gps):
    if gps.satellite_data_updated() and gps.valid:
        last_data['date'] = gps.date_string("long")
        last_data['latitude'] = gps.latitude_string()
        last_data['longitude'] = gps.longitude_string()
while True:
    # read some data from module via I2C
    raw = i2c.readfrom(GPS_I2CADDR, 16)
    # feed into gps object
    for b in raw:
        sentence = gps.update(chr(b))
        if sentence is not None:
            # gps successfully parsed a message from module
            # see if we have valid coordinates
            res = check_for_valid_coordinates(gps)
print("Finished.")
if 'date' in last_data:
    print("@ ", last_data['date'])
if 'latitude' in last_data and 'longitude' in last_data:
    print("> ", last_data['latitude'], " ", last_data['longitude'])
i2c.deinit()

感谢您的帮助。谢谢。你知道吗


Tags: fordatadaterawifi2cgpslast