Compare commits

...

7 Commits

10 changed files with 129 additions and 61 deletions

View File

@@ -35,7 +35,7 @@ static bool I2CDefaultWriteData( struct GDS_Device* Device, const uint8_t* Data,
bool GDS_I2CInit( int PortNumber, int SDA, int SCL, int Speed ) { bool GDS_I2CInit( int PortNumber, int SDA, int SCL, int Speed ) {
I2CPortNumber = PortNumber; I2CPortNumber = PortNumber;
I2CWait = pdMS_TO_TICKS( Speed ? Speed / 4000 : 100 ); I2CWait = pdMS_TO_TICKS( Speed ? (250 * 250000) / Speed : 250 );
if (SDA != -1 && SCL != -1) { if (SDA != -1 && SCL != -1) {
i2c_config_t Config = { 0 }; i2c_config_t Config = { 0 };

View File

@@ -5,6 +5,7 @@
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. CONDITIONS OF ANY KIND, either express or implied.
*/ */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
@@ -83,8 +84,8 @@ static void vCallbackFunction( TimerHandle_t xTimer ) {
*/ */
bool led_blink_core(int idx, int ontime, int offtime, bool pushed) { bool led_blink_core(int idx, int ontime, int offtime, bool pushed) {
if (!leds[idx].gpio || leds[idx].gpio < 0 ) return false; if (!leds[idx].gpio || leds[idx].gpio < 0 ) return false;
ESP_LOGD(TAG,"led_blink_core led idx %d, ontime %d, offtime %d, pushing %s. Led state: pushedon %d, pushedoff %d, timer %s, pushed %s", idx,ontime,offtime,pushed?"TRUE":"FALSE", leds[idx].pushedon,leds[idx].pushedoff,leds[idx].timer?"TRUE":"FALSE", leds[idx].pushed?"TRUE":"FALSE"); ESP_LOGD(TAG,"led_blink_core %d on:%d off:%d, pushed:%u", idx, ontime, offtime, pushed);
if (leds[idx].timer) { if (leds[idx].timer) {
// normal requests waits if a pop is pending // normal requests waits if a pop is pending
if (!pushed && leds[idx].pushed) { if (!pushed && leds[idx].pushed) {
@@ -97,18 +98,15 @@ bool led_blink_core(int idx, int ontime, int offtime, bool pushed) {
// save current state if not already pushed // save current state if not already pushed
if (!leds[idx].pushed) { if (!leds[idx].pushed) {
ESP_LOGD(TAG,"Pushing state. Ontime %d->%d. Offtime %d->%d",leds[idx].pushedon,leds[idx].ontime, leds[idx].pushedoff,leds[idx].offtime);
leds[idx].pushedon = leds[idx].ontime; leds[idx].pushedon = leds[idx].ontime;
leds[idx].pushedoff = leds[idx].offtime; leds[idx].pushedoff = leds[idx].offtime;
leds[idx].pushed = pushed; leds[idx].pushed = pushed;
} }
// then set new one // then set new one
leds[idx].ontime = ontime; leds[idx].ontime = ontime;
leds[idx].offtime = offtime; leds[idx].offtime = offtime;
if (ontime == 0) { if (ontime == 0) {
ESP_LOGD(TAG,"led %d, setting reverse level", idx); ESP_LOGD(TAG,"led %d, setting reverse level", idx);
set_level(leds + idx, false); set_level(leds + idx, false);
@@ -126,8 +124,7 @@ bool led_blink_core(int idx, int ontime, int offtime, bool pushed) {
ESP_LOGD(TAG,"led %d, Setting gpio %d and starting timer", idx, leds[idx].gpio); ESP_LOGD(TAG,"led %d, Setting gpio %d and starting timer", idx, leds[idx].gpio);
if (xTimerStart(leds[idx].timer, BLOCKTIME) == pdFAIL) return false; if (xTimerStart(leds[idx].timer, BLOCKTIME) == pdFAIL) return false;
} }
ESP_LOGD(TAG,"led_blink_core END led idx %d, ontime %d, offtime %d, pushing %s. Led state: pushedon %d, pushedoff %d, timer %s, pushed %s", idx,ontime,offtime,pushed?"TRUE":"FALSE", leds[idx].pushedon,leds[idx].pushedoff,leds[idx].timer?"TRUE":"FALSE", leds[idx].pushed?"TRUE":"FALSE");
return true; return true;
} }
@@ -234,13 +231,16 @@ void led_svc_init(void) {
#ifndef CONFIG_LED_LOCKED #ifndef CONFIG_LED_LOCKED
parse_set_GPIO(set_led_gpio); parse_set_GPIO(set_led_gpio);
#endif #endif
char *nvs_item = config_alloc_get(NVS_TYPE_STR, "led_brightness"), *p; char *nvs_item = config_alloc_get(NVS_TYPE_STR, "led_brightness"), *p;
if (nvs_item) { if (nvs_item) {
if ((p = strcasestr(nvs_item, "green")) != NULL) green.pwm = atoi(strchr(p, '=') + 1); if ((p = strcasestr(nvs_item, "green")) != NULL) green.pwm = atoi(strchr(p, '=') + 1);
if ((p = strcasestr(nvs_item, "red")) != NULL) red.pwm = atoi(strchr(p, '=') + 1); if ((p = strcasestr(nvs_item, "red")) != NULL) red.pwm = atoi(strchr(p, '=') + 1);
free(nvs_item); free(nvs_item);
} }
ESP_LOGI(TAG,"Configuring LEDs green:%d (active:%d %d%%), red:%d (active:%d %d%%)", green.gpio, green.active, green.pwm, red.gpio, red.active, red.pwm );
led_config(LED_GREEN, green.gpio, green.active, green.pwm); led_config(LED_GREEN, green.gpio, green.active, green.pwm);
led_config(LED_RED, red.gpio, red.active, red.pwm); led_config(LED_RED, red.gpio, red.active, red.pwm);
ESP_LOGI(TAG,"Configuring LEDs green:%d (active:%d %d%%), red:%d (active:%d %d%%)", green.gpio, green.active, green.pwm, red.gpio, red.active, red.pwm );
} }

View File

@@ -133,7 +133,7 @@ static esp_err_t i2c_write_reg(uint8_t reg, uint8_t val) {
i2c_master_write_byte(cmd, val, I2C_MASTER_NACK); i2c_master_write_byte(cmd, val, I2C_MASTER_NACK);
i2c_master_stop(cmd); i2c_master_stop(cmd);
ret = i2c_master_cmd_begin(i2c_port, cmd, 1000 / portTICK_RATE_MS); ret = i2c_master_cmd_begin(i2c_port, cmd, 100 / portTICK_RATE_MS);
i2c_cmd_link_delete(cmd); i2c_cmd_link_delete(cmd);
if (ret != ESP_OK) { if (ret != ESP_OK) {
@@ -161,7 +161,7 @@ static uint8_t i2c_read_reg(uint8_t reg) {
i2c_master_read_byte(cmd, &data, I2C_MASTER_NACK); i2c_master_read_byte(cmd, &data, I2C_MASTER_NACK);
i2c_master_stop(cmd); i2c_master_stop(cmd);
ret = i2c_master_cmd_begin(i2c_port, cmd, 1000 / portTICK_RATE_MS); ret = i2c_master_cmd_begin(i2c_port, cmd, 100 / portTICK_RATE_MS);
i2c_cmd_link_delete(cmd); i2c_cmd_link_delete(cmd);
if (ret != ESP_OK) { if (ret != ESP_OK) {

View File

@@ -253,6 +253,10 @@ void process_received_data(const char * buffer, size_t size){
if(bMirrorToUART){ if(bMirrorToUART){
write(uart_fd, command, size); write(uart_fd, command, size);
} }
for(int i=strlen(command);i>=0;i--){
// strip any cr/lf
if(command[i]== '\n' || command[i]== '\r') command[i]= '\0';
}
run_command((char *)command); run_command((char *)command);
} }
free(command); free(command);

View File

@@ -100,8 +100,95 @@ function RepeatRefreshAPInterval(){
if(RefreshAPIIntervalActive) if(RefreshAPIIntervalActive)
startRefreshAPInterval(); startRefreshAPInterval();
} }
function getConfigJson(slimMode){
var config = {};
$("input.nvs").each(function() {
var key = $(this)[0].id;
var val = $(this).val();
if(!slimMode){
var nvs_type = parseInt($(this)[0].attributes.nvs_type.nodeValue,10);
if (key != '') {
config[key] = {};
if(nvs_type == nvs_type_t.NVS_TYPE_U8
|| nvs_type == nvs_type_t.NVS_TYPE_I8
|| nvs_type == nvs_type_t.NVS_TYPE_U16
|| nvs_type == nvs_type_t.NVS_TYPE_I16
|| nvs_type == nvs_type_t.NVS_TYPE_U32
|| nvs_type == nvs_type_t.NVS_TYPE_I32
|| nvs_type == nvs_type_t.NVS_TYPE_U64
|| nvs_type == nvs_type_t.NVS_TYPE_I64) {
config[key].value = parseInt(val);
}
else {
config[key].value = val;
}
config[key].type = nvs_type;
}
}
else {
config[key] = val;
}
});
var key = $("#nvs-new-key").val();
var val = $("#nvs-new-value").val();
if (key != '') {
if(!slimMode){
config[key] = {};
config[key].value = val;
config[key].type = 33;
}
else {
config[key] = val;
}
}
return config;
}
$(document).ready(function(){
function onFileLoad(elementId, event) {
var data={};
try{
data = JSON.parse(elementId.srcElement.result);
}
catch (e){
alert('Parsing failed!\r\n '+ e);
}
$("input.nvs").each(function() {
var key = $(this)[0].id;
var val = $(this).val();
if(data[key]){
if(data[key] != val){
console.log("Changed "& key & " " & val & "==>" & data[key]);
$(this).val(data[key]);
}
}
else {
console.log("Value " & key & " missing from file");
}
});
}
function onChooseFile(event, onLoadFileHandler) {
if (typeof window.FileReader !== 'function')
throw ("The file API isn't supported on this browser.");
let input = event.target;
if (!input)
throw ("The browser does not properly implement the event object");
if (!input.files)
throw ("This browser does not support the `files` property of the file input.");
if (!input.files[0])
return undefined;
let file = input.files[0];
let fr = new FileReader();
fr.onload = onLoadFileHandler;
fr.readAsText(file);
input.value="";
}
$(document).ready(function(){
$("#load-nvs").click(function () {
$("#nvsfilename").trigger('click');
});
$("#wifi-status").on("click", ".ape", function() { $("#wifi-status").on("click", ".ape", function() {
$( "#wifi" ).slideUp( "fast", function() {}); $( "#wifi" ).slideUp( "fast", function() {});
$( "#connect-details" ).slideDown( "fast", function() {}); $( "#connect-details" ).slideDown( "fast", function() {});
@@ -334,42 +421,27 @@ $(document).ready(function(){
console.log('sent config JSON with data:', JSON.stringify(data)); console.log('sent config JSON with data:', JSON.stringify(data));
}); });
$("#save-as-nvs").on("click", function() {
var data = { 'timestamp': Date.now() };
var config = getConfigJson(true);
const a = document.createElement("a");
a.href = URL.createObjectURL(
new Blob([JSON.stringify(config, null, 2)], {
type: "text/plain"
}));
a.setAttribute("download", "nvs_config" + Date.now() +"json");
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
console.log('sent config JSON with headers:', JSON.stringify(headers));
console.log('sent config JSON with data:', JSON.stringify(data));
});
$("#save-nvs").on("click", function() { $("#save-nvs").on("click", function() {
var headers = {}; var headers = {};
var data = { 'timestamp': Date.now() }; var data = { 'timestamp': Date.now() };
var config = {}; var config = getConfigJson(false);
$("input.nvs").each(function() {
var key = $(this)[0].id;
var val = $(this).val();
var nvs_type = parseInt($(this)[0].attributes.nvs_type.nodeValue,10);
if (key != '') {
config[key] = {};
if(nvs_type == nvs_type_t.NVS_TYPE_U8
|| nvs_type == nvs_type_t.NVS_TYPE_I8
|| nvs_type == nvs_type_t.NVS_TYPE_U16
|| nvs_type == nvs_type_t.NVS_TYPE_I16
|| nvs_type == nvs_type_t.NVS_TYPE_U32
|| nvs_type == nvs_type_t.NVS_TYPE_I32
|| nvs_type == nvs_type_t.NVS_TYPE_U64
|| nvs_type == nvs_type_t.NVS_TYPE_I64) {
config[key].value = parseInt(val);
}
else {
config[key].value = val;
}
config[key].type = nvs_type;
}
});
var key = $("#nvs-new-key").val();
var val = $("#nvs-new-value").val();
if (key != '') {
// headers["X-Custom-" +key] = val;
config[key] = {};
config[key].value = val;
config[key].type = 33;
}
data['config'] = config; data['config'] = config;
$.ajax({ $.ajax({
url: '/config.json', url: '/config.json',
@@ -421,7 +493,6 @@ $(document).ready(function(){
fwurl : { fwurl : {
value : url, value : url,
type : 33 type : 33
} }
}; };

View File

@@ -721,6 +721,7 @@ esp_err_t config_post_handler(httpd_req_t *req){
if(err==ESP_OK){ if(err==ESP_OK){
httpd_resp_sendstr(req, "{ \"result\" : \"OK\" }"); httpd_resp_sendstr(req, "{ \"result\" : \"OK\" }");
messaging_post_message(MESSAGING_INFO,MESSAGING_CLASS_SYSTEM,"Save Success");
} }
cJSON_Delete(root); cJSON_Delete(root);
if(bOTA) { if(bOTA) {

View File

@@ -332,13 +332,16 @@
<tbody id="nvsTable"> <tbody id="nvsTable">
</tbody> </tbody>
</table> </table>
<div class="buttons"> <div class="buttons">
<div id="boot-div"> <div id="boot-div">
<form id="reboot-form" action="/reboot.json" method="post" target="dummyframe"> <form id="reboot-form" action="/reboot.json" method="post" target="dummyframe">
<button id="reboot-button" type="submit" class="btn btn-primary">Reboot</button> <button id="reboot-button" type="submit" class="btn btn-primary">Reboot</button>
</form> </form>
</div> </div>
<input id="save-nvs" type="button" class="btn btn-success" value="Save" /> <input id="save-nvs" type="button" class="btn btn-success" value="Commit">
<input id="save-as-nvs" type="button" class="btn btn-success" value="Download config">
<input id="load-nvs" type="button" class="btn btn-success" value="Load File">
<input aria-describedby="fileHelp" onchange="onChooseFile(event, onFileLoad.bind(this))" id="nvsfilename" type="file" style="display:none">
</div> </div>
</div> <!-- nvs --> </div> <!-- nvs -->

View File

@@ -693,8 +693,6 @@ static void event_handler(void* arg, esp_event_base_t event_base, int32_t event_
ESP_LOGD(TAG, "WIFI_EVENT_AP_STACONNECTED. aid: %d, mac: %s",stac->aid,STR_OR_BLANK(mac)); ESP_LOGD(TAG, "WIFI_EVENT_AP_STACONNECTED. aid: %d, mac: %s",stac->aid,STR_OR_BLANK(mac));
FREE_AND_NULL(mac); FREE_AND_NULL(mac);
xEventGroupSetBits(wifi_manager_event_group, WIFI_MANAGER_AP_STA_CONNECTED_BIT); xEventGroupSetBits(wifi_manager_event_group, WIFI_MANAGER_AP_STA_CONNECTED_BIT);
wifi_manager_send_message(EVENT_STA_CONNECTED, NULL);
} }
break; break;
case WIFI_EVENT_AP_STADISCONNECTED: case WIFI_EVENT_AP_STADISCONNECTED:
@@ -1482,9 +1480,6 @@ void wifi_manager( void * pvParameters ){
/* callback */ /* callback */
if(cb_ptr_arr[msg.code]) (*cb_ptr_arr[msg.code])(NULL); if(cb_ptr_arr[msg.code]) (*cb_ptr_arr[msg.code])(NULL);
break; break;
case EVENT_STA_CONNECTED:
if(cb_ptr_arr[msg.code]) (*cb_ptr_arr[msg.code])(NULL);
break;
case UPDATE_CONNECTION_OK: case UPDATE_CONNECTION_OK:
/* refresh JSON */ /* refresh JSON */
if(wifi_manager_lock_json_buffer( portMAX_DELAY )){ if(wifi_manager_lock_json_buffer( portMAX_DELAY )){

View File

@@ -191,8 +191,7 @@ typedef enum message_code_t {
ORDER_RESTART_RECOVERY = 16, ORDER_RESTART_RECOVERY = 16,
ORDER_RESTART_OTA_URL = 17, ORDER_RESTART_OTA_URL = 17,
ORDER_RESTART = 18, ORDER_RESTART = 18,
EVENT_STA_CONNECTED = 19, MESSAGE_CODE_COUNT = 19 /* important for the callback array */
MESSAGE_CODE_COUNT = 20 /* important for the callback array */
}message_code_t; }message_code_t;

View File

@@ -95,10 +95,6 @@ void cb_connection_sta_disconnected(void *pvParameter){
bWifiConnected=false; bWifiConnected=false;
xEventGroupClearBits(wifi_event_group, CONNECTED_BIT); xEventGroupClearBits(wifi_event_group, CONNECTED_BIT);
} }
void cb_connection_sta_connected(void *pvParameter){
}
bool wait_for_wifi(){ bool wait_for_wifi(){
bool connected=(xEventGroupGetBits(wifi_event_group) & CONNECTED_BIT)!=0; bool connected=(xEventGroupGetBits(wifi_event_group) & CONNECTED_BIT)!=0;
if(!connected){ if(!connected){
@@ -467,7 +463,6 @@ void app_main()
* This can be either after we're started the AP mode, or after we've started the STA mode */ * This can be either after we're started the AP mode, or after we've started the STA mode */
wifi_manager_set_callback(ORDER_START_AP, &start_telnet); wifi_manager_set_callback(ORDER_START_AP, &start_telnet);
wifi_manager_set_callback(ORDER_CONNECT_STA, &start_telnet); wifi_manager_set_callback(ORDER_CONNECT_STA, &start_telnet);
wifi_manager_set_callback(EVENT_STA_CONNECTED, &cb_connection_sta_connected);
} }
console_start(); console_start();