forked from enesbcs/rpieasy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_P069_LM75A.py
100 lines (93 loc) · 3.18 KB
/
_P069_LM75A.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env python3
#############################################################################
######################## LM75A plugin for RPIEasy ###########################
#############################################################################
#
# LM75 code added by haraldtux ( https://github.com/haraldtux )
#
# Copyright (C) 2019 by Alexander Nagy - https://bitekmindenhol.blog.hu/
#
import plugin
import webserver
import rpieGlobals
import rpieTime
import misc
import gpios
import smbus
import time
class Plugin(plugin.PluginProto):
PLUGIN_ID = 69
PLUGIN_NAME = "Environment - LM75A (TESTING)"
PLUGIN_VALUENAME1 = "Temperature"
def __init__(self,taskindex): # general init
plugin.PluginProto.__init__(self,taskindex)
self.dtype = rpieGlobals.DEVICE_TYPE_I2C
self.vtype = rpieGlobals.SENSOR_TYPE_SINGLE
self.readinprogress = 0
self.valuecount = 1
self.senddataoption = True
self.timeroption = True
self.timeroptional = False
self.formulaoption = True
self.bus = None
def plugin_init(self,enableplugin=None):
plugin.PluginProto.plugin_init(self,enableplugin)
self.uservar[0] = 0
self.bus = None
if self.enabled and int(self.taskdevicepluginconfig[0])>0:
try:
try:
i2cl = self.i2c
except:
i2cl = -1
self.bus = gpios.HWPorts.i2c_init(i2cl)
if i2cl==-1:
self.bus = gpios.HWPorts.i2cbus
if self.bus is not None:
if self.interval>2:
nextr = self.interval-2
else:
nextr = self.interval
self._lastdataservetime = rpieTime.millis()-(nextr*1000)
else:
misc.addLog(rpieGlobals.LOG_LEVEL_ERROR,"I2C can not be initialized!")
self.initialized = False
except Exception as e:
misc.addLog(rpieGlobals.LOG_LEVEL_ERROR,str(e))
self.initialized = False
def webform_load(self): # create html page for settings
choice1 = self.taskdevicepluginconfig[0]
options = ["0x48", "0x49", "0x4a", "0x4b", "0x4c","0x4d", "0x4e", "0x4f"]
optionvalues = [0x48, 0x49, 0x4a, 0x4b, 0x4c,0x4d, 0x4e, 0x4f]
webserver.addFormSelector("Address","plugin_069_addr",len(options),options,optionvalues,None,int(choice1))
webserver.addFormNote("Enable <a href='pinout'>I2C bus</a> first, than <a href='i2cscanner'>search for the used address</a>!")
return True
def webform_save(self,params): # process settings post reply
initpar = self.taskdevicepluginconfig[0]
par = webserver.arg("plugin_069_addr",params)
if par == "":
par = 0
self.taskdevicepluginconfig[0] = int(par)
if (initpar != self.taskdevicepluginconfig[0]) and (int(self.taskdevicepluginconfig[0])>0):
self.plugin_init()
return True
def plugin_read(self): # deal with data processing at specified time interval
result = False
if self.initialized and self.readinprogress==0 and self.enabled:
self.readinprogress = 1
atemp = self.read_lm75()
self.set_value(1,atemp,True)
self._lastdataservetime = rpieTime.millis()
result = True
self.readinprogress = 0
return result
def read_lm75(self):
temp = None
if self.bus is not None:
try:
raw = self.bus.read_word_data(int(self.taskdevicepluginconfig[0]), 0) & 0xFFFF
raw = ((raw << 8) & 0xFF00) + (raw >> 8)
temp = (raw / 32.0) / 8.0+ -1.3
except:
temp = None
return temp