gnss: Implement new library for GNSS
This commit is contained in:
parent
741e1d9828
commit
84f424f631
|
@ -162,6 +162,9 @@ endif
|
|||
ifeq ($(CIRCUITPY_GAMEPADSHIFT),1)
|
||||
SRC_PATTERNS += gamepadshift/%
|
||||
endif
|
||||
ifeq ($(CIRCUITPY_GNSS),1)
|
||||
SRC_PATTERNS += gnss/%
|
||||
endif
|
||||
ifeq ($(CIRCUITPY_I2CSLAVE),1)
|
||||
SRC_PATTERNS += i2cslave/%
|
||||
endif
|
||||
|
@ -283,6 +286,10 @@ SRC_COMMON_HAL_ALL = \
|
|||
displayio/ParallelBus.c \
|
||||
frequencyio/FrequencyIn.c \
|
||||
frequencyio/__init__.c \
|
||||
gnss/__init__.c \
|
||||
gnss/GNSS.c \
|
||||
gnss/PositionFix.c \
|
||||
gnss/SatelliteSystem.c \
|
||||
i2cslave/I2CSlave.c \
|
||||
i2cslave/__init__.c \
|
||||
microcontroller/Pin.c \
|
||||
|
|
|
@ -401,6 +401,13 @@ extern const struct _mp_obj_module_t gamepadshift_module;
|
|||
#define GAMEPAD_ROOT_POINTERS
|
||||
#endif
|
||||
|
||||
#if CIRCUITPY_GNSS
|
||||
extern const struct _mp_obj_module_t gnss_module;
|
||||
#define GNSS_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_gnss), (mp_obj_t)&gnss_module },
|
||||
#else
|
||||
#define GNSS_MODULE
|
||||
#endif
|
||||
|
||||
#if CIRCUITPY_I2CSLAVE
|
||||
extern const struct _mp_obj_module_t i2cslave_module;
|
||||
#define I2CSLAVE_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_i2cslave), (mp_obj_t)&i2cslave_module },
|
||||
|
@ -682,6 +689,7 @@ extern const struct _mp_obj_module_t watchdog_module;
|
|||
FREQUENCYIO_MODULE \
|
||||
GAMEPAD_MODULE \
|
||||
GAMEPADSHIFT_MODULE \
|
||||
GNSS_MODULE \
|
||||
I2CSLAVE_MODULE \
|
||||
JSON_MODULE \
|
||||
MATH_MODULE \
|
||||
|
|
|
@ -109,6 +109,9 @@ CFLAGS += -DCIRCUITPY_GAMEPAD=$(CIRCUITPY_GAMEPAD)
|
|||
CIRCUITPY_GAMEPADSHIFT ?= 0
|
||||
CFLAGS += -DCIRCUITPY_GAMEPADSHIFT=$(CIRCUITPY_GAMEPADSHIFT)
|
||||
|
||||
CIRCUITPY_GNSS ?= 0
|
||||
CFLAGS += -DCIRCUITPY_GNSS=$(CIRCUITPY_GNSS)
|
||||
|
||||
CIRCUITPY_I2CSLAVE ?= $(CIRCUITPY_FULL_BUILD)
|
||||
CFLAGS += -DCIRCUITPY_I2CSLAVE=$(CIRCUITPY_I2CSLAVE)
|
||||
|
||||
|
|
|
@ -0,0 +1,245 @@
|
|||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright 2020 Sony Semiconductor Solutions Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "shared-bindings/gnss/GNSS.h"
|
||||
#include "shared-bindings/util.h"
|
||||
|
||||
#include "py/objproperty.h"
|
||||
#include "py/runtime.h"
|
||||
|
||||
//| class GNSS:
|
||||
//| """Get updated positioning information from GNSS
|
||||
//|
|
||||
//| Usage::
|
||||
//|
|
||||
//| import gnss
|
||||
//| import time
|
||||
//|
|
||||
//| gps = gnss.GNSS()
|
||||
//| gps.select(gnss.SatelliteSystem.GPS)
|
||||
//| gps.start()
|
||||
//| last_print = time.monotonic()
|
||||
//| while True:
|
||||
//| gps.update()
|
||||
//| current = time.monotonic()
|
||||
//| if current - last_print >= 1.0:
|
||||
//| last_print = current
|
||||
//| if gps.fix is gnss.PositionFix.INVALID:
|
||||
//| print("Waiting for fix...")
|
||||
//| continue
|
||||
//| print("Latitude: {0:.6f} degrees".format(gps.latitude))
|
||||
//| print("Longitude: {0:.6f} degrees".format(gps.longitude))"""
|
||||
//|
|
||||
|
||||
//| def __init__(self, ):
|
||||
//| """Turn on the GNSS."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t gnss_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
gnss_obj_t *self = m_new_obj(gnss_obj_t);
|
||||
self->base.type = &gnss_type;
|
||||
|
||||
common_hal_gnss_construct(self);
|
||||
return MP_OBJ_FROM_PTR(self);
|
||||
}
|
||||
|
||||
//| def deinit(self, ) -> Any:
|
||||
//| """Turn off the GNSS."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t gnss_obj_deinit(mp_obj_t self_in) {
|
||||
gnss_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
common_hal_gnss_deinit(self);
|
||||
return mp_const_none;
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(gnss_deinit_obj, gnss_obj_deinit);
|
||||
|
||||
STATIC void check_for_deinit(gnss_obj_t *self) {
|
||||
if (common_hal_gnss_deinited(self)) {
|
||||
raise_deinited_error();
|
||||
}
|
||||
}
|
||||
|
||||
//| def select(self, system: gnss.SatelliteSystem) -> Any:
|
||||
//| """Add specified satellite system to selection for positioning.
|
||||
//|
|
||||
//| :param gnss.SatelliteSystem system: satellite system to use"""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t gnss_obj_select(mp_obj_t self_in, mp_obj_t system_obj) {
|
||||
gnss_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
check_for_deinit(self);
|
||||
|
||||
gnss_satellitesystem_t system = gnss_satellitesystem_obj_to_type(system_obj);
|
||||
common_hal_gnss_select(self, system);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(gnss_select_obj, gnss_obj_select);
|
||||
|
||||
//| def deselect(self, system: gnss.SatelliteSystem) -> Any:
|
||||
//| """Remove specified satellite system from selection for positioning.
|
||||
//|
|
||||
//| :param gnss.SatelliteSystem system: satellite system to remove"""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t gnss_obj_deselect(mp_obj_t self_in, mp_obj_t system_obj) {
|
||||
gnss_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
check_for_deinit(self);
|
||||
|
||||
gnss_satellitesystem_t system = gnss_satellitesystem_obj_to_type(system_obj);
|
||||
common_hal_gnss_deselect(self, system);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(gnss_deselect_obj, gnss_obj_deselect);
|
||||
|
||||
//| def start(self, ) -> Any:
|
||||
//| """Start positioning."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t gnss_obj_start(mp_obj_t self_in) {
|
||||
gnss_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
check_for_deinit(self);
|
||||
|
||||
common_hal_gnss_start(self);
|
||||
return mp_const_none;
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(gnss_start_obj, gnss_obj_start);
|
||||
|
||||
//| def stop(self, ) -> Any:
|
||||
//| """Stop positioning."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t gnss_obj_stop(mp_obj_t self_in) {
|
||||
gnss_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
check_for_deinit(self);
|
||||
|
||||
common_hal_gnss_stop(self);
|
||||
return mp_const_none;
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(gnss_stop_obj, gnss_obj_stop);
|
||||
|
||||
//| def update(self, ) -> Any:
|
||||
//| """Update GNSS positioning information."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t gnss_obj_update(mp_obj_t self_in) {
|
||||
gnss_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
check_for_deinit(self);
|
||||
|
||||
common_hal_gnss_update(self);
|
||||
return mp_const_none;
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(gnss_update_obj, gnss_obj_update);
|
||||
|
||||
//| latitude: Any = ...
|
||||
//| """Latitude of current position."""
|
||||
//|
|
||||
STATIC mp_obj_t gnss_obj_get_latitude(mp_obj_t self_in) {
|
||||
gnss_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
check_for_deinit(self);
|
||||
return mp_obj_new_float(common_hal_gnss_get_latitude(self));
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(gnss_get_latitude_obj, gnss_obj_get_latitude);
|
||||
|
||||
const mp_obj_property_t gnss_latitude_obj = {
|
||||
.base.type = &mp_type_property,
|
||||
.proxy = {(mp_obj_t)&gnss_get_latitude_obj,
|
||||
(mp_obj_t)&mp_const_none_obj,
|
||||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//| longitude: Any = ...
|
||||
//| """Longitude of current position."""
|
||||
//|
|
||||
STATIC mp_obj_t gnss_obj_get_longitude(mp_obj_t self_in) {
|
||||
gnss_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
check_for_deinit(self);
|
||||
return mp_obj_new_float(common_hal_gnss_get_longitude(self));
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(gnss_get_longitude_obj, gnss_obj_get_longitude);
|
||||
|
||||
const mp_obj_property_t gnss_longitude_obj = {
|
||||
.base.type = &mp_type_property,
|
||||
.proxy = {(mp_obj_t)&gnss_get_longitude_obj,
|
||||
(mp_obj_t)&mp_const_none_obj,
|
||||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//| altitude: Any = ...
|
||||
//| """Altitude of current position."""
|
||||
//|
|
||||
STATIC mp_obj_t gnss_obj_get_altitude(mp_obj_t self_in) {
|
||||
gnss_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
check_for_deinit(self);
|
||||
return mp_obj_new_float(common_hal_gnss_get_altitude(self));
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(gnss_get_altitude_obj, gnss_obj_get_altitude);
|
||||
|
||||
const mp_obj_property_t gnss_altitude_obj = {
|
||||
.base.type = &mp_type_property,
|
||||
.proxy = {(mp_obj_t)&gnss_get_altitude_obj,
|
||||
(mp_obj_t)&mp_const_none_obj,
|
||||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//| fix: Any = ...
|
||||
//| """Fix mode."""
|
||||
//|
|
||||
STATIC mp_obj_t gnss_obj_get_fix(mp_obj_t self_in) {
|
||||
gnss_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
check_for_deinit(self);
|
||||
return gnss_positionfix_type_to_obj(common_hal_gnss_get_fix(self));
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(gnss_get_fix_obj, gnss_obj_get_fix);
|
||||
|
||||
const mp_obj_property_t gnss_fix_obj = {
|
||||
.base.type = &mp_type_property,
|
||||
.proxy = {(mp_obj_t)&gnss_get_fix_obj,
|
||||
(mp_obj_t)&mp_const_none_obj,
|
||||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
STATIC const mp_rom_map_elem_t gnss_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&gnss_deinit_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_select), MP_ROM_PTR(&gnss_select_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_deselect), MP_ROM_PTR(&gnss_deselect_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_start), MP_ROM_PTR(&gnss_start_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_stop), MP_ROM_PTR(&gnss_stop_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&gnss_update_obj) },
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_latitude), MP_ROM_PTR(&gnss_latitude_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_longitude), MP_ROM_PTR(&gnss_longitude_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_altitude), MP_ROM_PTR(&gnss_altitude_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_fix), MP_ROM_PTR(&gnss_fix_obj) }
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(gnss_locals_dict, gnss_locals_dict_table);
|
||||
|
||||
const mp_obj_type_t gnss_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_GNSS,
|
||||
.make_new = gnss_make_new,
|
||||
.locals_dict = (mp_obj_dict_t*)&gnss_locals_dict,
|
||||
};
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright 2020 Sony Semiconductor Solutions Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_GNSS_GNSS_H
|
||||
#define MICROPY_INCLUDED_SHARED_BINDINGS_GNSS_GNSS_H
|
||||
|
||||
#include "common-hal/gnss/GNSS.h"
|
||||
#include "shared-bindings/gnss/SatelliteSystem.h"
|
||||
#include "shared-bindings/gnss/PositionFix.h"
|
||||
|
||||
extern const mp_obj_type_t gnss_type;
|
||||
|
||||
void common_hal_gnss_construct(gnss_obj_t *self);
|
||||
void common_hal_gnss_deinit(gnss_obj_t *self);
|
||||
bool common_hal_gnss_deinited(gnss_obj_t *self);
|
||||
void common_hal_gnss_select(gnss_obj_t *self, gnss_satellitesystem_t system);
|
||||
void common_hal_gnss_deselect(gnss_obj_t *self, gnss_satellitesystem_t system);
|
||||
void common_hal_gnss_start(gnss_obj_t *self);
|
||||
void common_hal_gnss_stop(gnss_obj_t *self);
|
||||
void common_hal_gnss_update(gnss_obj_t *self);
|
||||
|
||||
mp_float_t common_hal_gnss_get_latitude(gnss_obj_t *self);
|
||||
mp_float_t common_hal_gnss_get_longitude(gnss_obj_t *self);
|
||||
mp_float_t common_hal_gnss_get_altitude(gnss_obj_t *self);
|
||||
gnss_positionfix_t common_hal_gnss_get_fix(gnss_obj_t *self);
|
||||
|
||||
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_GNSS_GNSS_H
|
|
@ -0,0 +1,108 @@
|
|||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright 2020 Sony Semiconductor Solutions Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "shared-bindings/gnss/PositionFix.h"
|
||||
|
||||
//| class PositionFix:
|
||||
//| """Position fix mode"""
|
||||
//|
|
||||
//| def __init__(self, ):
|
||||
//| """Enum-like class to define the position fix mode."""
|
||||
//|
|
||||
//| INVALID: Any = ...
|
||||
//| """No measurement.
|
||||
//|
|
||||
//| :type gnss.PositionFix:"""
|
||||
//|
|
||||
//| FIX_2D: Any = ...
|
||||
//| """2D fix.
|
||||
//|
|
||||
//| :type gnss.PositionFix:"""
|
||||
//|
|
||||
//| FIX_3D: Any = ...
|
||||
//| """3D fix.
|
||||
//|
|
||||
//| :type gnss.PositionFix:"""
|
||||
//|
|
||||
const mp_obj_type_t gnss_positionfix_type;
|
||||
|
||||
const gnss_positionfix_obj_t gnss_positionfix_invalid_obj = {
|
||||
{ &gnss_positionfix_type },
|
||||
};
|
||||
|
||||
const gnss_positionfix_obj_t gnss_positionfix_fix2d_obj = {
|
||||
{ &gnss_positionfix_type },
|
||||
};
|
||||
|
||||
const gnss_positionfix_obj_t gnss_positionfix_fix3d_obj = {
|
||||
{ &gnss_positionfix_type },
|
||||
};
|
||||
|
||||
gnss_positionfix_t gnss_positionfix_obj_to_type(mp_obj_t obj) {
|
||||
gnss_positionfix_t posfix = POSITIONFIX_INVALID;
|
||||
if (obj == MP_ROM_PTR(&gnss_positionfix_fix2d_obj)) {
|
||||
posfix = POSITIONFIX_2D;
|
||||
} else if (obj == MP_ROM_PTR(&gnss_positionfix_fix3d_obj)) {
|
||||
posfix = POSITIONFIX_3D;
|
||||
}
|
||||
return posfix;
|
||||
}
|
||||
|
||||
mp_obj_t gnss_positionfix_type_to_obj(gnss_positionfix_t posfix) {
|
||||
switch (posfix) {
|
||||
case POSITIONFIX_2D:
|
||||
return (mp_obj_t)MP_ROM_PTR(&gnss_positionfix_fix2d_obj);
|
||||
case POSITIONFIX_3D:
|
||||
return (mp_obj_t)MP_ROM_PTR(&gnss_positionfix_fix3d_obj);
|
||||
case POSITIONFIX_INVALID:
|
||||
default:
|
||||
return (mp_obj_t)MP_ROM_PTR(&gnss_positionfix_invalid_obj);
|
||||
}
|
||||
}
|
||||
|
||||
STATIC const mp_rom_map_elem_t gnss_positionfix_locals_dict_table[] = {
|
||||
{MP_ROM_QSTR(MP_QSTR_INVALID), MP_ROM_PTR(&gnss_positionfix_invalid_obj)},
|
||||
{MP_ROM_QSTR(MP_QSTR_FIX_2D), MP_ROM_PTR(&gnss_positionfix_fix2d_obj)},
|
||||
{MP_ROM_QSTR(MP_QSTR_FIX_3D), MP_ROM_PTR(&gnss_positionfix_fix3d_obj)},
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(gnss_positionfix_locals_dict, gnss_positionfix_locals_dict_table);
|
||||
|
||||
STATIC void gnss_positionfix_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
qstr posfix = MP_QSTR_INVALID;
|
||||
if (MP_OBJ_TO_PTR(self_in) == MP_ROM_PTR(&gnss_positionfix_fix2d_obj)) {
|
||||
posfix = MP_QSTR_FIX_2D;
|
||||
} else if (MP_OBJ_TO_PTR(self_in) == MP_ROM_PTR(&gnss_positionfix_fix3d_obj)) {
|
||||
posfix = MP_QSTR_FIX_3D;
|
||||
}
|
||||
mp_printf(print, "%q.%q.%q", MP_QSTR_gnss, MP_QSTR_PositionFix, posfix);
|
||||
}
|
||||
|
||||
const mp_obj_type_t gnss_positionfix_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_PositionFix,
|
||||
.print = gnss_positionfix_print,
|
||||
.locals_dict = (mp_obj_t)&gnss_positionfix_locals_dict,
|
||||
};
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright 2020 Sony Semiconductor Solutions Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_GNSS_POSITIONFIX_H
|
||||
#define MICROPY_INCLUDED_SHARED_BINDINGS_GNSS_POSITIONFIX_H
|
||||
|
||||
#include "py/obj.h"
|
||||
|
||||
typedef enum {
|
||||
POSITIONFIX_INVALID,
|
||||
POSITIONFIX_2D,
|
||||
POSITIONFIX_3D,
|
||||
} gnss_positionfix_t;
|
||||
|
||||
const mp_obj_type_t gnss_positionfix_type;
|
||||
|
||||
gnss_positionfix_t gnss_positionfix_obj_to_type(mp_obj_t obj);
|
||||
mp_obj_t gnss_positionfix_type_to_obj(gnss_positionfix_t mode);
|
||||
|
||||
typedef struct {
|
||||
mp_obj_base_t base;
|
||||
} gnss_positionfix_obj_t;
|
||||
extern const gnss_positionfix_obj_t gnss_positionfix_invalid_obj;
|
||||
extern const gnss_positionfix_obj_t gnss_positionfix_fix2d_obj;
|
||||
extern const gnss_positionfix_obj_t gnss_positionfix_fix3d_obj;
|
||||
|
||||
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_GNSS_POSITIONFIX_H
|
|
@ -0,0 +1,145 @@
|
|||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright 2020 Sony Semiconductor Solutions Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "shared-bindings/gnss/SatelliteSystem.h"
|
||||
|
||||
//| class SatelliteSystem:
|
||||
//| """Satellite system type"""
|
||||
//|
|
||||
//| def __init__(self, ):
|
||||
//| """Enum-like class to define the satellite system type."""
|
||||
//|
|
||||
//| GPS: Any = ...
|
||||
//| """Global Positioning System.
|
||||
//|
|
||||
//| :type gnss.SatelliteSystem:"""
|
||||
//|
|
||||
//| GLONASS: Any = ...
|
||||
//| """GLObal NAvigation Satellite System.
|
||||
//|
|
||||
//| :type gnss.SatelliteSystem:"""
|
||||
//|
|
||||
//| SBAS: Any = ...
|
||||
//| """Satellite Based Augmentation System.
|
||||
//|
|
||||
//| :type gnss.SatelliteSystem:"""
|
||||
//|
|
||||
//| QZSS_L1CA: Any = ...
|
||||
//| """Quasi-Zenith Satellite System L1C/A.
|
||||
//|
|
||||
//| :type gnss.SatelliteSystem:"""
|
||||
//|
|
||||
//| QZSS_L1S: Any = ...
|
||||
//| """Quasi-Zenith Satellite System L1S.
|
||||
//|
|
||||
//| :type gnss.SatelliteSystem:"""
|
||||
//|
|
||||
const mp_obj_type_t gnss_satellitesystem_type;
|
||||
|
||||
const gnss_satellitesystem_obj_t gnss_satellitesystem_gps_obj = {
|
||||
{ &gnss_satellitesystem_type },
|
||||
};
|
||||
|
||||
const gnss_satellitesystem_obj_t gnss_satellitesystem_glonass_obj = {
|
||||
{ &gnss_satellitesystem_type },
|
||||
};
|
||||
|
||||
const gnss_satellitesystem_obj_t gnss_satellitesystem_sbas_obj = {
|
||||
{ &gnss_satellitesystem_type },
|
||||
};
|
||||
|
||||
const gnss_satellitesystem_obj_t gnss_satellitesystem_qzss_l1ca_obj = {
|
||||
{ &gnss_satellitesystem_type },
|
||||
};
|
||||
|
||||
const gnss_satellitesystem_obj_t gnss_satellitesystem_qzss_l1s_obj = {
|
||||
{ &gnss_satellitesystem_type },
|
||||
};
|
||||
|
||||
gnss_satellitesystem_t gnss_satellitesystem_obj_to_type(mp_obj_t obj) {
|
||||
if (obj == MP_ROM_PTR(&gnss_satellitesystem_gps_obj)) {
|
||||
return SATELLITESYSTEM_GPS;
|
||||
} else if (obj == MP_ROM_PTR(&gnss_satellitesystem_glonass_obj)) {
|
||||
return SATELLITESYSTEM_GLONASS;
|
||||
} else if (obj == MP_ROM_PTR(&gnss_satellitesystem_sbas_obj)) {
|
||||
return SATELLITESYSTEM_SBAS;
|
||||
} else if (obj == MP_ROM_PTR(&gnss_satellitesystem_qzss_l1ca_obj)) {
|
||||
return SATELLITESYSTEM_QZSS_L1CA;
|
||||
} else if (obj == MP_ROM_PTR(&gnss_satellitesystem_qzss_l1s_obj)) {
|
||||
return SATELLITESYSTEM_QZSS_L1S;
|
||||
}
|
||||
return SATELLITESYSTEM_NONE;
|
||||
}
|
||||
|
||||
mp_obj_t gnss_satellitesystem_type_to_obj(gnss_satellitesystem_t system) {
|
||||
switch (system) {
|
||||
case SATELLITESYSTEM_GPS:
|
||||
return (mp_obj_t)MP_ROM_PTR(&gnss_satellitesystem_gps_obj);
|
||||
case SATELLITESYSTEM_GLONASS:
|
||||
return (mp_obj_t)MP_ROM_PTR(&gnss_satellitesystem_glonass_obj);
|
||||
case SATELLITESYSTEM_SBAS:
|
||||
return (mp_obj_t)MP_ROM_PTR(&gnss_satellitesystem_sbas_obj);
|
||||
case SATELLITESYSTEM_QZSS_L1CA:
|
||||
return (mp_obj_t)MP_ROM_PTR(&gnss_satellitesystem_qzss_l1ca_obj);
|
||||
case SATELLITESYSTEM_QZSS_L1S:
|
||||
return (mp_obj_t)MP_ROM_PTR(&gnss_satellitesystem_qzss_l1s_obj);
|
||||
case SATELLITESYSTEM_NONE:
|
||||
default:
|
||||
return (mp_obj_t)MP_ROM_PTR(&mp_const_none_obj);
|
||||
}
|
||||
}
|
||||
|
||||
STATIC const mp_rom_map_elem_t gnss_satellitesystem_locals_dict_table[] = {
|
||||
{MP_ROM_QSTR(MP_QSTR_GPS), MP_ROM_PTR(&gnss_satellitesystem_gps_obj)},
|
||||
{MP_ROM_QSTR(MP_QSTR_GLONASS), MP_ROM_PTR(&gnss_satellitesystem_glonass_obj)},
|
||||
{MP_ROM_QSTR(MP_QSTR_SBAS), MP_ROM_PTR(&gnss_satellitesystem_sbas_obj)},
|
||||
{MP_ROM_QSTR(MP_QSTR_QZSS_L1CA), MP_ROM_PTR(&gnss_satellitesystem_qzss_l1ca_obj)},
|
||||
{MP_ROM_QSTR(MP_QSTR_QZSS_L1S), MP_ROM_PTR(&gnss_satellitesystem_qzss_l1s_obj)},
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(gnss_satellitesystem_locals_dict, gnss_satellitesystem_locals_dict_table);
|
||||
|
||||
STATIC void gnss_satellitesystem_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
qstr system = MP_QSTR_None;
|
||||
if (MP_OBJ_TO_PTR(self_in) == MP_ROM_PTR(&gnss_satellitesystem_gps_obj)) {
|
||||
system = MP_QSTR_GPS;
|
||||
} else if (MP_OBJ_TO_PTR(self_in) == MP_ROM_PTR(&gnss_satellitesystem_glonass_obj)) {
|
||||
system = MP_QSTR_GLONASS;
|
||||
} else if (MP_OBJ_TO_PTR(self_in) == MP_ROM_PTR(&gnss_satellitesystem_sbas_obj)) {
|
||||
system = MP_QSTR_SBAS;
|
||||
} else if (MP_OBJ_TO_PTR(self_in) == MP_ROM_PTR(&gnss_satellitesystem_qzss_l1ca_obj)) {
|
||||
system = MP_QSTR_QZSS_L1CA;
|
||||
} else if (MP_OBJ_TO_PTR(self_in) == MP_ROM_PTR(&gnss_satellitesystem_qzss_l1s_obj)) {
|
||||
system = MP_QSTR_QZSS_L1S;
|
||||
}
|
||||
mp_printf(print, "%q.%q.%q", MP_QSTR_gnss, MP_QSTR_SatelliteSystem, system);
|
||||
}
|
||||
|
||||
const mp_obj_type_t gnss_satellitesystem_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_SatelliteSystem,
|
||||
.print = gnss_satellitesystem_print,
|
||||
.locals_dict = (mp_obj_t)&gnss_satellitesystem_locals_dict,
|
||||
};
|
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright 2020 Sony Semiconductor Solutions Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_GNSS_SATELLITESYSTEM_H
|
||||
#define MICROPY_INCLUDED_SHARED_BINDINGS_GNSS_SATELLITESYSTEM_H
|
||||
|
||||
#include "py/obj.h"
|
||||
|
||||
typedef enum {
|
||||
SATELLITESYSTEM_NONE,
|
||||
SATELLITESYSTEM_GPS,
|
||||
SATELLITESYSTEM_GLONASS,
|
||||
SATELLITESYSTEM_SBAS,
|
||||
SATELLITESYSTEM_QZSS_L1CA,
|
||||
SATELLITESYSTEM_QZSS_L1S,
|
||||
} gnss_satellitesystem_t;
|
||||
|
||||
const mp_obj_type_t gnss_satellitesystem_type;
|
||||
|
||||
gnss_satellitesystem_t gnss_satellitesystem_obj_to_type(mp_obj_t obj);
|
||||
mp_obj_t gnss_satellitesystem_type_to_obj(gnss_satellitesystem_t mode);
|
||||
|
||||
typedef struct {
|
||||
mp_obj_base_t base;
|
||||
} gnss_satellitesystem_obj_t;
|
||||
extern const gnss_satellitesystem_obj_t gnss_satellitesystem_gps_obj;
|
||||
extern const gnss_satellitesystem_obj_t gnss_satellitesystem_glonass_obj;
|
||||
extern const gnss_satellitesystem_obj_t gnss_satellitesystem_sbas_obj;
|
||||
extern const gnss_satellitesystem_obj_t gnss_satellitesystem_qzss_l1ca_obj;
|
||||
extern const gnss_satellitesystem_obj_t gnss_satellitesystem_qzss_l1s_obj;
|
||||
|
||||
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_GNSS_SATELLITESYSTEM_H
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright 2020 Sony Semiconductor Solutions Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "py/obj.h"
|
||||
#include "py/runtime.h"
|
||||
#include "py/mphal.h"
|
||||
#include "shared-bindings/gnss/GNSS.h"
|
||||
#include "shared-bindings/gnss/SatelliteSystem.h"
|
||||
#include "shared-bindings/gnss/PositionFix.h"
|
||||
#include "shared-bindings/util.h"
|
||||
|
||||
//| """Global Navigation Satellite System
|
||||
//|
|
||||
//| The `gnss` module contains classes to control the GNSS and acquire positioning information."""
|
||||
//|
|
||||
STATIC const mp_rom_map_elem_t gnss_module_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_gnss) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_GNSS), MP_ROM_PTR(&gnss_type) },
|
||||
|
||||
// Enum-like Classes.
|
||||
{ MP_ROM_QSTR(MP_QSTR_SatelliteSystem), MP_ROM_PTR(&gnss_satellitesystem_type) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_PositionFix), MP_ROM_PTR(&gnss_positionfix_type) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(gnss_module_globals, gnss_module_globals_table);
|
||||
|
||||
const mp_obj_module_t gnss_module = {
|
||||
.base = { &mp_type_module },
|
||||
.globals = (mp_obj_dict_t*)&gnss_module_globals,
|
||||
};
|
Loading…
Reference in New Issue