Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

request to add Adafruit NeoKey 1x4 input board #1353

Open
Nithalik opened this issue Dec 10, 2023 · 70 comments
Open

request to add Adafruit NeoKey 1x4 input board #1353

Nithalik opened this issue Dec 10, 2023 · 70 comments
Labels
enhancement Implemented Implemented but may not be thoroughly tested

Comments

@Nithalik
Copy link

Nithalik commented Dec 10, 2023

Hi Kyle,

Found a device from adafruit that would be able to add a lot of possible functionality for people not super skilled in programming if you can add this input device. It is basically a i2c controlled mini keyboard that has 4 keyboard keys and 4 neopixels. basically a easy way to add 4 i2c controlled momentary switches to a system. It also has 8 possible i2c addresses so there is a lot of possibility here

https://www.adafruit.com/product/4980

adafruit neokey library: https://docs.circuitpython.org/projects/neokey/en/latest/

i have ordered one and been playing with it, have gotten their test code working, but getting it to work with mycodo is not working for me, with you already having neopixels added not sure if this would be complicated to sort out

@kizniche
Copy link
Owner

How were you envisioning it integrating?

@Nithalik
Copy link
Author

Nithalik commented Dec 10, 2023

im wanting to use the switches to start functions, and change what is displayed on a different i2c screen. neopixels are just a added bonus, they could be used as status led's or to show that the button was pressed and recognized

you can also have 8 of these together, so 32 total keys from one i2c bus

like be able to have a button to trigger some of the input actions on this page https://kizniche.github.io/Mycodo/Inputs/#input-actions

the more useful ones would be to trigger the supported actions which is where i would use it the most

https://kizniche.github.io/Mycodo/Supported-Actions/

button to capture a pic from all the cameras / execute command: shell / display backlight / pause would be the big ones i can think of right away.

im not currently able to access my mycodo system so not able to really go through all the different sections to see where it is useful, but i envision using it so i dont have to go into the webui when i do maintenance, i can do it by buttons.

-pause/enable everything
-run waterchange function
-pH balance / add nutrients
-turn off main lights (or dim)

@kizniche
Copy link
Owner

kizniche commented Dec 10, 2023

I could throw together a simple function that you could execute one or more actions when a button is pressed.

@Nithalik
Copy link
Author

Nithalik commented Dec 10, 2023

that would work for almost all of my use cases, and i think i can add a lot with that. the only other thing is if there would be a way to address the neoled's too.

also need to be able to change the i2c address, will probably end up using more then 1

example for 1 button - when button is pressed, runs action, then flashes the neoled while that is active. and push the button again to undo if its not one based on a timer.

@kizniche
Copy link
Owner

All three sound doable. I'll let you know when I have a module for you to test.

@Nithalik
Copy link
Author

All three sound doable. I'll let you know when I have a module for you to test.

cool, thanks

@kizniche
Copy link
Owner

Attached below is a module to test. Rename from txt to py and import as a Function. You will also need to upgrade to master to be able to use Actions for Custom Functions and see the Action ID needed to use the new Function. The instructions after creating the Function should be sufficient to use it. I won't detail how to use it to see if the instructions can stand on their own. Let me know if you run into any issues or can't get it working. Remember to enable the Function debug logging when testing to see all debug messages in the log.

function_adafruit_neokey_01.txt

@Nithalik
Copy link
Author

Nithalik commented Dec 10, 2023

Thank you for that, got it installed.

when i push a button it just lights up the LED underneath but nothing else. below is the error log.

just have all buttons mapped to deactivate a function for testing.

image

your assistance here is greatly appreciated

``` AttributeError: 'list' object has no attribute 'unique_id'
2023-12-10 15:31:46,916 - ERROR - mycodo.function.function_adafruit_neokey_01_8df033ec - Executing Action with ID dd3d8ad0
Traceback (most recent call last):
  File "/home/nithalik/Mycodo/mycodo/functions/custom_functions/function_adafruit_neokey_01.py", line 236, in check_key_press
    action.unique_id,
AttributeError: 'list' object has no attribute 'unique_id'
2023-12-10 15:31:46,928 - INFO - mycodo.function.function_adafruit_neokey_01_8df033ec - Button 4
2023-12-10 15:31:47,461 - ERROR - mycodo.function.function_adafruit_neokey_01_8df033ec - Executing Action with ID 8ceb33e8
Traceback (most recent call last):
  File "/home/nithalik/Mycodo/mycodo/functions/custom_functions/function_adafruit_neokey_01.py", line 236, in check_key_press
    action.unique_id,
AttributeError: 'list' object has no attribute 'unique_id'
2023-12-10 15:31:47,473 - ERROR - mycodo.function.function_adafruit_neokey_01_8df033ec - Executing Action with ID d05c3d60
Traceback (most recent call last):
  File "/home/nithalik/Mycodo/mycodo/functions/custom_functions/function_adafruit_neokey_01.py", line 236, in check_key_press
    action.unique_id,
AttributeError: 'list' object has no attribute 'unique_id'
2023-12-10 15:31:47,486 - ERROR - mycodo.function.function_adafruit_neokey_01_8df033ec - Executing Action with ID dd3d8ad0
Traceback (most recent call last):
  File "/home/nithalik/Mycodo/mycodo/functions/custom_functions/function_adafruit_neokey_01.py", line 236, in check_key_press
    action.unique_id,
AttributeError: 'list' object has no attribute 'unique_id'

@kizniche
Copy link
Owner

Here is an updated module. Delete all of this Function type, then delete the Function module, then import this new Function module.

function_adafruit_neokey_01.txt

@kizniche
Copy link
Owner

kizniche commented Dec 10, 2023

Wait, you didn't add the correct Function. That's one of the built-in functions. Your screenshot is of the Execute Actions Function, not the Device: Adafruit Neokey (Button Executes Actions) Function.

@Nithalik
Copy link
Author

the screenshot was just the execute actions, to show the id's

in changing the settings in it, now the method page wont load giving 500 error. i must have done something stupid. reinstalling mycodo and will test out the new file

Error (Full Traceback):

Traceback (most recent call last):
File "/var/mycodo-root/env/lib/python3.9/site-packages/flask/app.py", line 2190, in wsgi_app
response = self.full_dispatch_request()
File "/var/mycodo-root/env/lib/python3.9/site-packages/flask/app.py", line 1486, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/var/mycodo-root/env/lib/python3.9/site-packages/flask_restx/api.py", line 674, in error_router
return original_handler(e)
File "/var/mycodo-root/env/lib/python3.9/site-packages/flask/app.py", line 1484, in full_dispatch_request
rv = self.dispatch_request()
File "/var/mycodo-root/env/lib/python3.9/site-packages/flask/app.py", line 1469, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
File "/var/mycodo-root/env/lib/python3.9/site-packages/flask_login/utils.py", line 290, in decorated_view
return current_app.ensure_sync(func)(*args, **kwargs)
File "/home/nithalik/Mycodo/mycodo/mycodo_flask/routes_function.py", line 514, in page_function
return render_template('pages/function.html',
File "/var/mycodo-root/env/lib/python3.9/site-packages/flask/templating.py", line 151, in render_template
return _render(app, template, context)
File "/var/mycodo-root/env/lib/python3.9/site-packages/flask/templating.py", line 132, in _render
rv = template.render(context)
File "/var/mycodo-root/env/lib/python3.9/site-packages/jinja2/environment.py", line 1301, in render
self.environment.handle_exception()
File "/var/mycodo-root/env/lib/python3.9/site-packages/jinja2/environment.py", line 936, in handle_exception
raise rewrite_traceback_stack(source=source)
File "/home/nithalik/Mycodo/mycodo/mycodo_flask/templates/pages/function.html", line 3, in top-level template code
{% set help_page = ["https://kizniche.github.io/Mycodo/Functions/", dict_translation['function']['title']] %}
File "/home/nithalik/Mycodo/mycodo/mycodo_flask/templates/layout.html", line 383, in top-level template code
{%- block body %}{% endblock -%}
File "/home/nithalik/Mycodo/mycodo/mycodo_flask/templates/pages/function.html", line 135, in block 'body'
{% include 'pages/function_options/custom_function_entry.html' %}
File "/home/nithalik/Mycodo/mycodo/mycodo_flask/templates/pages/function_options/custom_function_entry.html", line 51, in top-level template code
{% include 'pages/function_options/custom_function_options.html' %}
File "/home/nithalik/Mycodo/mycodo/mycodo_flask/templates/pages/function_options/custom_function_options.html", line 292, in top-level template code
{% include 'pages/actions.html' %}
File "/home/nithalik/Mycodo/mycodo/mycodo_flask/templates/pages/actions.html", line 40, in top-level template code
{% include 'pages/form_options/Custom_Options.html' %}
File "/home/nithalik/Mycodo/mycodo/mycodo_flask/templates/pages/form_options/Custom_Options.html", line 285, in top-level template code
<option value="{{each_dev.unique_id}}"{% if (channel_options and each_dev.unique_id == custom_options_values[unique_id][channel][each_option['id']]) or (custom_options_values and each_dev.unique_id == custom_options_values[unique_id][each_option['id']]) %} selected{% endif %}>[{{name}} {{'%02d' % each_dev.id}}] {{each_dev.name}}
File "/var/mycodo-root/env/lib/python3.9/site-packages/jinja2/environment.py", line 466, in getitem
return obj[argument]
jinja2.exceptions.UndefinedError: dict object has no element Undefined

@kizniche
Copy link
Owner

kizniche commented Dec 10, 2023

The IDs should show on all Functions. You should be only using the Function I created.

@kizniche
Copy link
Owner

kizniche commented Dec 10, 2023

What did you do in the time between it working and not working?

@Nithalik
Copy link
Author

all i did was change the ID's in the new module to random numbers, thinking that using the id's from the execute actions function was causing the issue

@Nithalik
Copy link
Author

Nithalik commented Dec 10, 2023

i was just showing with that screenshot that i didnt make a error copying the action id's into the boxes in the new module

@kizniche
Copy link
Owner

It would be most beneficial if you can give steps to reproduce any errors you get. If you found an error that crashes the frontend, that is a major issue.

@Nithalik
Copy link
Author

It would be most beneficial if you can give steps to reproduce any errors you get. If you found an error that crashes the frontend, that is a major issue.

i am working on trying to reproduce it now, as i could not load the method page, not much i could do other then reinstall. which i am doing now. if i can reproduce it, i will provide steps

all i did, was change the ids in the new module, not sure how that changed other things.

@Nithalik
Copy link
Author

Nithalik commented Dec 11, 2023

pretty sure i see what causes it, fresh install, installed the new module, and clicked on add action in the module itself, after adding a module to deactivate a controller in the action itself it gave the 500 error when i went to load the main functions page

/Error (Full Traceback):

Traceback (most recent call last):
File "/var/mycodo-root/env/lib/python3.9/site-packages/flask/app.py", line 2190, in wsgi_app
response = self.full_dispatch_request()
File "/var/mycodo-root/env/lib/python3.9/site-packages/flask/app.py", line 1486, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/var/mycodo-root/env/lib/python3.9/site-packages/flask_restx/api.py", line 674, in error_router
return original_handler(e)
File "/var/mycodo-root/env/lib/python3.9/site-packages/flask/app.py", line 1484, in full_dispatch_request
rv = self.dispatch_request()
File "/var/mycodo-root/env/lib/python3.9/site-packages/flask/app.py", line 1469, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
File "/var/mycodo-root/env/lib/python3.9/site-packages/flask_login/utils.py", line 290, in decorated_view
return current_app.ensure_sync(func)(*args, **kwargs)
File "/home/nithalik/Mycodo/mycodo/mycodo_flask/routes_function.py", line 514, in page_function
return render_template('pages/function.html',
File "/var/mycodo-root/env/lib/python3.9/site-packages/flask/templating.py", line 151, in render_template
return _render(app, template, context)
File "/var/mycodo-root/env/lib/python3.9/site-packages/flask/templating.py", line 132, in _render
rv = template.render(context)
File "/var/mycodo-root/env/lib/python3.9/site-packages/jinja2/environment.py", line 1301, in render
self.environment.handle_exception()
File "/var/mycodo-root/env/lib/python3.9/site-packages/jinja2/environment.py", line 936, in handle_exception
raise rewrite_traceback_stack(source=source)
File "/home/nithalik/Mycodo/mycodo/mycodo_flask/templates/pages/function.html", line 3, in top-level template code
{% set help_page = ["https://kizniche.github.io/Mycodo/Functions/", dict_translation['function']['title']] %}
File "/home/nithalik/Mycodo/mycodo/mycodo_flask/templates/layout.html", line 383, in top-level template code
{%- block body %}{% endblock -%}
File "/home/nithalik/Mycodo/mycodo/mycodo_flask/templates/pages/function.html", line 135, in block 'body'
{% include 'pages/function_options/custom_function_entry.html' %}
File "/home/nithalik/Mycodo/mycodo/mycodo_flask/templates/pages/function_options/custom_function_entry.html", line 51, in top-level template code
{% include 'pages/function_options/custom_function_options.html' %}
File "/home/nithalik/Mycodo/mycodo/mycodo_flask/templates/pages/function_options/custom_function_options.html", line 292, in top-level template code
{% include 'pages/actions.html' %}
File "/home/nithalik/Mycodo/mycodo/mycodo_flask/templates/pages/actions.html", line 40, in top-level template code
{% include 'pages/form_options/Custom_Options.html' %}
File "/home/nithalik/Mycodo/mycodo/mycodo_flask/templates/pages/form_options/Custom_Options.html", line 285, in top-level template code
<option value="{{each_dev.unique_id}}"{% if (channel_options and each_dev.unique_id == custom_options_values[unique_id][channel][each_option['id']]) or (custom_options_values and each_dev.unique_id == custom_options_values[unique_id][each_option['id']]) %} selected{% endif %}>[{{name}} {{'%02d' % each_dev.id}}] {{each_dev.name}}
File "/var/mycodo-root/env/lib/python3.9/site-packages/jinja2/environment.py", line 466, in getitem
return obj[argument]
jinja2.exceptions.UndefinedError: dict object has no element Undefined

@Nithalik
Copy link
Author

Nithalik commented Dec 11, 2023

Got it somewhat working.

new mycodo system.
image

all the activate and deactivate does is turn on or off the ph and ec regulation.

the buttons work to turn it on and off. the only issue is, when using the deactivate action, the led never turns off. when using activate the led turns on for 1 second. if there is no action tied to a button it also turns on the LED and it does not turn off on any future button presses.

looks like the behaviour when deactivating a controller is leaving the led on, maybe because it just sees the controller deactivated so its duration never ends? if i go and turn on the controller the led does not turn off

I think the best use for the LED's on this board, is to only have them light up when the corresponding buttons actions are being ran, or for a set time after the last action happens.

image

logs look good now

023-12-10 16:19:07,905 - INFO - mycodo.function.function_adafruit_neokey_01_38392045 - Button 2
2023-12-10 16:19:08,651 - DEBUG - mycodo.function.function_adafruit_neokey_01_38392045 - Return message: Deactivate Controller e4a02994-af6c-49d0-bb9b-619e49782034 (Regulate pH and Electrical Conductivity).
2023-12-10 16:19:08,945 - INFO - mycodo.controllers.controller_function_e4a02994 - Deactivated in 196.5 ms
2023-12-10 16:19:13,649 - INFO - mycodo.controllers.controller_function_e4a02994 - Activated in 352.2 ms
2023-12-10 16:19:15,049 - INFO - mycodo.function.function_adafruit_neokey_01_38392045 - Button 2
2023-12-10 16:19:15,736 - DEBUG - mycodo.function.function_adafruit_neokey_01_38392045 - Return message: Deactivate Controller e4a02994-af6c-49d0-bb9b-619e49782034 (Regulate pH and Electrical Conductivity).
2023-12-10 16:19:15,908 - INFO - mycodo.controllers.controller_function_e4a02994 - Deactivated in 68.5 ms
2023-12-10 16:19:17,740 - ERROR - mycodo - Function controller with ID e4a02994-af6c-49d0-bb9b-619e49782034 not found
2023-12-10 16:19:21,248 - INFO - mycodo.function.function_adafruit_neokey_01_38392045 - Button 1
2023-12-10 16:19:21,977 - DEBUG - mycodo.function.function_adafruit_neokey_01_38392045 - Return message: Activate Controller e4a02994-af6c-49d0-bb9b-619e49782034 (Regulate pH and Electrical Conductivity).
2023-12-10 16:19:22,660 - INFO - mycodo.controllers.controller_function_e4a02994 - Activated in 571.2 ms

Found bug reproduction steps:

add neokey function

add controller:deactivate under measurement settings

image

do not need to add anything specific under, just save as blank and then try to load the functions page and you get 500 error.

i think the fix for this is just removing the measurement settings area as it is not needed for the neokey function, i was only playing with it at first as part of my troubleshooting

@kizniche
Copy link
Owner

I was able to replicate the error. Looking into a fix.

@kizniche
Copy link
Owner

kizniche commented Dec 11, 2023

Fixed the error. You'll need to upgrade to master to get that fix. And to fix the LED on all but the first button not working, change the last line of the module from:

self.neokey.pixels[0] = 0x0

to

self.neokey.pixels[key] = 0x0

The current behavior is to only have the LED on when the actions are executing. You are likely choosing short-lived actions, why the LED goes off quickly.

@Nithalik
Copy link
Author

all working now, and the code change worked.

there are cases where having it be enabled for total duration would be helpful, would it be difficult to be able to select per key if it is pixels[0] to pixels[key]

@kizniche
Copy link
Owner

kizniche commented Dec 11, 2023

What do you mean by enabled for total duration? The LED stays on for as long as it takes the Actions to complete.

I also just majorly refactored the Function Module to utilize another method for organizing configuration data so it's easier to work with in the code. And added a delay to keep the LED on after all actions have completed. I also made the key press spawn a thread to complete the actions, so you can now have multiple key action sets running at the same time and you don't have to wait for the first to finish before starting the next.

function_adafruit_neokey_01.txt

@Nithalik
Copy link
Author

Nithalik commented Dec 11, 2023

Your screenshot does not look correct. Your Function is missing all options to set for each key.

i did upgrade to master. the screentshot was just of the execute actions of the functions i was going to use, to show the id's

What do you mean by enabled for total duration? The LED stays on for as long as it takes the Actions to complete.

I also just majorly refactored the Function Module to utilize another method for organizing configuration data so it's easier to work with in the code. And added a delay to keep the LED on after all actions have completed. I also made the key press spawn a thread to complete the actions, so you can now have multiple key action sets running at the same time and you don't have to wait for the first to finish before starting the next.

function_adafruit_neokey_01.txt

i just misunderstood the code change. what you did is perfect, the new changes make it very clear what is happening. I would say it is complete for at least my needs now.

Thank you very much for doing this

@kizniche
Copy link
Owner

I'm working on allowing the color of each key to be set

@Nithalik
Copy link
Author

Nithalik commented Dec 11, 2023

I'm working on allowing the color of each key to be set

if your working on that side, is it possible to have a start colour, then it change colour on its last action? like a colour change to signify when it is on its last action. just a thought

@kizniche
Copy link
Owner

kizniche commented Dec 11, 2023

Here is an update that adds LED colors for resting, running, and last action running. Let me know if it works.

function_adafruit_neokey_01.txt

@Nithalik
Copy link
Author

Here is an update that adds LED colors for resting, running, and last action running. Let me know if it works.

function_adafruit_neokey_01.txt

very nice just tested and it all works.

only thing i would add, is since there is a resting led state now, maybe add a brightness option to resting so you can have the light off on rest

@kizniche
Copy link
Owner

I don't think brightness can be set. Here is a version that turns the LED off when set to 0.

function_adafruit_neokey_01.txt

@kizniche
Copy link
Owner

kizniche commented Dec 11, 2023

This version may or may not work to set the brightness.

function_adafruit_neokey_01.txt

@kizniche
Copy link
Owner

kizniche commented Dec 11, 2023

Here's one with many more debug lines. Are you deleting the Function then deleting the Function Module, then importing the new module, then adding the Function?

function_adafruit_neokey_01.txt

@Nithalik
Copy link
Author

Here's one with many more debig lines. Are you deleting the Function then deleting the Function Module, then importing the new module, then adding the Function?

function_adafruit_neokey_01.txt

yes i am following that process, delete the function, then the function module, then importing and adding new function

@Nithalik
Copy link
Author

here is the error log from the most

Here's one with many more debug lines. Are you deleting the Function then deleting the Function Module, then importing the new module, then adding the Function?

function_adafruit_neokey_01.txt

here is the error log from this one, buttons still do not seem to do anything, have to go to the old file again

2023-12-10 19:47:07,584 - DEBUG - mycodo.function.function_adafruit_neokey_01_eed44e0c - Parsed Action IDs: OrderedDict([(0, ['8e4a9986']), (1, ['34505ec9']), (2, []), (3, [])])
2023-12-10 19:47:07,584 - DEBUG - mycodo.function.function_adafruit_neokey_01_eed44e0c - Brightness: 0.2
2023-12-10 19:47:07,585 - DEBUG - mycodo.function.function_adafruit_neokey_01_eed44e0c - Colors: OrderedDict([(0, 0), (1, 0), (2, 0), (3, 0)]), OrderedDict([(0, 85), (1, 85), (2, 85), (3, 85)]), OrderedDict([(0, 255), (1, 255), (2, 255), (3, 255)])
2023-12-10 19:47:08,122 - DEBUG - mycodo.controllers.controller_function_eed44e0c - loop() not found
2023-12-10 19:47:08,124 - DEBUG - mycodo.controllers.controller_function_eed44e0c - listener() found
2023-12-10 19:47:08,125 - DEBUG - mycodo.controllers.controller_function_eed44e0c - Starting listener() thread
2023-12-10 19:47:08,126 - INFO - mycodo.controllers.controller_function_eed44e0c - Activated in 910.0 ms
2023-12-10 19:47:13,142 - DEBUG - mycodo.function.function_adafruit_neokey_01_eed44e0c - Key 2
2023-12-10 19:47:13,663 - DEBUG - mycodo.function.function_adafruit_neokey_01_eed44e0c - Executing Actions for Key 1
2023-12-10 19:47:18,630 - DEBUG - mycodo.function.function_adafruit_neokey_01_eed44e0c - Key 1
2023-12-10 19:47:19,152 - DEBUG - mycodo.function.function_adafruit_neokey_01_eed44e0c - Executing Actions for Key 0
2023-12-10 19:47:25,412 - DEBUG - mycodo.function.function_adafruit_neokey_01_eed44e0c - Key 2
2023-12-10 19:47:26,451 - DEBUG - mycodo.function.function_adafruit_neokey_01_eed44e0c - Executing Actions for Key 1
2023-12-10 19:47:27,404 - DEBUG - mycodo.function.function_adafruit_neokey_01_eed44e0c - Key 1

@kizniche
Copy link
Owner

Now we're getting somewhere. Try this version. I suspect we'll see something strange in this one.

function_adafruit_neokey_01.txt

@Nithalik
Copy link
Author

Now we're getting somewhere. Try this version. I suspect we'll see something strange in this one.

function_adafruit_neokey_01.txt

Here are the logs from that one

2023-12-10 19:54:10,793 - DEBUG - mycodo.function.function_adafruit_neokey_01_b6dc24df - Parsed Action IDs: OrderedDict([(0, ['34505ec9']), (1, ['8e4a9986']), (2, []), (3, [])])
2023-12-10 19:54:10,794 - DEBUG - mycodo.function.function_adafruit_neokey_01_b6dc24df - Brightness: 0.2
2023-12-10 19:54:10,794 - DEBUG - mycodo.function.function_adafruit_neokey_01_b6dc24df - Colors: OrderedDict([(0, 0), (1, 0), (2, 0), (3, 0)]), OrderedDict([(0, 85), (1, 85), (2, 85), (3, 85)]), OrderedDict([(0, 255), (1, 255), (2, 255), (3, 255)])
2023-12-10 19:54:11,332 - DEBUG - mycodo.controllers.controller_function_b6dc24df - loop() not found
2023-12-10 19:54:11,332 - DEBUG - mycodo.controllers.controller_function_b6dc24df - listener() found
2023-12-10 19:54:11,333 - DEBUG - mycodo.controllers.controller_function_b6dc24df - Starting listener() thread
2023-12-10 19:54:11,334 - INFO - mycodo.controllers.controller_function_b6dc24df - Activated in 712.1 ms
2023-12-10 19:54:12,799 - DEBUG - mycodo.function.function_adafruit_neokey_01_b6dc24df - Key 2
2023-12-10 19:54:13,327 - DEBUG - mycodo.function.function_adafruit_neokey_01_b6dc24df - Executing Actions for Key 2
2023-12-10 19:54:18,227 - DEBUG - mycodo.function.function_adafruit_neokey_01_b6dc24df - Key 1
2023-12-10 19:54:18,749 - DEBUG - mycodo.function.function_adafruit_neokey_01_b6dc24df - Executing Actions for Key 1

here are the logs from the last version that was working

2023-12-10 19:51:34,573 - INFO - mycodo.controllers.controller_function_11107a50 - Deactivated in 230.7 ms
2023-12-10 19:51:41,250 - DEBUG - mycodo.controllers.controller_function_11107a50 - loop() not found
2023-12-10 19:51:41,251 - DEBUG - mycodo.controllers.controller_function_11107a50 - listener() found
2023-12-10 19:51:41,252 - DEBUG - mycodo.controllers.controller_function_11107a50 - Starting listener() thread
2023-12-10 19:51:41,262 - INFO - mycodo.controllers.controller_function_11107a50 - Activated in 731.0 ms
2023-12-10 19:51:51,647 - INFO - mycodo.function.function_adafruit_neokey_01_11107a50 - Key 1
2023-12-10 19:51:52,401 - DEBUG - mycodo.function.function_adafruit_neokey_01_11107a50 - Return message:  Deactivate Controller 4671a538-ed2d-4c17-888e-00eaab4414c0 (Seedling Regulate pH and Electrical Conductivity).
2023-12-10 19:51:52,699 - INFO - mycodo.controllers.controller_function_4671a538 - Deactivated in 210.6 ms
2023-12-10 19:52:00,551 - INFO - mycodo.function.function_adafruit_neokey_01_11107a50 - Key 2
2023-12-10 19:52:01,247 - DEBUG - mycodo.function.function_adafruit_neokey_01_11107a50 - Return message:  Activate Controller 4671a538-ed2d-4c17-888e-00eaab4414c0 (Seedling Regulate pH and Electrical Conductivity).
2023-12-10 19:52:01,691 - INFO - mycodo.controllers.controller_function_4671a538 - Activated in 356.7 ms
2023-12-10 19:52:07,173 - INFO - mycodo.function.function_adafruit_neokey_01_11107a50 - Key 1
2023-12-10 19:52:07,866 - DEBUG - mycodo.function.function_adafruit_neokey_01_11107a50 - Return message:  Deactivate Controller 4671a538-ed2d-4c17-888e-00eaab4414c0 (Seedling Regulate pH and Electrical Conductivity).
2023-12-10 19:52:08,205 - INFO - mycodo.controllers.controller_function_4671a538 - Deactivated in 245.7 ms

@kizniche
Copy link
Owner

I understand. There's nothing I can tell between the versions that would affect anything. THe only thing I cna do is give you versions to try, since i don't have the device.

@kizniche
Copy link
Owner

kizniche commented Dec 11, 2023

This version I threw in a slew of debug lines.

function_adafruit_neokey_01.txt

@Nithalik
Copy link
Author

This version I threw in a slew of debug lines.

function_adafruit_neokey_01.txt

apologies, didnt know if you saw my message on the old version working. here are the new logs.

2023-12-10 20:01:40,956 - DEBUG - mycodo.function.function_adafruit_neokey_01_d40c3f98 - Parsed Action IDs: OrderedDict([(0, ['34505ec9']), (1, ['8e4a9986']), (2, []), (3, [])])
2023-12-10 20:01:40,956 - DEBUG - mycodo.function.function_adafruit_neokey_01_d40c3f98 - Brightness: 0.2
2023-12-10 20:01:40,957 - DEBUG - mycodo.function.function_adafruit_neokey_01_d40c3f98 - Colors: OrderedDict([(0, 0), (1, 0), (2, 0), (3, 0)]), OrderedDict([(0, 85), (1, 85), (2, 85), (3, 85)]), OrderedDict([(0, 255), (1, 255), (2, 255), (3, 255)])
2023-12-10 20:01:41,494 - DEBUG - mycodo.controllers.controller_function_d40c3f98 - loop() not found
2023-12-10 20:01:41,495 - DEBUG - mycodo.controllers.controller_function_d40c3f98 - listener() found
2023-12-10 20:01:41,495 - DEBUG - mycodo.controllers.controller_function_d40c3f98 - Starting listener() thread
2023-12-10 20:01:41,496 - INFO - mycodo.controllers.controller_function_d40c3f98 - Activated in 715.6 ms
2023-12-10 20:01:53,894 - DEBUG - mycodo.function.function_adafruit_neokey_01_d40c3f98 - Key 2 Pressed
2023-12-10 20:01:54,423 - DEBUG - mycodo.function.function_adafruit_neokey_01_d40c3f98 - Executing Actions for Key 2
2023-12-10 20:01:54,423 - DEBUG - mycodo.function.function_adafruit_neokey_01_d40c3f98 - TEST00
2023-12-10 20:02:03,045 - DEBUG - mycodo.function.function_adafruit_neokey_01_d40c3f98 - Key 1 Pressed
2023-12-10 20:02:03,566 - DEBUG - mycodo.function.function_adafruit_neokey_01_d40c3f98 - Executing Actions for Key 1
2023-12-10 20:02:03,567 - DEBUG - mycodo.function.function_adafruit_neokey_01_d40c3f98 - TEST00

@kizniche
Copy link
Owner

oh wow, it was the easiest fix. Simple error. Should work now.

function_adafruit_neokey_01.txt

@Nithalik
Copy link
Author

oh wow, it was the easiest fix. Simple error. Should work now.

function_adafruit_neokey_01.txt

it is working now. everything seems to be working properly.

what was the issue?

@kizniche
Copy link
Owner

"len(list)" instead of the actual list. "list" is a type, not a variable.

@kizniche
Copy link
Owner

kizniche commented Dec 11, 2023

The last thing I can think of to add is to write a value of 1 to the measurement database for the channel of the key pressed, so it's recorded. We've been at it for a while, so I don't expect you to test this right away if you're done for now. Just let me know if it works if you get a chance to test it.

function_adafruit_neokey_01.txt

@Nithalik
Copy link
Author

we have success, always willing to test when i am the only one who currently benefits, appreciate the help here

image

@kizniche
Copy link
Owner

kizniche commented Dec 11, 2023

I can't seem to get a key name to appear on the chart without some more in-depth refactoring, so I'm going to call it a wrap for now. Thanks for all the testing, I'll add this in my next commit to github.

kizniche added a commit that referenced this issue Dec 11, 2023
…hange deprecated threading.currentThread to threading.current_thread
@kizniche kizniche added the Implemented Implemented but may not be thoroughly tested label Dec 11, 2023
@kizniche
Copy link
Owner

kizniche commented Dec 11, 2023

The last thing I changed (and will commit soon) was figuring out how to have the key number show on measurements (such as on charts, live page, etc). I'm also going to implement an action to set the color of a neopixel at position x of a function and set this new function as the recipient module for that action (as well as the other neopixel functions). That way you can have the lights change in response to things elsewhere in the system, such as turning a key red to notify of a system issue.

If anyone else has ideas for improving the functionality, let me know and we can discuss the feasibility.

One thing that may be interesting (maybe a separate function) would be two sets of actions and colors per key, that when pressed will toggle between executing each set of actions. For example, press Key 1 and it deactivates Function x and turns red (or flash a color, like the flash functionality of LCD screens to indicate an issue), press Key 1 again and it activates Function x and turns green.

Side note: I kind of want one of these now. It seems really useful as a device that can serve as both a status indicator and input device.

@Nithalik
Copy link
Author

Nithalik commented Dec 11, 2023

the addon part is what i was initially envisioning, same button to turn on grow lights, then if on, the same button turns them off. thought it would be to complicated, but it does cut the need for a some of the keys down.

im thinking on how to expand this to use like 4-5 of the keypads.

it is a handy little thing. i love that your thinking of expanding it to be able to address the neopixels too, can replace the neopixel led strip with this and free up that wiring

@kizniche
Copy link
Owner

kizniche commented Dec 11, 2023

Thankfully, I refactored the system a while ago to make development much quicker by allowing all code for a function to be contained in a single file, so developing these functions is much more enjoyable than previously (editing multiple files). This makes it rather easy to implement these features, as long as you understand how the system works and options available to build a module. My only limitation is not owning the hardware, which significantly slows testing. I just bought the board, so we soon won't have to share a dozen module files to make development progress.

@Nithalik
Copy link
Author

The last thing I changed (and will commit soon) was figuring out how to have the key number show on measurements (such as on charts, live page, etc). I'm also going to implement an action to set the color of a neopixel at position x of a function and set this new function as the recipient module for that action (as well as the other neopixel functions). That way you can have the lights change in response to things elsewhere in the system, such as turning a key red to notify of a system issue.

If anyone else has ideas for improving the functionality, let me know and we can discuss the feasibility.

One thing that may be interesting (maybe a separate function) would be two sets of actions and colors per key, that when pressed will toggle between executing each set of actions. For example, press Key 1 and it deactivates Function x and turns red (or flash a color, like the flash functionality of LCD screens to indicate an issue), press Key 1 again and it activates Function x and turns green.

Side note: I kind of want one of these now. It seems really useful as a device that can serve as both a status indicator and input device.

with it showing the key number, how do you account for multiple devices? just have it display device name-1?

@kizniche
Copy link
Owner

kizniche commented Dec 11, 2023

You can already name the Function, which appears next to each measurement. I'll also work on allowing renaming the measurement so you can change the measurement name from "Key 1".

kizniche added a commit that referenced this issue Dec 12, 2023
…work with Neopixel Function, Add Actions: Neopixel Flashing On and Neopixel Flashing Off (#1353)
@kizniche
Copy link
Owner

I just committed changes to the Neopixel Function to include the ability to flash and have the color set via the Neopixel Set Color Action (and updated the action to work with this Function). I also created Flash On and Flash Off Actions for the Neopixel Function. All code is on the master branch now, so delete any Neopixel Functions, delete the Function Module from the import page, upgrade to master, then you should have the built-in Function available.

@Nithalik
Copy link
Author

tested the neopixel set colour and all works as described. like the flashing option

@kizniche
Copy link
Owner

kizniche commented Dec 12, 2023

Great. I'm actually a little surprised it all worked on the first try, considering I couldn't test anything since I don't yet have the hardware. I also have a small update that can fix some edge cases with button presses and flashing, but I'll be committing that soon.

@kizniche
Copy link
Owner

kizniche commented Dec 12, 2023

I think I may change from using the single value color to the format I used previously for neopixels, the RGB string, e.g. "10, 255, 0".

@Nithalik
Copy link
Author

Nithalik commented Dec 12, 2023

I think I may change from using the single value color to the format I used previously for neopixels, the RGB string, e.g. "10, 255, 0".

would make sense for consistency, and i believe with that 0 is still off

@kizniche
Copy link
Owner

I received my NeoKey 4x1 and had a chance tonight to test it with the Function. I found a bunch of bugs that I fixed and performance improvements. Just a few of the changes: it's now faster, key presses do nothing if it's already executing, there's a new shutdown color, fixed an issue with the function thread stopping, you can press another key while you have one already pressed. You can upgrade to master to get the new code.

@Nithalik
Copy link
Author

Nithalik commented Dec 16, 2023

i like the shutdown colour option. the pressing more then one at once was something i noticed before, so glad to see you already resolved it

i also found this

https://www.adafruit.com/product/5157

image

its not i2c, so im not sure if its something that you can implement, but its basically this neokey, but any amount of keys you want.

and this https://www.adafruit.com/product/5100 almost a holy grail input device in my eyes. but its USBC or UART so prob not really a feasible option

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Implemented Implemented but may not be thoroughly tested
Projects
None yet
Development

No branches or pull requests

4 participants
@kizniche @Nithalik and others