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

Reduce button click events #24

Open
lyweilian opened this issue Dec 12, 2016 · 0 comments
Open

Reduce button click events #24

lyweilian opened this issue Dec 12, 2016 · 0 comments

Comments

@lyweilian
Copy link

First of all great work with what you have done with aRestUI. It's awesome!

I have made some slight modifications to my local copy of your code that generates the button Javascript. Instead of having a pair of functions (on and off) per pin for buttons. You can simply have one button click event for all buttons. This can be achieved by changing the ID of the button to tell the function what pin and what state (low or high). This may help keep your code lean and keep the OUTPUT_BUFFER_SIZE size lower in aREST.h. You may want to also consider offloading the HTML generation to JQuery as well.

See the following:

// Buttons UI
    for (int i = 0; i < buttons_index; i++) {
      addToBuffer("<div class=\"row\">");
      addToBuffer("<div class=\"col-md-2\"><button class=\"btn btn-block btn-lg btn-primary\" id='btn_1_");
      addToBuffer(buttons[i]);
      addToBuffer("'>On</button></div>");
      addToBuffer("<div class=\"col-md-2\"><button class=\"btn btn-block btn-lg btn-danger\" id='btn_0_");
      addToBuffer(buttons[i]);
      addToBuffer("'>Off</button></div>");
      addToBuffer("</div>");
    }
    // Buttons JavaScript
	
	addToBuffer("$('.btn').click(function(){");
	addToBuffer("var id = $(this).attr('id').split('_');");
	addToBuffer("$.getq('queue','/digital/'+id[2]+'/'+id[1]); });");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant