Skip to content

Commit

Permalink
Implement boardfile override in buildenv
Browse files Browse the repository at this point in the history
Makes it easier to have local modifications on the boardfile. (e.g.
custom LED's.
  • Loading branch information
SteffenKockel committed Oct 7, 2023
1 parent 8280fef commit f916fdc
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,18 @@ If `socat` is installed, a proxy will be started for every device that connectio
After installation the `pyduin` module can be imported.
```python
from pyduin import arduino
from pyduin import _utils as utils

board = 'nanoatmega328'
boardfile = utils.board_boardfile(board)

Arduino = arduino.Arduino(board=board,
tty='/dev/ttyUSB0',
boardfile=boardfile,
wait=True)
print(Arduino.firmware_version)
pin = Arduino.get_pin(13)
pin.set_mode('OUTPUT')
pin.high()
print(Arduino.free_memory)

```

## Command-line
Expand Down
2 changes: 1 addition & 1 deletion src/pyduin/arduino.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __init__(self, board=False, tty=False, baudrate=False, boardfile=False,
self.board = board
self.tty = tty
self.baudrate = baudrate
self._boardfile = boardfile or utils.board_boardfile(board)
self._boardfile = boardfile or utils.boardfile_for(board)
self.boardfile = False
self.ready = False
self.wait = wait
Expand Down
5 changes: 2 additions & 3 deletions src/pyduin/arduino_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def get_basic_config(args):
board = args.board or utils.get_buddy_cfg(cfg, args.buddy, 'board')

if board:
cfg['boardfile'] = args.boardfile or utils.board_boardfile(board)
cfg['boardfile'] = args.boardfile or utils.boardfile_for(board)
logger.debug("Using boardfile from: %s", cfg['boardfile'])
cfg['board'] = board
else:
Expand All @@ -78,8 +78,7 @@ def _get_arduino_config(args, config):
arduino_config['tty'] = arduino_config.get('tty', False)
arduino_config['baudrate'] = arduino_config.get('baudrate', False)
if not arduino_config.get('boardfile'):
boardfile = os.path.join(utils.boardfiledir, f'{arduino_config["board"]}.yml')
arduino_config['boardfile'] = boardfile
arduino_config['boardfile'] = config['boardfile']
logger.debug("device_config: %s", arduino_config)
config['_arduino_'] = arduino_config
model = config['_arduino_']['board']
Expand Down
18 changes: 17 additions & 1 deletion src/pyduin/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class PyduinUtils:
""" Wrapper for some useful functions. Exists, to be able to make
use of @propget decorator and ease handling on the usage side """

_configfile = os.path.expanduser('~/.pyduin.yml')
_workdir = os.path.expanduser('~/.pyduin')
@staticmethod
def logger():
""" Return the pyduin log facility
Expand All @@ -69,6 +71,17 @@ def boardfiledir(self):
""" Return the directory within the package, where the boardfiles resied """
return os.path.join(self.package_root, 'data', 'boardfiles')

@property
def configfile(self):
""" Return the default path to the users config file """
return self._configfile

@property
def workdir(self):
""" Return the directory where the build environments live """
return self._workdir


@property
def firmwaredir(self):
""" Return the directory within the package, where the firmware resides """
Expand Down Expand Up @@ -100,8 +113,11 @@ def platformio_ini(self):
""" Return the pull path to default platformio.ini """
return os.path.join(self.firmwaredir, 'platformio.ini')

def board_boardfile(self, board):
def boardfile_for(self, board):
""" Return the full path to a specific boardfile in the package """
# check for overrides in workdir
if os.path.isfile(os.path.join(self.workdir, board, f'{board}.yml')):
return os.path.join(self.workdir, board, f'{board}.yml')
return os.path.join(self.boardfiledir, f'{board}.yml')

@staticmethod
Expand Down

0 comments on commit f916fdc

Please sign in to comment.