cjn-PiTools 1.2__tar.gz → 1.2.1__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.
Files changed (38) hide show
  1. {cjn_pitools-1.2/src/cjn_PiTools.egg-info → cjn_pitools-1.2.1}/PKG-INFO +16 -4
  2. {cjn_pitools-1.2 → cjn_pitools-1.2.1}/README.md +14 -2
  3. {cjn_pitools-1.2 → cjn_pitools-1.2.1}/pyproject.toml +10 -2
  4. {cjn_pitools-1.2 → cjn_pitools-1.2.1}/src/cjn_PiTools/ADC121C.py +20 -9
  5. {cjn_pitools-1.2 → cjn_pitools-1.2.1}/src/cjn_PiTools/HTU21D.py +23 -6
  6. {cjn_pitools-1.2 → cjn_pitools-1.2.1}/src/cjn_PiTools/PCA9548.py +26 -14
  7. {cjn_pitools-1.2 → cjn_pitools-1.2.1}/src/cjn_PiTools/PiOLED.py +6 -6
  8. {cjn_pitools-1.2 → cjn_pitools-1.2.1}/src/cjn_PiTools/SHT3x.py +1 -1
  9. {cjn_pitools-1.2 → cjn_pitools-1.2.1/src/cjn_PiTools.egg-info}/PKG-INFO +16 -4
  10. {cjn_pitools-1.2 → cjn_pitools-1.2.1}/src/cjn_PiTools.egg-info/requires.txt +1 -1
  11. {cjn_pitools-1.2 → cjn_pitools-1.2.1}/LICENSE +0 -0
  12. {cjn_pitools-1.2 → cjn_pitools-1.2.1}/setup.cfg +0 -0
  13. {cjn_pitools-1.2 → cjn_pitools-1.2.1}/src/cjn_PiTools/DS18B20.py +0 -0
  14. {cjn_pitools-1.2 → cjn_pitools-1.2.1}/src/cjn_PiTools/MCP23008.py +0 -0
  15. {cjn_pitools-1.2 → cjn_pitools-1.2.1}/src/cjn_PiTools/PiBlinky.py +0 -0
  16. {cjn_pitools-1.2 → cjn_pitools-1.2.1}/src/cjn_PiTools/__init__.py +0 -0
  17. {cjn_pitools-1.2 → cjn_pitools-1.2.1}/src/cjn_PiTools/deployment_files/PiOLED_server.cfg +0 -0
  18. {cjn_pitools-1.2 → cjn_pitools-1.2.1}/src/cjn_PiTools/deployment_files/PiOLED_server.service +0 -0
  19. {cjn_pitools-1.2 → cjn_pitools-1.2.1}/src/cjn_PiTools/deployment_files/initW1buses.service +0 -0
  20. {cjn_pitools-1.2 → cjn_pitools-1.2.1}/src/cjn_PiTools/fonts/C&C Red Alert [INET].ttf +0 -0
  21. {cjn_pitools-1.2 → cjn_pitools-1.2.1}/src/cjn_PiTools/fonts/ChiKareGo.ttf +0 -0
  22. {cjn_pitools-1.2 → cjn_pitools-1.2.1}/src/cjn_PiTools/fonts/FreePixel.ttf +0 -0
  23. {cjn_pitools-1.2 → cjn_pitools-1.2.1}/src/cjn_PiTools/fonts/GLECB.TTF +0 -0
  24. {cjn_pitools-1.2 → cjn_pitools-1.2.1}/src/cjn_PiTools/fonts/ProggyTiny.ttf +0 -0
  25. {cjn_pitools-1.2 → cjn_pitools-1.2.1}/src/cjn_PiTools/fonts/README [INET].txt +0 -0
  26. {cjn_pitools-1.2 → cjn_pitools-1.2.1}/src/cjn_PiTools/fonts/Volter__28Goldfish_29.ttf +0 -0
  27. {cjn_pitools-1.2 → cjn_pitools-1.2.1}/src/cjn_PiTools/fonts/code2000.ttf +0 -0
  28. {cjn_pitools-1.2 → cjn_pitools-1.2.1}/src/cjn_PiTools/fonts/creep.bdf +0 -0
  29. {cjn_pitools-1.2 → cjn_pitools-1.2.1}/src/cjn_PiTools/fonts/fontawesome-webfont.ttf +0 -0
  30. {cjn_pitools-1.2 → cjn_pitools-1.2.1}/src/cjn_PiTools/fonts/miscfs_.ttf +0 -0
  31. {cjn_pitools-1.2 → cjn_pitools-1.2.1}/src/cjn_PiTools/fonts/pixelmix.ttf +0 -0
  32. {cjn_pitools-1.2 → cjn_pitools-1.2.1}/src/cjn_PiTools/fonts/tiny.ttf +0 -0
  33. {cjn_pitools-1.2 → cjn_pitools-1.2.1}/src/cjn_PiTools/initW1buses.py +0 -0
  34. {cjn_pitools-1.2 → cjn_pitools-1.2.1}/src/cjn_PiTools/shared.py +0 -0
  35. {cjn_pitools-1.2 → cjn_pitools-1.2.1}/src/cjn_PiTools.egg-info/SOURCES.txt +0 -0
  36. {cjn_pitools-1.2 → cjn_pitools-1.2.1}/src/cjn_PiTools.egg-info/dependency_links.txt +0 -0
  37. {cjn_pitools-1.2 → cjn_pitools-1.2.1}/src/cjn_PiTools.egg-info/entry_points.txt +0 -0
  38. {cjn_pitools-1.2 → cjn_pitools-1.2.1}/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.1
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,7 +10,7 @@ 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
@@ -77,7 +77,13 @@ If using the pigpio driver:
77
77
 
78
78
  ## Key changes since the prior major public release (1.1)
79
79
 
80
- V1.2 - Changes
80
+ V1.2.1 Changes
81
+ - HTU21D dummy user reg reads for measurement reads stability, init changed do_soft_reset > do_reset, consistent with SHT3x.
82
+ - PCA9548 monitor_ch feature
83
+ - 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
84
+
85
+
86
+ V1.2 Changes
81
87
  PiOLED uses shared memory, changed from display_file - cjnfuncs 3.2 dependency
82
88
  PiOLED add toolname to pioled_display_driver pioled_shm_lock and pioled_go_flag .get_lock() calls
83
89
  PiOLED taillog command
@@ -87,7 +93,13 @@ V1.2 - Changes
87
93
  <br/>
88
94
 
89
95
  ## Revision history
90
- - 1.2 - Changes
96
+ - 1.2.1 260526
97
+ HTU21D dummy user reg reads for measurement reads stability
98
+ PCA9548 monitor_ch
99
+ ADC121C read_conversion_result force_address switch added
100
+ PiOLED tweaks
101
+ HTU21D init changed do_soft_reset > do_reset, consistent with SHT3x
102
+ - 1.2 260506
91
103
  PiOLED uses shared memory, changed from display_file - cjnfuncs 3.2 dependency
92
104
  PiOLED add toolname to pioled_display_driver pioled_shm_lock and pioled_go_flag .get_lock() calls
93
105
  PiOLED taillog command
@@ -55,7 +55,13 @@ If using the pigpio driver:
55
55
 
56
56
  ## Key changes since the prior major public release (1.1)
57
57
 
58
- V1.2 - Changes
58
+ V1.2.1 Changes
59
+ - HTU21D dummy user reg reads for measurement reads stability, init changed do_soft_reset > do_reset, consistent with SHT3x.
60
+ - PCA9548 monitor_ch feature
61
+ - 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
62
+
63
+
64
+ V1.2 Changes
59
65
  PiOLED uses shared memory, changed from display_file - cjnfuncs 3.2 dependency
60
66
  PiOLED add toolname to pioled_display_driver pioled_shm_lock and pioled_go_flag .get_lock() calls
61
67
  PiOLED taillog command
@@ -65,7 +71,13 @@ V1.2 - Changes
65
71
  <br/>
66
72
 
67
73
  ## Revision history
68
- - 1.2 - Changes
74
+ - 1.2.1 260526
75
+ HTU21D dummy user reg reads for measurement reads stability
76
+ PCA9548 monitor_ch
77
+ ADC121C read_conversion_result force_address switch added
78
+ PiOLED tweaks
79
+ HTU21D init changed do_soft_reset > do_reset, consistent with SHT3x
80
+ - 1.2 260506
69
81
  PiOLED uses shared memory, changed from display_file - cjnfuncs 3.2 dependency
70
82
  PiOLED add toolname to pioled_display_driver pioled_shm_lock and pioled_go_flag .get_lock() calls
71
83
  PiOLED taillog command
@@ -1,10 +1,18 @@
1
1
  [project]
2
2
  name = 'cjn_PiTools'
3
- version = "1.2"
3
+ version = "1.2.1"
4
+ # 1.2.1
5
+ # HTU21D dummy user reg reads for measurement reads stability
6
+ # PCA9548 monitor_ch
7
+ # ADC121C read_conversion_result force_address switch added
8
+ # PiOLED tweaks
9
+ # HTU21D init changed do_soft_reset > do_reset, consistent with SHT3x
10
+ # 1.2 release
4
11
  # PiOLED uses shared memory, changed from display_file - cjnfuncs 3.2 dependency
5
12
  # PiOLED add toolname to pioled_display_driver pioled_shm_lock and pioled_go_flag .get_lock() calls
6
13
  # PiOLED taillog command
7
14
  # Debug logging of MCP23008 set_register() and set_bits() values
15
+ # doc fixes
8
16
  # 1.1.1 - pyproject.toml cleanup, Added to keywords
9
17
  # 1.1 - Final cleanup, release
10
18
  # 1.0.1 - PiOLED startup display file access check debug
@@ -16,7 +24,7 @@ requires-python = ">=3.9"
16
24
  authors = [ {name = "Chris Nelson", email = "github@cjnaz.com"} ]
17
25
  license = "MIT"
18
26
  dependencies = [
19
- 'cjnfuncs >= 3.2',
27
+ 'cjnfuncs >= 3.2.1',
20
28
  'luma.oled',
21
29
  'pillow',
22
30
  'spidev',
@@ -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"Conversion result <{self.device_name}>: (0x{data[0]:0>2x} 0x{data[1]:0>2x}) = <{conv_result:5.3f}V>, Alert flag <{alert_flag}>")
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"VLow limit <{self.device_name}>: (0x{data[0]:0>2x} 0x{data[1]:0>2x}) = <{vlow_limit_value:5.3f}V>")
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"VHigh limit <{self.device_name}>: (0x{data[0]:0>2x} 0x{data[1]:0>2x}) = <{vhigh_limit_value:5.3f}V>")
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"vhyst value <{self.device_name}>: (0x{data[0]:0>2x} 0x{data[1]:0>2x}) = <{vhyst_value:5.3f}V>")
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"vmin value <{self.device_name}>: (0x{data[0]:0>2x} 0x{data[1]:0>2x}) = <{vmin_value:5.3f}V>")
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"vmax value <{self.device_name}>: (0x{data[0]:0>2x} 0x{data[1]:0>2x}) = <{vmax_value:5.3f}V>")
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, do_soft_reset=True) - HTU21D library for Raspberry Pi
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
- `do_soft_reset` (bool, default True)
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, do_soft_reset=True):
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(do_soft_reset, bool):
82
- raise ValueError (f"<{self.device_name}> do_soft_reset must be a bool. Received <{do_soft_reset}>")
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 do_soft_reset:
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
- `channel_enable_bit_map` (int)
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
- 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}>")
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 `channel_enable_bit_map`
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 `channel_enable_bit_map`
115
+ - The resolved value is also saved to the instance variable `channel_enable_bitmap`
104
116
 
105
117
 
106
118
  ### Returns
107
- - `channel_enable_bit_map` value on success
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
- channel_enable_bit_map = self._build_bit_map(write_value)
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{channel_enable_bit_map:0>8b}>, channels <{self._bit_map_to_channel_str(channel_enable_bit_map)}>")
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, channel_enable_bit_map)
121
- self.channel_enable_bit_map = channel_enable_bit_map
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 channel_enable_bit_map
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._bit_map_to_channel_str(current_ch_enable_mask)}>")
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 _build_bit_map (self, channel_value):
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 _bit_map_to_channel_str(self, bit_mask):
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'
@@ -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"\nPiOLED_go_flag is currently set? <{pioled_go_flag.is_locked()}>, last locked by: <{pioled_go_flag.get_lock_info()}>")
516
- print (f"\npioled_shm_lock is currently set? <{pioled_shm_lock.is_locked()}>, last locked by: <{pioled_shm_lock.get_lock_info()}>")
515
+ print (f"\nPiOLED_go_flag is currently set? <{pioled_go_flag.is_locked()}>, last locked by: <{pioled_go_flag.get_lock_info()}>")
516
+ print (f"\nPiOLED_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: PiOLED_go_flag is currently set? <{pioled_go_flag.is_locked()}>")
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: 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()}>")
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: pioled_shm_lock is currently locked? <{pioled_shm_lock.is_locked()}>")
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
- - If the device is not accessible at the time of instantiation then set `do_reset=False` and reset the device when available
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.1
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,7 +10,7 @@ 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
@@ -77,7 +77,13 @@ If using the pigpio driver:
77
77
 
78
78
  ## Key changes since the prior major public release (1.1)
79
79
 
80
- V1.2 - Changes
80
+ V1.2.1 Changes
81
+ - HTU21D dummy user reg reads for measurement reads stability, init changed do_soft_reset > do_reset, consistent with SHT3x.
82
+ - PCA9548 monitor_ch feature
83
+ - 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
84
+
85
+
86
+ V1.2 Changes
81
87
  PiOLED uses shared memory, changed from display_file - cjnfuncs 3.2 dependency
82
88
  PiOLED add toolname to pioled_display_driver pioled_shm_lock and pioled_go_flag .get_lock() calls
83
89
  PiOLED taillog command
@@ -87,7 +93,13 @@ V1.2 - Changes
87
93
  <br/>
88
94
 
89
95
  ## Revision history
90
- - 1.2 - Changes
96
+ - 1.2.1 260526
97
+ HTU21D dummy user reg reads for measurement reads stability
98
+ PCA9548 monitor_ch
99
+ ADC121C read_conversion_result force_address switch added
100
+ PiOLED tweaks
101
+ HTU21D init changed do_soft_reset > do_reset, consistent with SHT3x
102
+ - 1.2 260506
91
103
  PiOLED uses shared memory, changed from display_file - cjnfuncs 3.2 dependency
92
104
  PiOLED add toolname to pioled_display_driver pioled_shm_lock and pioled_go_flag .get_lock() calls
93
105
  PiOLED taillog command
@@ -1,4 +1,4 @@
1
- cjnfuncs>=3.2
1
+ cjnfuncs>=3.2.1
2
2
  luma.oled
3
3
  pillow
4
4
  spidev
File without changes
File without changes