Skip to content

Commit

Permalink
update typos + add pin command + add sent button
Browse files Browse the repository at this point in the history
  • Loading branch information
karelv committed Feb 2, 2024
1 parent fe2be32 commit 1638d8d
Show file tree
Hide file tree
Showing 14 changed files with 172 additions and 75 deletions.
10 changes: 10 additions & 0 deletions i2c-stick-arduino/context.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ boards:
port_discovery_method: arduino-cli
USB_PID: 0x0483
USB_VID: 0x16C0
- fqbn: teensy:avr:teensy40
disable: 0
name: Teensy 4.0
nick: teensy40
core: teensy:avr
bin_extension: hex
url: https://www.pjrc.com/store/teensy40.html
port_discovery_method: arduino-cli
USB_PID: 0x0483
USB_VID: 0x16C0
- fqbn: esp32:esp32:sparkfun_esp32c6_qwiic_pocket
disable: 1
name: Sparkfun ESP32-C6 QWIIC pocket
Expand Down
26 changes: 20 additions & 6 deletions i2c-stick-arduino/dodo.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@
# Arduino compiles all cpp files in the directory; rename to <ori>.disable
for driver in context['drivers']:
if driver['disable']:
files = list(Path(".").glob(driver['scr_name'] + "_*.cpp")) + list(Path(".").glob(driver['scr_name'] + "_*.h"))
files = list(Path(".").glob(driver['src_name'] + "_*.cpp")) + list(Path(".").glob(driver['src_name'] + "_*.h"))
for file in files:
shutil.move(file, str(file) + ".disable")

# undo: Arduino compiles all cpp files in the directory; rename to <ori>.disable
for driver in context['drivers']:
if driver['disable'] == 0:
files = list(Path(".").glob(driver['scr_name'] + "_*.disable"))
files = list(Path(".").glob(driver['src_name'] + "_*.disable"))
for file in files:
shutil.move(file, str(file).replace(".disable", ""))

Expand Down Expand Up @@ -105,6 +105,15 @@ def remove(path):
raise ValueError("path {} is not a file or dir.".format(p))


def find_git_repo(path):
"""Find repository root from the path's parents"""
for path in Path(path).parents:
# Check whether "path/.git" exists and is a directory
git_dir = path / ".git"
if git_dir.is_dir():
return path


def show_cmd(task):
msg = task.name
if task.verbosity >= 2:
Expand Down Expand Up @@ -541,14 +550,15 @@ def task_copy_plugins():
""" Copy the plugin's arduino source files to this arduino directory """
def do_copy(task):
# print(task.file_dep)
with open("../.git/info/exclude", "r") as ge:
exclude_file = os.path.join(find_git_repo(__file__), '.git', 'info', 'exclude')
with open(exclude_file, "r") as ge:
git_exclude = [x.strip() for x in ge.readlines()]

for src in task.file_dep:
destination = Path(src).name
if ("i2c-stick-arduino/" + destination) not in git_exclude:
git_exclude.append("i2c-stick-arduino/" + destination)
with open("../.git/info/exclude", "w") as ge:
with open(exclude_file, "w") as ge:
ge.write('\n'.join(git_exclude))

must_copy = 0
Expand Down Expand Up @@ -629,7 +639,7 @@ def do_add_driver(driver, src_name, function_id, sa_list):
with open(yaml_file, 'w') as output_f:
output_f.write(yaml.dump({
'name': driver,
'scr_name': src_name,
'src_name': src_name,
'function_id': function_id,
}))
output_f.write("\n")
Expand Down Expand Up @@ -679,9 +689,13 @@ def make_dist_dir():
if not Path("../dist").is_dir():
os.mkdir('../dist')

def do_copy():
shutil.copytree("build", "../dist", dirs_exist_ok=True)


return {
'actions': [(make_dist_dir,),
"cp -rfv build/* ../dist",
(do_copy, )
],
'verbosity': 2,
'task_dep': ['arduino-compile', ],
Expand Down
4 changes: 2 additions & 2 deletions i2c-stick-arduino/i2c-stick-arduino.ino
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ hal_write_pin(uint8_t pin, uint8_t state)


uint8_t
hal_read_pin(uint8_t pin)
hal_read_pin(uint8_t pin, uint8_t pullup)
{
pinMode(pin, INPUT);
pinMode(pin, pullup ? INPUT_PULLUP : INPUT);
return digitalRead(pin);
}

Expand Down
48 changes: 47 additions & 1 deletion i2c-stick-arduino/i2c_stick_cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ handle_cmd(uint8_t channel_mask, const char *cmd)
send_answer_chunk(channel_mask, "mlx:MELEXIS I2C STICK", 1);
send_answer_chunk(channel_mask, "mlx:=================", 1);
send_answer_chunk(channel_mask, "mlx:", 1);
send_answer_chunk(channel_mask, "mlx:Melexis Inspired Engineering", 1);
send_answer_chunk(channel_mask, "mlx:Melexis Innovation with Heart", 1);
send_answer_chunk(channel_mask, "mlx:", 1);
send_answer_chunk(channel_mask, "mlx:hit '?' for help", 1);
return NULL;
Expand Down Expand Up @@ -704,6 +704,52 @@ handle_cmd(uint8_t channel_mask, const char *cmd)
return NULL;
}

this_cmd = "pin"; // Pin command
if (!strncmp(this_cmd, cmd, strlen(this_cmd)))
{
int16_t pin_no = -1;
if (cmd[strlen(this_cmd)] == ':')
{
const char *p = cmd+strlen(this_cmd)+1;
if (('0' <= *p) && (*p <= '9'))
{
pin_no = atoi(p);
}
}
if (pin_no >= 0)
{
const char *p = strchr(cmd+strlen(this_cmd)+1, ':');
int16_t value = -1;
if (p)
{
value = atoi(p+1);
} else
{
value = hal_read_pin(pin_no, strchr(cmd+strlen(this_cmd)+1, '+') ? 1 : 0);
char buf[32];
sprintf(buf, ":%d:read:%d", pin_no, value);
send_answer_chunk(channel_mask, this_cmd, 0);
send_answer_chunk(channel_mask, buf, 1);
return NULL;
}
if ((value == 0) || (value == 1))
{
hal_write_pin(pin_no, value);
send_answer_chunk(channel_mask, this_cmd, 0);
send_answer_chunk(channel_mask, ":OK", 1);
} else
{
send_answer_chunk(channel_mask, this_cmd, 0);
send_answer_chunk(channel_mask, ":FAIL:Invalid pin value", 1);
}
} else
{
send_answer_chunk(channel_mask, this_cmd, 0);
send_answer_chunk(channel_mask, ":FAIL:pwm invalid pin_num", 1);
}
return NULL;
}

this_cmd = "nd"; // New Data command
if (!strncmp(this_cmd, cmd, strlen(this_cmd)))
{
Expand Down
2 changes: 1 addition & 1 deletion i2c-stick-arduino/i2c_stick_dispatcher.cpp.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

// Include all the drivers cmd header files:
{%- for driver in drivers %}
#include "{{driver.scr_name}}_cmd.h"
#include "{{driver.src_name}}_cmd.h"
{%- endfor %}

#include <string.h>
Expand Down
2 changes: 1 addition & 1 deletion i2c-stick-arduino/i2c_stick_hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ int16_t hal_i2c_direct_write(uint8_t sa, uint8_t *write_buffer, uint16_t write_n
int16_t hal_i2c_indirect_read(uint8_t sa, uint8_t *write_buffer, uint16_t write_n_bytes, uint8_t *read_buffer, uint16_t read_n_bytes);

void hal_write_pin(uint8_t pin, uint8_t state);
uint8_t hal_read_pin(uint8_t pin);
uint8_t hal_read_pin(uint8_t pin, uint8_t pullup = false);

void hal_i2c_set_pwm(uint8_t pin_no, uint8_t pwm);

Expand Down
2 changes: 1 addition & 1 deletion i2c-stick-arduino/mlx90614_driver.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
function_id: '90614'
name: MLX90614
scr_name: mlx90614
src_name: mlx90614
2 changes: 1 addition & 1 deletion i2c-stick-arduino/mlx90632_driver.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
function_id: '90632'
name: MLX90632
scr_name: mlx90632
src_name: mlx90632
2 changes: 1 addition & 1 deletion i2c-stick-arduino/mlx90640_driver.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
function_id: '90640'
name: MLX90640
scr_name: mlx90640
src_name: mlx90640
2 changes: 1 addition & 1 deletion i2c-stick-arduino/mlx90641_driver.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
function_id: '90641'
name: MLX90641
scr_name: mlx90641
src_name: mlx90641
11 changes: 11 additions & 0 deletions i2c-stick-py/melexis/i2c_stick/I2CStick.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,17 @@ def pwm(self, pin, pwm):
a = self.run_cmd("pwm:{}:{}".format(pin, pwm))
return a

def pinvalue(self, pin, val): # alias for pin
return self.pin(pin, val)

def pin(self, pin, val=None):
"""set or get a pin of the I2C-stick"""
if val is None:
return self.run_cmd("pin:{}".format(pin))
if val == 'pullup':
return self.run_cmd("pin:{}+".format(pin))
return self.run_cmd("pin:{}:{}".format(pin, val))


if __name__ == '__main__':
mis = I2CStick("COM154")
Expand Down
9 changes: 6 additions & 3 deletions web-interface/dodo.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,19 +524,22 @@ def task_dist():
"robots.txt",
"sitemap.txt",
]
files = " ".join(file_dep)

def make_dist_dir():
if not Path("../dist").is_dir():
os.mkdir('../dist')

def do_copy(task):
shutil.copytree("assets", "../dist/assets", dirs_exist_ok=True)
for file in task.file_dep:
shutil.copy(file, f"../dist/{file}")

return {
'actions': [(make_dist_dir,),
f"cp -frv {files} assets ../dist",
(do_copy, )
],
'file_dep': file_dep,
'uptodate': [False],
'title': show_cmd,
'verbosity': 2,
}

Expand Down
12 changes: 9 additions & 3 deletions web-interface/index.jinja2.html
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,14 @@
<section id="serial_terminal" style="height: 100%; overflow: auto;">
</section>
</main>
<input type="text" class="input is-primary" id="serial_send" name="serial_send" style="width:100%;margin-top: 5px;" placeholder="Enter here the command to sent and press <ENTER>" />
<div class="field has-addons" style="width:100%;margin-top: 5px;">
<div class="control is-expanded">
<input type="text" class="input is-primary is-11" id="serial_send" name="serial_send" placeholder="Enter here the command to sent and press <ENTER>" />
</div>
<p class="control">
<a title="Sent" class="button is-primary btn_sent">Sent</a>
</p>
</div>
</div>
<div class="column is-4">

Expand Down Expand Up @@ -290,5 +297,4 @@ <h1>MY CONTENT</h1>
<script type="text/javascript" src="./assets/site/jquery-3.6.1.min.js"></script>
<script type="text/javascript" src="./assets/site/chart.min.js"></script>
<script type="text/javascript" src="./interface.min.js"></script>

</html>
</html>
Loading

0 comments on commit 1638d8d

Please sign in to comment.