aREST_UI icon indicating copy to clipboard operation
aREST_UI copied to clipboard

Reduce button click events

Open lyweilian opened this issue 8 years ago • 0 comments

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]); });");

lyweilian avatar Dec 12 '16 05:12 lyweilian