Skip to content

Commit 280f34b

Browse files
committed
Small code formatting changes
1 parent efa933a commit 280f34b

File tree

4 files changed

+27
-27
lines changed

4 files changed

+27
-27
lines changed

pypozyx/structures/byte_structure.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ def change_data(self, index, new_data):
8787
else:
8888
print("Trying to change data with invalid new values (use int or list)")
8989

90-
def load(self, data, convert=1):
90+
# TODO make convert use True/False not 1/0
91+
def load(self, data, convert=True):
9192
"""Loads data in its relevant class components."""
9293
raise NotImplementedError(
9394
'load(data) should be customised for every derived structure')

pypozyx/structures/device.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
contains all of the UWB settings: channel, bitrate, prf, plen, and gain.
1717
"""
1818

19-
from pypozyx.definitions.constants import *
2019
from pypozyx.definitions.bitmasks import PozyxBitmasks
2120
from pypozyx.structures.byte_structure import ByteStructure
2221
from pypozyx.structures.generic import Data

pypozyx/structures/generic.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@
3737
>>> d = Data([0] * len(data_format), data_format)
3838
"""
3939

40-
import struct
41-
4240
from pypozyx.structures.byte_structure import ByteStructure
4341

4442

@@ -103,6 +101,7 @@ def dataCheck(data):
103101
return False
104102
return True
105103

104+
106105
class XYZ(ByteStructure):
107106
"""
108107
Generic XYZ data structure consisting of 3 integers x, y, and z.
@@ -124,7 +123,7 @@ def __init__(self, x=0, y=0, z=0):
124123
self.z = z
125124
self.data = [x, y, z]
126125

127-
def load(self, data=[0] * 3, convert=1):
126+
def load(self, data, convert=True):
128127
self.data = data
129128
if convert:
130129
self.x = data[0] / self.physical_convert
@@ -182,7 +181,7 @@ def __init__(self, data=None, data_format=None):
182181
self.set_packed_size()
183182
self.byte_data = '00' * self.byte_size
184183

185-
def load(self, data, convert=1):
184+
def load(self, data, convert=True):
186185
self.data = data
187186

188187

@@ -212,11 +211,13 @@ def __init__(self, value=0, size=1, signed=0, print_style='hex'):
212211
data_format = 'h'
213212
elif size == 4:
214213
data_format = 'i'
214+
else:
215+
raise ValueError("Size should be 1, 2, or 4")
215216
if signed == 0:
216217
data_format = data_format.capitalize()
217218
Data.__init__(self, [value], data_format)
218219

219-
def load(self, data, convert=1):
220+
def load(self, data, convert=True):
220221
self.data = data
221222

222223
@property
@@ -227,7 +228,6 @@ def value(self):
227228
def value(self, new_value):
228229
self.data[0] = new_value
229230

230-
231231
def __str__(self):
232232
if self.print_style is 'hex':
233233
return hex(self.data[0]).capitalize()
@@ -236,6 +236,7 @@ def __str__(self):
236236
else:
237237
return str(self.data[0])
238238

239+
239240
class SingleSensorValue(ByteStructure):
240241
"""
241242
Generic Single Sensor Value data structure.
@@ -255,7 +256,7 @@ def __init__(self, value=0):
255256
self.value = value
256257
self.load([value])
257258

258-
def load(self, data=[0], convert=1):
259+
def load(self, data=[0], convert=True):
259260
self.data = data
260261
if convert:
261262
self.value = float(data[0]) / self.physical_convert

pypozyx/structures/sensor_data.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
"""pypozyx.structures.sensor_data - Contains container classes for data from the Pozyx's many sensors."""
44
from math import sqrt
55

6-
from pypozyx.definitions.constants import (POZYX_ACCEL_DIV_MG, POZYX_MAG_DIV_UT, POZYX_GYRO_DIV_DPS,
7-
POZYX_QUAT_DIV, POZYX_MAX_LIN_ACCEL_DIV_MG, POZYX_TEMP_DIV_CELSIUS, POZYX_PRESS_DIV_PA, POZYX_EULER_DIV_DEG)
6+
from pypozyx.definitions.constants import PozyxConstants
87
from pypozyx.structures.byte_structure import ByteStructure
98
from pypozyx.structures.generic import XYZ, SingleSensorValue
109

@@ -14,7 +13,7 @@ class Coordinates(XYZ):
1413
byte_size = 12
1514
data_format = 'iii'
1615

17-
def load(self, data, convert=0):
16+
def load(self, data, convert=False):
1817
self.data = data
1918
self.x = data[0]
2019
self.y = data[1]
@@ -23,36 +22,36 @@ def load(self, data, convert=0):
2322

2423
class Acceleration(XYZ):
2524
"""Container for acceleration in x, y, and z (in mg)."""
26-
physical_convert = POZYX_ACCEL_DIV_MG
25+
physical_convert = PozyxConstants.POZYX_ACCEL_DIV_MG
2726

2827
byte_size = 6
2928
data_format = 'hhh'
3029

3130

3231
class Magnetic(XYZ):
3332
"""Container for coordinates in x, y, and z (in uT)."""
34-
physical_convert = POZYX_MAG_DIV_UT
33+
physical_convert = PozyxConstants.POZYX_MAG_DIV_UT
3534

3635
byte_size = 6
3736
data_format = 'hhh'
3837

3938

4039
class AngularVelocity(XYZ):
4140
"""Container for angular velocity in x, y, and z (in dps)."""
42-
physical_convert = POZYX_GYRO_DIV_DPS
41+
physical_convert = PozyxConstants.POZYX_GYRO_DIV_DPS
4342

4443
byte_size = 6
4544
data_format = 'hhh'
4645

4746

4847
class LinearAcceleration(XYZ):
4948
"""Container for linear acceleration in x, y, and z (in mg), as floats."""
50-
physical_convert = POZYX_ACCEL_DIV_MG
49+
physical_convert = PozyxConstants.POZYX_ACCEL_DIV_MG
5150

5251
byte_size = 6
5352
data_format = 'hhh'
5453

55-
def load(self, data, convert=1):
54+
def load(self, data, convert=True):
5655
if convert:
5756
self.x = float(data[0]) / self.physical_convert
5857
self.y = float(data[1]) / self.physical_convert
@@ -96,7 +95,7 @@ def __str__(self):
9695

9796
class Quaternion(XYZ):
9897
"""Container for quaternion data in x, y, z and w."""
99-
physical_convert = POZYX_QUAT_DIV
98+
physical_convert = PozyxConstants.POZYX_QUAT_DIV
10099

101100
byte_size = 8
102101
data_format = 'hhhh'
@@ -107,7 +106,7 @@ def __init__(self, w=0, x=0, y=0, z=0):
107106
self.data = [w, x, y, z]
108107
self.w = w
109108

110-
def load(self, data, convert=1):
109+
def load(self, data, convert=True):
111110
for i in range(len(data)):
112111
data[i] = float(data[i])
113112
XYZ.load(self, data[1:4], convert)
@@ -141,14 +140,14 @@ def __str__(self):
141140

142141

143142
class MaxLinearAcceleration(SingleSensorValue):
144-
physical_convert = POZYX_MAX_LIN_ACCEL_DIV_MG
143+
physical_convert = PozyxConstants.POZYX_MAX_LIN_ACCEL_DIV_MG
145144

146145
byte_size = 2
147146
data_format = 'h'
148147

149148

150149
class Temperature(SingleSensorValue):
151-
physical_convert = POZYX_TEMP_DIV_CELSIUS
150+
physical_convert = PozyxConstants.POZYX_TEMP_DIV_CELSIUS
152151

153152
byte_size = 1
154153
data_format = 'b'
@@ -158,15 +157,15 @@ def __str__(self):
158157

159158

160159
class Pressure(SingleSensorValue):
161-
physical_convert = POZYX_PRESS_DIV_PA
160+
physical_convert = PozyxConstants.POZYX_PRESS_DIV_PA
162161

163162
byte_size = 4
164163
data_format = 'I'
165164

166165

167166
class EulerAngles(ByteStructure):
168167
"""Container for euler angles as heading, roll, and pitch (in degrees)."""
169-
physical_convert = POZYX_EULER_DIV_DEG
168+
physical_convert = PozyxConstants.POZYX_EULER_DIV_DEG
170169

171170
byte_size = 6
172171
data_format = 'hhh'
@@ -178,7 +177,7 @@ def __init__(self, heading=0, roll=0, pitch=0):
178177
self.roll = roll
179178
self.pitch = pitch
180179

181-
def load(self, data, convert=1):
180+
def load(self, data, convert=True):
182181
self.data = data
183182
if convert:
184183
self.heading = float(data[0]) / self.physical_convert
@@ -236,7 +235,7 @@ def __init__(self, data=[0] * 24):
236235
self.gravity_vector = LinearAcceleration(data[20], data[21], data[22])
237236
self.temperature = Temperature(data[23])
238237

239-
def load(self, data, convert=1):
238+
def load(self, data, convert=True):
240239
self.data = data
241240
self.pressure.load([data[0]], convert)
242241
self.acceleration.load(data[1:4], convert)
@@ -272,5 +271,5 @@ def __init__(self, data=[0] * 24):
272271
"""Initializes the RawSensorData object"""
273272
SensorData.__init__(self, data)
274273

275-
def load(self, data, convert=0):
276-
SensorData.load(self, data, convert=0)
274+
def load(self, data):
275+
SensorData.load(self, data, convert=False)

0 commit comments

Comments
 (0)