Skip to content

Commit

Permalink
Merge ec4c79d into cd13e50
Browse files Browse the repository at this point in the history
  • Loading branch information
brainelectronics authored May 14, 2023
2 parents cd13e50 + ec4c79d commit e8b49ef
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 47 deletions.
1 change: 1 addition & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ exclude =
libs_external
sdist_upip.py
setup.py
nextion/ulogging.py

# Provide a comma-separated list of glob patterns to add to the list of excluded ones.
# extend-exclude =
Expand Down
24 changes: 0 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,30 +136,6 @@ cp examples/basic/main.py /pyboard
cp examples/boot.py /pyboard
```

### Install additional MicroPython packages

To use this package with the provided [`boot.py`](examples/boot.py) and one of
the `main.py` files of an [example subfolder](examples/), the additional
module `ulogging` is required.

Either install the required package(s) using `upip` as follows after
connecting to a WiFi network:

```python
# network connection already established

import upip
upip.install('micropython-ulogging')
```

or copy it manually to the MicroPython board using e.g. `rshell`:

```bash
mkdir /pyboard/lib

cp -r libs_external/* /pyboard/lib
```

## Usage

Use one of the [examples](examples/) to get started. Read also the
Expand Down
8 changes: 7 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ r"^\#\# \[\d{1,}[.]\d{1,}[.]\d{1,}\] \- \d{4}\-\d{2}-\d{2}$"
-->

## Released
## [0.15.1] - 2023-05-14
### Fixed
- Remove yet unavailable files from `package.json`, see #33
- Add `ulogging` module to package to remove all external dependencies

## [0.15.0] - 2023-05-13
### Added
- `package.json` for `mip` installation with MicroPython v1.19.1 or newer, see #27
Expand Down Expand Up @@ -215,8 +220,9 @@ r"^\#\# \[\d{1,}[.]\d{1,}[.]\d{1,}\] \- \d{4}\-\d{2}-\d{2}$"
- [Example HMI file](examples/everything.HMI) to be used for all examples

<!-- Links -->
[Unreleased]: https://github.com/brainelectronics/micropython-nextion/compare/0.15.0...develop
[Unreleased]: https://github.com/brainelectronics/micropython-nextion/compare/0.15.1...develop

[0.15.1]: https://github.com/brainelectronics/micropython-nextion/tree/0.15.1
[0.15.0]: https://github.com/brainelectronics/micropython-nextion/tree/0.15.0
[0.14.0]: https://github.com/brainelectronics/micropython-nextion/tree/0.14.0
[0.13.0]: https://github.com/brainelectronics/micropython-nextion/tree/0.13.0
Expand Down
2 changes: 1 addition & 1 deletion nextion/nextion_hardware.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
# system packages
from machine import UART
from time import ticks_diff, ticks_ms
import ulogging as logging

# custom packages
from .typing import Optional
from . import const as Const
from . import ulogging as logging


class NexHardwareError(Exception):
Expand Down
94 changes: 94 additions & 0 deletions nextion/ulogging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import sys

CRITICAL = 50
ERROR = 40
WARNING = 30
INFO = 20
DEBUG = 10
NOTSET = 0

_level_dict = {
CRITICAL: "CRIT",
ERROR: "ERROR",
WARNING: "WARN",
INFO: "INFO",
DEBUG: "DEBUG",
}

_stream = sys.stderr

class Logger:

level = NOTSET

def __init__(self, name):
self.name = name

def _level_str(self, level):
l = _level_dict.get(level)
if l is not None:
return l
return "LVL%s" % level

def setLevel(self, level):
self.level = level

def isEnabledFor(self, level):
return level >= (self.level or _level)

def log(self, level, msg, *args):
if level >= (self.level or _level):
_stream.write("%s:%s:" % (self._level_str(level), self.name))
if not args:
print(msg, file=_stream)
else:
print(msg % args, file=_stream)

def debug(self, msg, *args):
self.log(DEBUG, msg, *args)

def info(self, msg, *args):
self.log(INFO, msg, *args)

def warning(self, msg, *args):
self.log(WARNING, msg, *args)

def error(self, msg, *args):
self.log(ERROR, msg, *args)

def critical(self, msg, *args):
self.log(CRITICAL, msg, *args)

def exc(self, e, msg, *args):
self.log(ERROR, msg, *args)
sys.print_exception(e, _stream)

def exception(self, msg, *args):
self.exc(sys.exc_info()[1], msg, *args)


_level = INFO
_loggers = {}

def getLogger(name):
if name in _loggers:
return _loggers[name]
l = Logger(name)
_loggers[name] = l
return l

def info(msg, *args):
getLogger(None).info(msg, *args)

def debug(msg, *args):
getLogger(None).debug(msg, *args)

def basicConfig(level=INFO, filename=None, stream=None, format=None):
global _level, _stream
_level = level
if stream:
_stream = stream
if filename is not None:
print("logging.basicConfig: filename arg is not supported")
if format is not None:
print("logging.basicConfig: format arg is not supported")
26 changes: 6 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@
"nextion/nextion_checkbox.py",
"github:brainelectronics/micropython-nextion/nextion/nextion_checkbox.py"
],
[
"nextion/nextion_crop.py",
"github:brainelectronics/micropython-nextion/nextion/nextion_crop.py"
],
[
"nextion/nextion_dual_state_button.py",
"github:brainelectronics/micropython-nextion/nextion/nextion_dual_state_button.py"
Expand All @@ -48,10 +44,6 @@
"nextion/nextion_page.py",
"github:brainelectronics/micropython-nextion/nextion/nextion_page.py"
],
[
"nextion/nextion_picture.py",
"github:brainelectronics/micropython-nextion/nextion/nextion_picture.py"
],
[
"nextion/nextion_progressbar.py",
"github:brainelectronics/micropython-nextion/nextion/nextion_progressbar.py"
Expand All @@ -64,10 +56,6 @@
"nextion/nextion_rtc.py",
"github:brainelectronics/micropython-nextion/nextion/nextion_rtc.py"
],
[
"nextion/nextion_scrolltext.py",
"github:brainelectronics/micropython-nextion/nextion/nextion_scrolltext.py"
],
[
"nextion/nextion_slider.py",
"github:brainelectronics/micropython-nextion/nextion/nextion_slider.py"
Expand All @@ -76,10 +64,6 @@
"nextion/nextion_text.py",
"github:brainelectronics/micropython-nextion/nextion/nextion_text.py"
],
[
"nextion/nextion_timer.py",
"github:brainelectronics/micropython-nextion/nextion/nextion_timer.py"
],
[
"nextion/nextion_upload.py",
"github:brainelectronics/micropython-nextion/nextion/nextion_upload.py"
Expand All @@ -96,13 +80,15 @@
"nextion/typing.py",
"github:brainelectronics/micropython-nextion/nextion/typing.py"
],
[
"nextion/ulogging.py",
"github:brainelectronics/micropython-nextion/nextion/ulogging.py"
],
[
"nextion/version.py",
"github:brainelectronics/micropython-nextion/nextion/version.py"
]
],
"deps": [
"micropython-ulogging"
],
"version": "0.15.0"
"deps": [],
"version": "0.15.1"
}
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@
license='MIT',
cmdclass={'sdist': sdist_upip.sdist},
packages=['nextion'],
install_requires=['micropython-ulogging']
install_requires=[]
)

0 comments on commit e8b49ef

Please sign in to comment.