var g_GpioPins = [ { gpio: '17', mode: 'out', value: 1 }, { gpio: '18', mode: 'out', value: 1 }, { gpio: '27', mode: 'out', value: 1 }, { gpio: '22', mode: 'out', value: 1 }, { gpio: '24', mode: 'in', value: 0 } ]; var g_RefreshTimer = null; function debug(debug_data) { $.ajax({ url: 'debug.php', type: 'post', datatype: 'json', data: debug_data, success: function(result) { // Do something with data that came back. var objData = jQuery.parseJSON(result); $('#UpdateResult').html(objData.status); } }); } function getSetPin(pinData) { $.ajax({ url: 'gpio.php', type: 'post', datatype: 'json', data: pinData, success: function(result) { // Do something with data that came back. var objData = jQuery.parseJSON(result); $('#UpdateResult').html(objData.status); } }); } function switchValue(gpio) { for (var i_Pin in g_GpioPins) { if (g_GpioPins[i_Pin].gpio == gpio) { switch (g_GpioPins[i_Pin].mode) { case 'out': switch (g_GpioPins[i_Pin].value) { case 0: g_GpioPins[i_Pin].value = 1; break; case 1: g_GpioPins[i_Pin].value = 0; break; } break; case 'in': console.log('auslesen' + g_GpioPins[i_Pin].gpio); break; } getSetPin(g_GpioPins[i_Pin]); break; } } debug(gpio); } function autoRefresh() { //console.log($('#AutoRefresh').val()); if ($('#AutoRefresh').val() == 'On') { autoRefreshStart(); } else { autoRefreshStop(); } } function autoRefreshStop() { //console.log('Auto OFF!'); clearInterval(g_RefreshTimer); g_RefreshTimer = null; } function autoRefreshStart() { //console.log('Auto On!'); g_RefreshTimer = setInterval('getSetPin(g_GpioPins[1])', 100); getSetPin(g_GpioPins[1]); }