-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix(mqtt) * feat(drivers) * feat(updates) * feat(relesae setup)
- Loading branch information
Showing
12 changed files
with
158 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from features.analog_accessor.analog_accessor import AnalogAccessor | ||
|
||
|
||
class AnalogDriver: | ||
def __init__(self, analog_accessor: AnalogAccessor, channel: int): | ||
self.analog_accessor = analog_accessor | ||
self.channel = channel | ||
self.min = 0 | ||
self.max = 65535 | ||
|
||
async def read_raw(self): | ||
return await self.analog_accessor.read(self.channel) | ||
|
||
async def read(self): | ||
return await self._read() | ||
|
||
async def _read(self): | ||
raw = await self.read_raw() | ||
|
||
if raw <= self.min: | ||
return 0 | ||
if raw >= self.max: | ||
return 100 | ||
|
||
calc = int(raw / self.max * 100) | ||
|
||
return min(100, max(0, calc)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from features.devices.drivers.adc_driver import AnalogDriver | ||
from math import log, e | ||
from machine import Pin, ADC | ||
from uasyncio import sleep_ms | ||
|
||
|
||
class InsolationDriver(AnalogDriver): | ||
def __init__(self, adc_pin: int): | ||
self.adc = ADC(Pin(adc_pin)) | ||
self.light = 1000 | ||
self.dark = 50000 | ||
|
||
async def read_raw(self): | ||
await sleep_ms(1) | ||
return self.adc.read_u16() | ||
|
||
async def _read(self): | ||
raw = await self.read_raw() | ||
|
||
if raw >= self.dark: | ||
return 0 | ||
if raw <= self.light: | ||
return 100 | ||
|
||
calc = int(276.295 - 24.188 * log(raw, e)) | ||
|
||
return min(100, max(0, calc)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from features.analog_accessor.analog_accessor import AnalogAccessor | ||
from features.devices.drivers.adc_driver import AnalogDriver | ||
from math import log, e | ||
|
||
|
||
class SMSDriver(AnalogDriver): | ||
def __init__(self, analog_accessor: AnalogAccessor, channel: int): | ||
super().__init__(analog_accessor, channel) | ||
self.wet = 26000 | ||
self.mid = 33000 | ||
self.dry = 63000 | ||
|
||
async def _read(self): | ||
raw = await self.read_raw() | ||
|
||
if raw >= self.dry: | ||
return 0 | ||
if raw <= self.wet: | ||
return 100 | ||
|
||
calc = int(1162.08 - 105.507 * log(raw, e)) | ||
|
||
return min(100, max(0, calc)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from features.analog_accessor.analog_accessor import AnalogAccessor | ||
from features.devices.drivers.adc_driver import AnalogDriver | ||
from math import log, e | ||
|
||
|
||
class GravityV1(AnalogDriver): | ||
def __init__(self, analog_accessor: AnalogAccessor, channel: int): | ||
super().__init__(analog_accessor, channel) | ||
self.wet = 23000 | ||
self.mid = 37000 | ||
self.dry = 50000 | ||
|
||
async def _read(self): | ||
raw = await self.read_raw() | ||
|
||
if raw >= self.dry: | ||
return 0 | ||
if raw <= self.wet: | ||
return 100 | ||
|
||
calc = int(1246.17 - 115.51 * log(raw, e)) | ||
|
||
return min(100, max(0, calc)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters