Skip to content

Commit

Permalink
optimize device stat reporting content
Browse files Browse the repository at this point in the history
  • Loading branch information
ftylitak committed Sep 5, 2023
1 parent a6686af commit c0a293f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
16 changes: 6 additions & 10 deletions insighioNode/lib/device_info/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@

uos_version_data = uos.uname()
machine_data = uos_version_data.machine
firmware_data = uos_version_data.version.split(" ")[0].split("-")
firmware_data[0] = firmware_data[0][1:] # "from 'v1.18' to '1.18'"
firmware_data = uos_version_data.release.split(".")
firmware_commit_data = uos_version_data.version.split(" ")[0]

def is_esp32():
return sys.platform == 'esp32' or 'esp8266'
Expand Down Expand Up @@ -69,18 +69,14 @@ def get_firmware_version():
major = None
minor = None
patch = None
commit = None

major_minor = firmware_data[0].split(".")
commit = firmware_commit_data

try:
major = int(major_minor[0])
if len(major_minor) > 1:
minor = int(major_minor[1])
major = int(firmware_data[0])
if len(firmware_data) > 1:
patch = int(firmware_data[1])
minor = int(firmware_data[1])
if len(firmware_data) > 2:
commit = int(firmware_data[2])
patch = int(firmware_data[2])
except:
pass

Expand Down
26 changes: 18 additions & 8 deletions insighioNode/lib/gpio_handler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import device_info

from machine import ADC, Pin
(major_version, minor_version, _, _) = device_info.get_firmware_version()

import logging

Expand All @@ -18,15 +17,26 @@ def get_input_voltage(pin, voltage_divider=1, attn=ADC.ATTN_11DB, measurement_cy
adc_width = ADC.WIDTH_13BIT if device_info.supports_13bit_adc() else ADC.WIDTH_12BIT
adc.width(adc_width)

adc_initialized=False

try:
if major_version == 1 and minor_version < 18:
adc.init(attn, adc_width)
elif major_version == 1 and minor_version >= 18:
adc.init_mp(atten=ADC.ATTN_11DB)
return adc.read_voltage(_NUM_ADC_READINGS) * voltage_divider
adc.init_mp(atten=ADC.ATTN_11DB)
adc_initialized=True
except Exception as e:
logging.exception(e, "unable to read: pin: {}".format(pin))
pass
logging.exception(e, "unable to init: pin: {}".format(pin))

if not adc_initialized:
try:
adc.init(attn, adc_width)
adc_initialized=True
except Exception as e:
logging.exception(e, "unable to init: pin: {}")

if adc_initialized:
try:
return adc.read_voltage(_NUM_ADC_READINGS) * voltage_divider
except Exception as e:
logging.exception(e, "unable to read: pin: {}".format(pin))

logging.debug("fallback ADC without calibration")

Expand Down
1 change: 1 addition & 0 deletions insighioNode/lib/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import esp32
import uos

key_value_storage = esp32.NVS("insighio")

Expand Down

0 comments on commit c0a293f

Please sign in to comment.