Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,15 @@ Some utility methods are provided and are still in development:

## Convenience and scaffolding methods

### create_project(PROJECT_NAME, PATH)
### create_sketch(SKETCH_NAME, PATH)

Will create a new Python file (`.py`) with the specified name at the provided path.
Example:

```Python
create_project('my_arduino_sketch')
create_project('my_arduino_sketch', 'tmp')
create_project('main')
create_sketch('my_arduino_sketch')
create_sketch('my_arduino_sketch', 'tmp')
create_sketch('main')
```

If the destination `.py` file exists, a timestamp in _microseconds_ will be appended to the name.
Expand Down
14 changes: 8 additions & 6 deletions arduino/arduino.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,23 @@ def delay(_ms):


# HELPERS
def create_new_sketch(sketch_name = None, path = '.'):
def create_sketch(sketch_name = None, path = '.', overwrite = False):

if sketch_name is None:
sketch_name = 'main'
new_sketch_path = f'{path}/{sketch_name}.py'
try:
open(new_sketch_path, 'x')
open(new_sketch_path, 'r')
if not overwrite:
sketch_name = f'{sketch_name}_{ticks_us()}'
except OSError:
sketch_name = f'{sketch_name}_{ticks_us()}'
pass

if sketch_name is None:
sketch_name = f'main_{ticks_us()}.py'
template_path = '/'.join(__file__.split('/')[:-1]) + '/template.py'
template_sketch = open(template_path, 'r')
new_sketch_path = f'{path}/{sketch_name}.py'

with open(f'{path}/{sketch_name}.py', 'w') as f:
with open(new_sketch_path, 'w') as f:
sketch_line = None
while sketch_line is not '':
sketch_line = template_sketch.readline()
Expand Down