cjn-PiTools 1.2__tar.gz → 1.2.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {cjn_pitools-1.2/src/cjn_PiTools.egg-info → cjn_pitools-1.2.2}/PKG-INFO +28 -12
- {cjn_pitools-1.2 → cjn_pitools-1.2.2}/README.md +25 -10
- {cjn_pitools-1.2 → cjn_pitools-1.2.2}/pyproject.toml +12 -2
- {cjn_pitools-1.2 → cjn_pitools-1.2.2}/src/cjn_PiTools/ADC121C.py +20 -9
- {cjn_pitools-1.2 → cjn_pitools-1.2.2}/src/cjn_PiTools/HTU21D.py +23 -6
- {cjn_pitools-1.2 → cjn_pitools-1.2.2}/src/cjn_PiTools/PCA9548.py +26 -14
- {cjn_pitools-1.2 → cjn_pitools-1.2.2}/src/cjn_PiTools/PiOLED.py +8 -8
- {cjn_pitools-1.2 → cjn_pitools-1.2.2}/src/cjn_PiTools/SHT3x.py +1 -1
- {cjn_pitools-1.2 → cjn_pitools-1.2.2/src/cjn_PiTools.egg-info}/PKG-INFO +28 -12
- {cjn_pitools-1.2 → cjn_pitools-1.2.2}/src/cjn_PiTools.egg-info/requires.txt +2 -1
- {cjn_pitools-1.2 → cjn_pitools-1.2.2}/LICENSE +0 -0
- {cjn_pitools-1.2 → cjn_pitools-1.2.2}/setup.cfg +0 -0
- {cjn_pitools-1.2 → cjn_pitools-1.2.2}/src/cjn_PiTools/DS18B20.py +0 -0
- {cjn_pitools-1.2 → cjn_pitools-1.2.2}/src/cjn_PiTools/MCP23008.py +0 -0
- {cjn_pitools-1.2 → cjn_pitools-1.2.2}/src/cjn_PiTools/PiBlinky.py +0 -0
- {cjn_pitools-1.2 → cjn_pitools-1.2.2}/src/cjn_PiTools/__init__.py +0 -0
- {cjn_pitools-1.2 → cjn_pitools-1.2.2}/src/cjn_PiTools/deployment_files/PiOLED_server.cfg +0 -0
- {cjn_pitools-1.2 → cjn_pitools-1.2.2}/src/cjn_PiTools/deployment_files/PiOLED_server.service +0 -0
- {cjn_pitools-1.2 → cjn_pitools-1.2.2}/src/cjn_PiTools/deployment_files/initW1buses.service +0 -0
- {cjn_pitools-1.2 → cjn_pitools-1.2.2}/src/cjn_PiTools/fonts/C&C Red Alert [INET].ttf +0 -0
- {cjn_pitools-1.2 → cjn_pitools-1.2.2}/src/cjn_PiTools/fonts/ChiKareGo.ttf +0 -0
- {cjn_pitools-1.2 → cjn_pitools-1.2.2}/src/cjn_PiTools/fonts/FreePixel.ttf +0 -0
- {cjn_pitools-1.2 → cjn_pitools-1.2.2}/src/cjn_PiTools/fonts/GLECB.TTF +0 -0
- {cjn_pitools-1.2 → cjn_pitools-1.2.2}/src/cjn_PiTools/fonts/ProggyTiny.ttf +0 -0
- {cjn_pitools-1.2 → cjn_pitools-1.2.2}/src/cjn_PiTools/fonts/README [INET].txt +0 -0
- {cjn_pitools-1.2 → cjn_pitools-1.2.2}/src/cjn_PiTools/fonts/Volter__28Goldfish_29.ttf +0 -0
- {cjn_pitools-1.2 → cjn_pitools-1.2.2}/src/cjn_PiTools/fonts/code2000.ttf +0 -0
- {cjn_pitools-1.2 → cjn_pitools-1.2.2}/src/cjn_PiTools/fonts/creep.bdf +0 -0
- {cjn_pitools-1.2 → cjn_pitools-1.2.2}/src/cjn_PiTools/fonts/fontawesome-webfont.ttf +0 -0
- {cjn_pitools-1.2 → cjn_pitools-1.2.2}/src/cjn_PiTools/fonts/miscfs_.ttf +0 -0
- {cjn_pitools-1.2 → cjn_pitools-1.2.2}/src/cjn_PiTools/fonts/pixelmix.ttf +0 -0
- {cjn_pitools-1.2 → cjn_pitools-1.2.2}/src/cjn_PiTools/fonts/tiny.ttf +0 -0
- {cjn_pitools-1.2 → cjn_pitools-1.2.2}/src/cjn_PiTools/initW1buses.py +0 -0
- {cjn_pitools-1.2 → cjn_pitools-1.2.2}/src/cjn_PiTools/shared.py +0 -0
- {cjn_pitools-1.2 → cjn_pitools-1.2.2}/src/cjn_PiTools.egg-info/SOURCES.txt +0 -0
- {cjn_pitools-1.2 → cjn_pitools-1.2.2}/src/cjn_PiTools.egg-info/dependency_links.txt +0 -0
- {cjn_pitools-1.2 → cjn_pitools-1.2.2}/src/cjn_PiTools.egg-info/entry_points.txt +0 -0
- {cjn_pitools-1.2 → cjn_pitools-1.2.2}/src/cjn_PiTools.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cjn_PiTools
|
|
3
|
-
Version: 1.2
|
|
3
|
+
Version: 1.2.2
|
|
4
4
|
Summary: cjn's library of Raspberry Pi functions, drivers, tools, ...
|
|
5
5
|
Author-email: Chris Nelson <github@cjnaz.com>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -10,12 +10,13 @@ Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
|
10
10
|
Requires-Python: >=3.9
|
|
11
11
|
Description-Content-Type: text/markdown
|
|
12
12
|
License-File: LICENSE
|
|
13
|
-
Requires-Dist: cjnfuncs>=3.2
|
|
13
|
+
Requires-Dist: cjnfuncs>=3.2.1
|
|
14
14
|
Requires-Dist: luma.oled
|
|
15
15
|
Requires-Dist: pillow
|
|
16
16
|
Requires-Dist: spidev
|
|
17
17
|
Requires-Dist: smbus2
|
|
18
18
|
Requires-Dist: RPi.GPIO
|
|
19
|
+
Requires-Dist: crc
|
|
19
20
|
Provides-Extra: pigpio
|
|
20
21
|
Requires-Dist: pigpio; extra == "pigpio"
|
|
21
22
|
Dynamic: license-file
|
|
@@ -77,21 +78,36 @@ If using the pigpio driver:
|
|
|
77
78
|
|
|
78
79
|
## Key changes since the prior major public release (1.1)
|
|
79
80
|
|
|
80
|
-
V1.2
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
81
|
+
V1.2.2 Changes
|
|
82
|
+
- Minor tweak on PiOLED logging of IPC handle names
|
|
83
|
+
V1.2.1 Changes
|
|
84
|
+
- HTU21D dummy user reg reads for measurement reads stability, init changed do_soft_reset > do_reset, consistent with SHT3x.
|
|
85
|
+
- PCA9548 monitor_ch feature
|
|
86
|
+
- ADC121C read_conversion_result _force_address_ switch added to address issue when a second process accesses the device and leaves the address register set elsewhere
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
V1.2 Changes
|
|
90
|
+
- PiOLED uses shared memory, changed from display_file - cjnfuncs 3.2 dependency
|
|
91
|
+
- PiOLED add toolname to pioled_display_driver pioled_shm_lock and pioled_go_flag .get_lock() calls
|
|
92
|
+
- PiOLED taillog command
|
|
93
|
+
- Debug logging of MCP23008 set_register() and set_bits() values
|
|
85
94
|
|
|
86
95
|
|
|
87
96
|
<br/>
|
|
88
97
|
|
|
89
98
|
## Revision history
|
|
90
|
-
- 1.2 -
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
99
|
+
- 1.2.2 260828 - Corrected PiOLED logging of IPC handle names
|
|
100
|
+
- 1.2.1 260526
|
|
101
|
+
- HTU21D dummy user reg reads for measurement reads stability
|
|
102
|
+
- PCA9548 monitor_ch
|
|
103
|
+
- ADC121C read_conversion_result force_address switch added
|
|
104
|
+
- PiOLED tweaks
|
|
105
|
+
- HTU21D init changed do_soft_reset > do_reset, consistent with SHT3x
|
|
106
|
+
- 1.2 260506
|
|
107
|
+
- PiOLED uses shared memory, changed from display_file - cjnfuncs 3.2 dependency
|
|
108
|
+
- PiOLED add toolname to pioled_display_driver pioled_shm_lock and pioled_go_flag .get_lock() calls
|
|
109
|
+
- PiOLED taillog command
|
|
110
|
+
- Debug logging of MCP23008 set_register() and set_bits() values
|
|
95
111
|
- 1.1.1 260401 - pyproject.toml cleanup, keywords
|
|
96
112
|
- 1.1 260401 - Added ADC121C, HTU21D, MCP23008, PCA9548, and SHT3x drivers
|
|
97
113
|
- 1.0 260207 - New. Bundled PiBlinky, PiOLED, initW1buses, and DS18B20 modules
|
|
@@ -55,21 +55,36 @@ If using the pigpio driver:
|
|
|
55
55
|
|
|
56
56
|
## Key changes since the prior major public release (1.1)
|
|
57
57
|
|
|
58
|
-
V1.2
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
58
|
+
V1.2.2 Changes
|
|
59
|
+
- Minor tweak on PiOLED logging of IPC handle names
|
|
60
|
+
V1.2.1 Changes
|
|
61
|
+
- HTU21D dummy user reg reads for measurement reads stability, init changed do_soft_reset > do_reset, consistent with SHT3x.
|
|
62
|
+
- PCA9548 monitor_ch feature
|
|
63
|
+
- ADC121C read_conversion_result _force_address_ switch added to address issue when a second process accesses the device and leaves the address register set elsewhere
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
V1.2 Changes
|
|
67
|
+
- PiOLED uses shared memory, changed from display_file - cjnfuncs 3.2 dependency
|
|
68
|
+
- PiOLED add toolname to pioled_display_driver pioled_shm_lock and pioled_go_flag .get_lock() calls
|
|
69
|
+
- PiOLED taillog command
|
|
70
|
+
- Debug logging of MCP23008 set_register() and set_bits() values
|
|
63
71
|
|
|
64
72
|
|
|
65
73
|
<br/>
|
|
66
74
|
|
|
67
75
|
## Revision history
|
|
68
|
-
- 1.2 -
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
76
|
+
- 1.2.2 260828 - Corrected PiOLED logging of IPC handle names
|
|
77
|
+
- 1.2.1 260526
|
|
78
|
+
- HTU21D dummy user reg reads for measurement reads stability
|
|
79
|
+
- PCA9548 monitor_ch
|
|
80
|
+
- ADC121C read_conversion_result force_address switch added
|
|
81
|
+
- PiOLED tweaks
|
|
82
|
+
- HTU21D init changed do_soft_reset > do_reset, consistent with SHT3x
|
|
83
|
+
- 1.2 260506
|
|
84
|
+
- PiOLED uses shared memory, changed from display_file - cjnfuncs 3.2 dependency
|
|
85
|
+
- PiOLED add toolname to pioled_display_driver pioled_shm_lock and pioled_go_flag .get_lock() calls
|
|
86
|
+
- PiOLED taillog command
|
|
87
|
+
- Debug logging of MCP23008 set_register() and set_bits() values
|
|
73
88
|
- 1.1.1 260401 - pyproject.toml cleanup, keywords
|
|
74
89
|
- 1.1 260401 - Added ADC121C, HTU21D, MCP23008, PCA9548, and SHT3x drivers
|
|
75
90
|
- 1.0 260207 - New. Bundled PiBlinky, PiOLED, initW1buses, and DS18B20 modules
|
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = 'cjn_PiTools'
|
|
3
|
-
version = "1.2"
|
|
3
|
+
version = "1.2.2"
|
|
4
|
+
# 1.2.2 - Corrected PiOLED logging of IPC handle names, missing crc dependency
|
|
5
|
+
# 1.2.1
|
|
6
|
+
# HTU21D dummy user reg reads for measurement reads stability
|
|
7
|
+
# PCA9548 monitor_ch
|
|
8
|
+
# ADC121C read_conversion_result force_address switch added
|
|
9
|
+
# PiOLED tweaks
|
|
10
|
+
# HTU21D init changed do_soft_reset > do_reset, consistent with SHT3x
|
|
11
|
+
# 1.2 release
|
|
4
12
|
# PiOLED uses shared memory, changed from display_file - cjnfuncs 3.2 dependency
|
|
5
13
|
# PiOLED add toolname to pioled_display_driver pioled_shm_lock and pioled_go_flag .get_lock() calls
|
|
6
14
|
# PiOLED taillog command
|
|
7
15
|
# Debug logging of MCP23008 set_register() and set_bits() values
|
|
16
|
+
# doc fixes
|
|
8
17
|
# 1.1.1 - pyproject.toml cleanup, Added to keywords
|
|
9
18
|
# 1.1 - Final cleanup, release
|
|
10
19
|
# 1.0.1 - PiOLED startup display file access check debug
|
|
@@ -16,12 +25,13 @@ requires-python = ">=3.9"
|
|
|
16
25
|
authors = [ {name = "Chris Nelson", email = "github@cjnaz.com"} ]
|
|
17
26
|
license = "MIT"
|
|
18
27
|
dependencies = [
|
|
19
|
-
'cjnfuncs >= 3.2',
|
|
28
|
+
'cjnfuncs >= 3.2.1',
|
|
20
29
|
'luma.oled',
|
|
21
30
|
'pillow',
|
|
22
31
|
'spidev',
|
|
23
32
|
'smbus2',
|
|
24
33
|
'RPi.GPIO',
|
|
34
|
+
'crc', # SHT3x
|
|
25
35
|
]
|
|
26
36
|
keywords = ['cjnaz', 'cjnfuncs', 'Raspberry', 'Raspberry Pi', 'RPi',
|
|
27
37
|
'luma', 'luma.oled', 'OLED',
|
|
@@ -181,17 +181,26 @@ Create an ADC121C family device instance
|
|
|
181
181
|
#=====================================================================================
|
|
182
182
|
#=====================================================================================
|
|
183
183
|
|
|
184
|
-
def read_conversion_result(self):
|
|
184
|
+
def read_conversion_result(self, force_address=False):
|
|
185
185
|
"""
|
|
186
186
|
## read_conversion_result () - Return the measured voltage
|
|
187
187
|
|
|
188
188
|
***ADC121C class member function***
|
|
189
189
|
|
|
190
190
|
|
|
191
|
+
### Args
|
|
192
|
+
`force_address` (bool, default False)
|
|
193
|
+
- If True, force the Address Pointer Register byte to be written
|
|
194
|
+
- Needed if a separate process should access the device and independently change the address pointer register
|
|
195
|
+
while the current process thinks the the register still points to the conversion result register (and thus does
|
|
196
|
+
not write/update the address pointer register).
|
|
197
|
+
|
|
198
|
+
|
|
191
199
|
### Returns
|
|
192
200
|
- Tuple (Alert Flag bit, Measured Voltage (float))
|
|
193
201
|
- Tuple (I2C_ERROR, I2C_ERROR) on I2C IO error
|
|
194
202
|
|
|
203
|
+
|
|
195
204
|
### Behaviors and rules
|
|
196
205
|
- The 12-bit code read from the device is scaled by Vref and returned as the measured voltage
|
|
197
206
|
- Setting the register Address Pointer to the Conversion Result register is skipped on consecutive calls
|
|
@@ -200,13 +209,15 @@ to `read_conversion_result()`
|
|
|
200
209
|
adc121c_logger.debug (f"<{self.device_name}> ***** read_conversion_result()")
|
|
201
210
|
|
|
202
211
|
try:
|
|
203
|
-
if not self.conv_rslt_reg_addressed:
|
|
212
|
+
if not self.conv_rslt_reg_addressed or force_address:
|
|
213
|
+
if force_address:
|
|
214
|
+
adc121c_logger.debug (f"<{self.device_name}> Force reset of the Address Pointer Register")
|
|
204
215
|
self.pi_i2c_bus_handle.i2c_write_device (self.device_addr, [CONVERSION_RSLT_REG_PTR])
|
|
205
216
|
self.conv_rslt_reg_addressed = True
|
|
206
217
|
(count, data) = self.pi_i2c_bus_handle.i2c_read_device(self.device_addr, 2)
|
|
207
218
|
conv_result = (((data[0] & 0x0f) << 8) | (data[1] & 0xff)) / 4096 * self.Vref
|
|
208
219
|
alert_flag = 1 if data[0] & 0x80 else 0
|
|
209
|
-
adc121c_logger.debug (f"
|
|
220
|
+
adc121c_logger.debug (f"<{self.device_name}> Conversion result: (0x{data[0]:0>2x} 0x{data[1]:0>2x}) = <{conv_result:5.3f}V>, Alert flag <{alert_flag}>")
|
|
210
221
|
return alert_flag, conv_result
|
|
211
222
|
|
|
212
223
|
except Exception as e:
|
|
@@ -242,7 +253,7 @@ to `read_conversion_result()`
|
|
|
242
253
|
|
|
243
254
|
over_range_alert = (alert_status_reg_value & 0b00000010) >> 1
|
|
244
255
|
under_range_alert = alert_status_reg_value & 0b00000001
|
|
245
|
-
adc121c_logger.debug (f"over_range_alert: <{over_range_alert}>, under_range_alert: <{under_range_alert}>")
|
|
256
|
+
adc121c_logger.debug (f"<{self.device_name}> over_range_alert: <{over_range_alert}>, under_range_alert: <{under_range_alert}>")
|
|
246
257
|
return over_range_alert, under_range_alert
|
|
247
258
|
|
|
248
259
|
except Exception as e:
|
|
@@ -528,7 +539,7 @@ The register value is converted to a voltage based on Vref
|
|
|
528
539
|
self.conv_rslt_reg_addressed = False
|
|
529
540
|
(count, data) = self.pi_i2c_bus_handle.i2c_read_device(self.device_addr, 2)
|
|
530
541
|
vlow_limit_value = (((data[0] & 0x0f) << 8) | (data[1] & 0xff)) / 4096 * self.Vref
|
|
531
|
-
adc121c_logger.debug (f"
|
|
542
|
+
adc121c_logger.debug (f"<{self.device_name}> VLow limit: (0x{data[0]:0>2x} 0x{data[1]:0>2x}) = <{vlow_limit_value:5.3f}V>")
|
|
532
543
|
return vlow_limit_value
|
|
533
544
|
|
|
534
545
|
except Exception as e:
|
|
@@ -601,7 +612,7 @@ The register value is converted to a voltage based on Vref
|
|
|
601
612
|
self.conv_rslt_reg_addressed = False
|
|
602
613
|
(count, data) = self.pi_i2c_bus_handle.i2c_read_device(self.device_addr, 2)
|
|
603
614
|
vhigh_limit_value = (((data[0] & 0x0f) << 8) | (data[1] & 0xff)) / 4096 * self.Vref
|
|
604
|
-
adc121c_logger.debug (f"
|
|
615
|
+
adc121c_logger.debug (f"<{self.device_name}> VHigh limit: (0x{data[0]:0>2x} 0x{data[1]:0>2x}) = <{vhigh_limit_value:5.3f}V>")
|
|
605
616
|
return vhigh_limit_value
|
|
606
617
|
|
|
607
618
|
except Exception as e:
|
|
@@ -674,7 +685,7 @@ The register value is converted to a voltage based on Vref
|
|
|
674
685
|
self.conv_rslt_reg_addressed = False
|
|
675
686
|
(count, data) = self.pi_i2c_bus_handle.i2c_read_device(self.device_addr, 2)
|
|
676
687
|
vhyst_value = (((data[0] & 0x0f) << 8) | (data[1] & 0xff)) / 4096 * self.Vref
|
|
677
|
-
adc121c_logger.debug (f"
|
|
688
|
+
adc121c_logger.debug (f"<{self.device_name}> Vhyst value: (0x{data[0]:0>2x} 0x{data[1]:0>2x}) = <{vhyst_value:5.3f}V>")
|
|
678
689
|
return vhyst_value
|
|
679
690
|
|
|
680
691
|
except Exception as e:
|
|
@@ -752,7 +763,7 @@ mode (switching to Normal mode).
|
|
|
752
763
|
self.conv_rslt_reg_addressed = False
|
|
753
764
|
(count, data) = self.pi_i2c_bus_handle.i2c_read_device(self.device_addr, 2)
|
|
754
765
|
vmin_value = (((data[0] & 0x0f) << 8) | (data[1] & 0xff)) / 4096 * self.Vref
|
|
755
|
-
adc121c_logger.debug (f"
|
|
766
|
+
adc121c_logger.debug (f"<{self.device_name}> Vmin value: (0x{data[0]:0>2x} 0x{data[1]:0>2x}) = <{vmin_value:5.3f}V>")
|
|
756
767
|
return vmin_value
|
|
757
768
|
|
|
758
769
|
except Exception as e:
|
|
@@ -826,7 +837,7 @@ The register value is converted to a voltage based on Vref
|
|
|
826
837
|
self.conv_rslt_reg_addressed = False
|
|
827
838
|
(count, data) = self.pi_i2c_bus_handle.i2c_read_device(self.device_addr, 2)
|
|
828
839
|
vmax_value = (((data[0] & 0x0f) << 8) | (data[1] & 0xff)) / 4096 * self.Vref
|
|
829
|
-
adc121c_logger.debug (f"
|
|
840
|
+
adc121c_logger.debug (f"<{self.device_name}> Vmax value: (0x{data[0]:0>2x} 0x{data[1]:0>2x}) = <{vmax_value:5.3f}V>")
|
|
830
841
|
return vmax_value
|
|
831
842
|
|
|
832
843
|
except Exception as e:
|
|
@@ -39,7 +39,7 @@ htu21d_logger = logging.getLogger('cjn_PiTools.HTU21D')
|
|
|
39
39
|
|
|
40
40
|
class HTU21D:
|
|
41
41
|
"""
|
|
42
|
-
## Class HTU21D (device_name, pi_i2c_bus_handle,
|
|
42
|
+
## Class HTU21D (device_name, pi_i2c_bus_handle, do_reset=True) - HTU21D library for Raspberry Pi
|
|
43
43
|
|
|
44
44
|
Create an HTU21D device instance
|
|
45
45
|
|
|
@@ -50,8 +50,9 @@ Create an HTU21D device instance
|
|
|
50
50
|
`pi_i2c_bus_handle` (cjn_PiTools.shared.pi_i2c instance)
|
|
51
51
|
- Get a `pi_i2c` instance handle in the tools script code and pass it to this device instantiation
|
|
52
52
|
|
|
53
|
-
`
|
|
53
|
+
`do_reset` (bool, default True)
|
|
54
54
|
- If True, issue a soft reset as part of instantiation
|
|
55
|
+
- Set to False if the device is not available at instantiation time, and reset the device before reading values
|
|
55
56
|
|
|
56
57
|
|
|
57
58
|
### Class instance variables - as passed in at instantiation
|
|
@@ -70,7 +71,7 @@ Create an HTU21D device instance
|
|
|
70
71
|
|
|
71
72
|
logging.getLogger('cjn_PiTools.HTU21D').setLevel(logging.DEBUG)
|
|
72
73
|
"""
|
|
73
|
-
def __init__(self, device_name, pi_i2c_bus_handle,
|
|
74
|
+
def __init__(self, device_name, pi_i2c_bus_handle, do_reset=True):
|
|
74
75
|
self.device_name = device_name
|
|
75
76
|
self.device_addr = HTU21D_ADDR
|
|
76
77
|
self.pi_i2c_bus_handle = pi_i2c_bus_handle
|
|
@@ -78,11 +79,11 @@ Create an HTU21D device instance
|
|
|
78
79
|
if not isinstance(self.device_name, str):
|
|
79
80
|
raise ValueError (f"HTU21D device_name must be a str. Received <{device_name}>")
|
|
80
81
|
|
|
81
|
-
if not isinstance(
|
|
82
|
-
raise ValueError (f"<{self.device_name}>
|
|
82
|
+
if not isinstance(do_reset, bool):
|
|
83
|
+
raise ValueError (f"<{self.device_name}> do_reset must be a bool. Received <{do_reset}>")
|
|
83
84
|
|
|
84
85
|
|
|
85
|
-
if
|
|
86
|
+
if do_reset:
|
|
86
87
|
if self.soft_reset() == I2C_ERROR:
|
|
87
88
|
raise RuntimeError (f"<{self.device_name}> soft_reset during instantiation failed")
|
|
88
89
|
|
|
@@ -268,6 +269,10 @@ Calls `fetch_temperature()` after triggering the hold mode temperature measureme
|
|
|
268
269
|
Args, Returns, and Behaviors info.
|
|
269
270
|
"""
|
|
270
271
|
htu21d_logger.debug (f"<{self.device_name}> ***** read_temperature()")
|
|
272
|
+
try:
|
|
273
|
+
self.read_user_reg(quiet=True)
|
|
274
|
+
except:
|
|
275
|
+
pass
|
|
271
276
|
try:
|
|
272
277
|
self.pi_i2c_bus_handle.i2c_write_byte(self.device_addr, TRIGGER_TEMP_MEASURE_HOLD)
|
|
273
278
|
except Exception as e:
|
|
@@ -304,6 +309,10 @@ obtain the measured result after an appropriate delay. See the datasheet for mea
|
|
|
304
309
|
- If the measurement is still in progress then I2C_ERROR is returned, and `fetch_temperature()` should be called again later.
|
|
305
310
|
"""
|
|
306
311
|
htu21d_logger.debug (f"<{self.device_name}> ***** trigger_temperature_nohold()")
|
|
312
|
+
try:
|
|
313
|
+
self.read_user_reg(quiet=True)
|
|
314
|
+
except:
|
|
315
|
+
pass
|
|
307
316
|
try:
|
|
308
317
|
self.pi_i2c_bus_handle.i2c_write_byte(self.device_addr, TRIGGER_TEMP_MEASURE_NOHOLD)
|
|
309
318
|
return 0
|
|
@@ -402,6 +411,10 @@ Calls `fetch_RH()` after triggering the hold mode RH measurement. See `fetch_RH
|
|
|
402
411
|
Args, Returns, and Behaviors info.
|
|
403
412
|
"""
|
|
404
413
|
htu21d_logger.debug (f"<{self.device_name}> ***** read_RH()")
|
|
414
|
+
try:
|
|
415
|
+
self.read_user_reg(quiet=True)
|
|
416
|
+
except:
|
|
417
|
+
pass
|
|
405
418
|
try:
|
|
406
419
|
self.pi_i2c_bus_handle.i2c_write_byte(self.device_addr, TRIGGER_RH_MEASURE_HOLD)
|
|
407
420
|
except Exception as e:
|
|
@@ -437,6 +450,10 @@ obtain the measured result after an appropriate delay. See the datasheet for mea
|
|
|
437
450
|
- If the measurement is still in progress then I2C_ERROR is returned, and `fetch_RH()` should be called again later.
|
|
438
451
|
"""
|
|
439
452
|
htu21d_logger.debug (f"<{self.device_name}> ***** trigger_RH_nohold()")
|
|
453
|
+
try:
|
|
454
|
+
self.read_user_reg(quiet=True)
|
|
455
|
+
except:
|
|
456
|
+
pass
|
|
440
457
|
try:
|
|
441
458
|
self.pi_i2c_bus_handle.i2c_write_byte(self.device_addr, TRIGGER_RH_MEASURE_NOHOLD)
|
|
442
459
|
return 0
|
|
@@ -39,6 +39,10 @@ Create a PCA9548 device instance
|
|
|
39
39
|
`pi_i2c_bus_handle` (cjn_PiTools.shared.pi_i2c instance)
|
|
40
40
|
- Get an instance handle in the tools script code and pass it to this device instantiation
|
|
41
41
|
|
|
42
|
+
`monitor_ch` (int or str, default int 0)
|
|
43
|
+
- Setting the `monitor_ch` enables channel(s) to alway be enabled, and thus available for monitoring bus activity
|
|
44
|
+
- See `write_control_reg(write_value)` for allowed values
|
|
45
|
+
|
|
42
46
|
|
|
43
47
|
### Class instance variables
|
|
44
48
|
`device_name` (str)
|
|
@@ -47,9 +51,12 @@ Create a PCA9548 device instance
|
|
|
47
51
|
`device_addr` (int)
|
|
48
52
|
- As from instantiation
|
|
49
53
|
|
|
50
|
-
`
|
|
54
|
+
`channel_enable_bitmap` (int)
|
|
51
55
|
- Current mask of enabled channels (1=enabled) - value range 0x00 to 0xFF
|
|
52
56
|
|
|
57
|
+
`monitor_ch_bitmap` (int)
|
|
58
|
+
- Decoded `monitor_ch` bitmap from instantiation
|
|
59
|
+
|
|
53
60
|
|
|
54
61
|
### Returns
|
|
55
62
|
- Handle to the PCA9548 instance on success
|
|
@@ -64,10 +71,11 @@ Create a PCA9548 device instance
|
|
|
64
71
|
|
|
65
72
|
"""
|
|
66
73
|
|
|
67
|
-
def __init__ (self, device_name, device_addr, pi_i2c_bus_handle):
|
|
74
|
+
def __init__ (self, device_name, device_addr, pi_i2c_bus_handle, monitor_ch=0x00):
|
|
68
75
|
self.device_name = device_name
|
|
69
76
|
self.device_addr = device_addr
|
|
70
77
|
self.pi_i2c_bus_handle = pi_i2c_bus_handle
|
|
78
|
+
self.monitor_ch_bitmap = 0x00
|
|
71
79
|
|
|
72
80
|
if not isinstance (self.device_name, str):
|
|
73
81
|
raise ValueError (f"PCA9548 device.name must be str, received <{device_name}>")
|
|
@@ -76,7 +84,11 @@ Create a PCA9548 device instance
|
|
|
76
84
|
raise ValueError (f"<{self.device_name}> PCA9548 device.addr must be 0x70 - 0x77, received <0x{device_addr:0>x}>")
|
|
77
85
|
|
|
78
86
|
api = 'smbus' if self.pi_i2c_bus_handle.api == 'smbus' else 'pigpio'
|
|
79
|
-
|
|
87
|
+
|
|
88
|
+
if monitor_ch:
|
|
89
|
+
self.monitor_ch_bitmap = self._build_bitmap(monitor_ch)
|
|
90
|
+
# PCA9548_logger.debug (f"<{self.device_name}> ")
|
|
91
|
+
PCA9548_logger.debug (f"<{self.device_name}> New PCA9548 device defined at addr <0x{self.device_addr:0>2x}> using api <{api}> on i2c bus <{self.pi_i2c_bus_handle.i2c_bus_num}>, Monitor channel(s) enabled: <{self._bitmap_to_channel_str(self.monitor_ch_bitmap)}>")
|
|
80
92
|
|
|
81
93
|
|
|
82
94
|
#=====================================================================================
|
|
@@ -91,7 +103,7 @@ Create a PCA9548 device instance
|
|
|
91
103
|
|
|
92
104
|
***PCA9548 class member function***
|
|
93
105
|
|
|
94
|
-
The `write_value` is written to the control register and saved in `
|
|
106
|
+
The `write_value` is written to the control register and saved in `channel_enable_bitmap`
|
|
95
107
|
|
|
96
108
|
|
|
97
109
|
### Args
|
|
@@ -100,30 +112,30 @@ The `write_value` is written to the control register and saved in `channel_enabl
|
|
|
100
112
|
- If int value: Used directly as the channel enable mask
|
|
101
113
|
- If str '-1': Sets the channel enable mask to 0x00 (no channels enabled)
|
|
102
114
|
- If str '0' to '7': Enables the individual channel, and disables all others, e.g., '2' resolves to 0b00000100
|
|
103
|
-
- The resolved value is also saved to the instance variable `
|
|
115
|
+
- The resolved value is also saved to the instance variable `channel_enable_bitmap`
|
|
104
116
|
|
|
105
117
|
|
|
106
118
|
### Returns
|
|
107
|
-
- `
|
|
119
|
+
- `channel_enable_bitmap` value on success
|
|
108
120
|
- I2C_ERROR if unable to write to the control register
|
|
109
121
|
- Raises ValueError if `write_value` is not valid
|
|
110
122
|
"""
|
|
111
123
|
|
|
112
124
|
PCA9548_logger.debug (f"<{self.device_name}> ***** write_control_reg()")
|
|
113
125
|
|
|
114
|
-
|
|
126
|
+
channel_enable_bitmap = self._build_bitmap(write_value) | self.monitor_ch_bitmap
|
|
115
127
|
|
|
116
128
|
if PCA9548_logger.isEnabledFor(logging.DEBUG):
|
|
117
|
-
PCA9548_logger.debug (f"<{self.device_name}> New mask: <0b{
|
|
129
|
+
PCA9548_logger.debug (f"<{self.device_name}> New mask: <0b{channel_enable_bitmap:0>8b}>, channels <{self._bitmap_to_channel_str(channel_enable_bitmap)}>")
|
|
118
130
|
|
|
119
131
|
try:
|
|
120
|
-
result = self.pi_i2c_bus_handle.i2c_write_byte(self.device_addr,
|
|
121
|
-
self.
|
|
132
|
+
result = self.pi_i2c_bus_handle.i2c_write_byte(self.device_addr, channel_enable_bitmap)
|
|
133
|
+
self.channel_enable_bitmap = channel_enable_bitmap
|
|
122
134
|
except Exception as e:
|
|
123
135
|
PCA9548_logger.debug (f"<{self.device_name}> exception: {type(e).__name__}: {e}")
|
|
124
136
|
return I2C_ERROR
|
|
125
137
|
|
|
126
|
-
return
|
|
138
|
+
return channel_enable_bitmap
|
|
127
139
|
|
|
128
140
|
|
|
129
141
|
#=====================================================================================
|
|
@@ -153,7 +165,7 @@ The `write_value` is written to the control register and saved in `channel_enabl
|
|
|
153
165
|
return I2C_ERROR
|
|
154
166
|
|
|
155
167
|
if PCA9548_logger.isEnabledFor(logging.DEBUG) and current_ch_enable_mask >= 0x00: # TODO pigpio returns negative error codes. Log and return I2C_ERROR
|
|
156
|
-
PCA9548_logger.debug (f"<{self.device_name}> Current mask: <0b{current_ch_enable_mask:0>8b}>, channels <{self.
|
|
168
|
+
PCA9548_logger.debug (f"<{self.device_name}> Current mask: <0b{current_ch_enable_mask:0>8b}>, channels <{self._bitmap_to_channel_str(current_ch_enable_mask)}>")
|
|
157
169
|
return current_ch_enable_mask
|
|
158
170
|
|
|
159
171
|
|
|
@@ -164,7 +176,7 @@ The `write_value` is written to the control register and saved in `channel_enabl
|
|
|
164
176
|
#=====================================================================================
|
|
165
177
|
#=====================================================================================
|
|
166
178
|
|
|
167
|
-
def
|
|
179
|
+
def _build_bitmap (self, channel_value):
|
|
168
180
|
"""
|
|
169
181
|
Accepts channel_value
|
|
170
182
|
int 0x00 to 0xFF: Set channels per bit mask
|
|
@@ -192,7 +204,7 @@ The `write_value` is written to the control register and saved in `channel_enabl
|
|
|
192
204
|
return 0x01 << int(xx)
|
|
193
205
|
|
|
194
206
|
|
|
195
|
-
def
|
|
207
|
+
def _bitmap_to_channel_str(self, bit_mask):
|
|
196
208
|
"""
|
|
197
209
|
returns str of enabled channels for logging
|
|
198
210
|
e.g., 0b00000101 returns '0 2'
|
|
@@ -236,7 +236,7 @@ class pioled_display_driver:
|
|
|
236
236
|
return 1
|
|
237
237
|
|
|
238
238
|
if not pioled_shm_lock.get_lock(lock_info=self.toolname + ' - message_page'):
|
|
239
|
-
periodic_log(f"Failed to get
|
|
239
|
+
periodic_log(f"Failed to get <{PIOLED_SHM_LOCK}>. Current lock owner: <{pioled_shm_lock.get_lock_info()}> - Skipping",
|
|
240
240
|
category='get pioled_shm_lock', logger_name='pioled_logger', log_interval='1h', log_level=logging.WARNING)
|
|
241
241
|
return 1
|
|
242
242
|
|
|
@@ -491,7 +491,7 @@ def cli():
|
|
|
491
491
|
if args.service:
|
|
492
492
|
ll = [config.getcfg('LogLevel', logging.WARNING), logging.INFO, logging.DEBUG][args.verbose]
|
|
493
493
|
set_logging_level (ll) # Set root logger level for the server process
|
|
494
|
-
set_logging_level (ll, logger_name='cjnfuncs.resourcelock')
|
|
494
|
+
set_logging_level (ll, logger_name='cjnfuncs.resourcelock')
|
|
495
495
|
|
|
496
496
|
if args.val_logfile:
|
|
497
497
|
# setuplogging (call_logfile=args.val_logfile, call_logfile_wins=True, FileLogFormat=SERVER_CONS_LOGGING_FORMAT)
|
|
@@ -512,20 +512,20 @@ def cli():
|
|
|
512
512
|
print ("-----------------------------")
|
|
513
513
|
print (f"\n{subprocess.run(['systemctl', 'status', 'PiOLED_server'], capture_output=True, text=True).stdout}")
|
|
514
514
|
print ("-----------------------------")
|
|
515
|
-
print (f"
|
|
516
|
-
print (f"
|
|
515
|
+
print (f"<{PIOLED_GO_FLAG}> is currently set? <{pioled_go_flag.is_locked()}>, last locked by: <{pioled_go_flag.get_lock_info()}>")
|
|
516
|
+
print (f"<{PIOLED_SHM_LOCK}> is currently set? <{pioled_shm_lock.is_locked()}>, last locked by: <{pioled_shm_lock.get_lock_info()}>")
|
|
517
517
|
print ("-----------------------------")
|
|
518
518
|
sys.exit()
|
|
519
519
|
|
|
520
520
|
|
|
521
521
|
# ----------- U N L O C K -----------
|
|
522
522
|
if args.Command == 'unlock':
|
|
523
|
-
print (f"Before forced unlock:
|
|
523
|
+
print (f"Before forced unlock: <{PIOLED_GO_FLAG}> is currently set? <{pioled_go_flag.is_locked()}>")
|
|
524
524
|
pioled_go_flag.unget_lock(force=True, where_called='PiOLED.main - UNLOCK forced unlock')
|
|
525
|
-
print (f"After forced unlock:
|
|
526
|
-
print (f"Before forced unlock:
|
|
525
|
+
print (f"After forced unlock: <{PIOLED_GO_FLAG}> is currently set? <{pioled_go_flag.is_locked()}>")
|
|
526
|
+
print (f"Before forced unlock: <{PIOLED_SHM_LOCK}> is currently locked? <{pioled_shm_lock.is_locked()}>")
|
|
527
527
|
pioled_shm_lock.unget_lock(force=True, where_called='PiOLED.main - UNLOCK forced unlock')
|
|
528
|
-
print (f"After forced unlock:
|
|
528
|
+
print (f"After forced unlock: <{PIOLED_SHM_LOCK}> is currently locked? <{pioled_shm_lock.is_locked()}>")
|
|
529
529
|
sys.exit()
|
|
530
530
|
|
|
531
531
|
|
|
@@ -95,7 +95,7 @@ Create a SHT3x family device instance
|
|
|
95
95
|
|
|
96
96
|
`do_reset` (bool, default True)
|
|
97
97
|
- If True, call `soft_reset()` and `clear_status_reg()` as part of instantiation
|
|
98
|
-
-
|
|
98
|
+
- Set to False if the device is not available at instantiation time, and reset the device before reading values
|
|
99
99
|
|
|
100
100
|
|
|
101
101
|
### Class instance variables - as passed in at instantiation
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cjn_PiTools
|
|
3
|
-
Version: 1.2
|
|
3
|
+
Version: 1.2.2
|
|
4
4
|
Summary: cjn's library of Raspberry Pi functions, drivers, tools, ...
|
|
5
5
|
Author-email: Chris Nelson <github@cjnaz.com>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -10,12 +10,13 @@ Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
|
10
10
|
Requires-Python: >=3.9
|
|
11
11
|
Description-Content-Type: text/markdown
|
|
12
12
|
License-File: LICENSE
|
|
13
|
-
Requires-Dist: cjnfuncs>=3.2
|
|
13
|
+
Requires-Dist: cjnfuncs>=3.2.1
|
|
14
14
|
Requires-Dist: luma.oled
|
|
15
15
|
Requires-Dist: pillow
|
|
16
16
|
Requires-Dist: spidev
|
|
17
17
|
Requires-Dist: smbus2
|
|
18
18
|
Requires-Dist: RPi.GPIO
|
|
19
|
+
Requires-Dist: crc
|
|
19
20
|
Provides-Extra: pigpio
|
|
20
21
|
Requires-Dist: pigpio; extra == "pigpio"
|
|
21
22
|
Dynamic: license-file
|
|
@@ -77,21 +78,36 @@ If using the pigpio driver:
|
|
|
77
78
|
|
|
78
79
|
## Key changes since the prior major public release (1.1)
|
|
79
80
|
|
|
80
|
-
V1.2
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
81
|
+
V1.2.2 Changes
|
|
82
|
+
- Minor tweak on PiOLED logging of IPC handle names
|
|
83
|
+
V1.2.1 Changes
|
|
84
|
+
- HTU21D dummy user reg reads for measurement reads stability, init changed do_soft_reset > do_reset, consistent with SHT3x.
|
|
85
|
+
- PCA9548 monitor_ch feature
|
|
86
|
+
- ADC121C read_conversion_result _force_address_ switch added to address issue when a second process accesses the device and leaves the address register set elsewhere
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
V1.2 Changes
|
|
90
|
+
- PiOLED uses shared memory, changed from display_file - cjnfuncs 3.2 dependency
|
|
91
|
+
- PiOLED add toolname to pioled_display_driver pioled_shm_lock and pioled_go_flag .get_lock() calls
|
|
92
|
+
- PiOLED taillog command
|
|
93
|
+
- Debug logging of MCP23008 set_register() and set_bits() values
|
|
85
94
|
|
|
86
95
|
|
|
87
96
|
<br/>
|
|
88
97
|
|
|
89
98
|
## Revision history
|
|
90
|
-
- 1.2 -
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
99
|
+
- 1.2.2 260828 - Corrected PiOLED logging of IPC handle names
|
|
100
|
+
- 1.2.1 260526
|
|
101
|
+
- HTU21D dummy user reg reads for measurement reads stability
|
|
102
|
+
- PCA9548 monitor_ch
|
|
103
|
+
- ADC121C read_conversion_result force_address switch added
|
|
104
|
+
- PiOLED tweaks
|
|
105
|
+
- HTU21D init changed do_soft_reset > do_reset, consistent with SHT3x
|
|
106
|
+
- 1.2 260506
|
|
107
|
+
- PiOLED uses shared memory, changed from display_file - cjnfuncs 3.2 dependency
|
|
108
|
+
- PiOLED add toolname to pioled_display_driver pioled_shm_lock and pioled_go_flag .get_lock() calls
|
|
109
|
+
- PiOLED taillog command
|
|
110
|
+
- Debug logging of MCP23008 set_register() and set_bits() values
|
|
95
111
|
- 1.1.1 260401 - pyproject.toml cleanup, keywords
|
|
96
112
|
- 1.1 260401 - Added ADC121C, HTU21D, MCP23008, PCA9548, and SHT3x drivers
|
|
97
113
|
- 1.0 260207 - New. Bundled PiBlinky, PiOLED, initW1buses, and DS18B20 modules
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{cjn_pitools-1.2 → cjn_pitools-1.2.2}/src/cjn_PiTools/deployment_files/PiOLED_server.service
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|