clang-format: rcommand.cpp, rgb_led.cpp+h, rokkithash.cpp, vendor_array
This commit is contained in:
parent
6250a0c308
commit
b79442f26b
477
src/rcommand.cpp
477
src/rcommand.cpp
@ -1,6 +1,7 @@
|
|||||||
// remote command interpreter
|
// remote command interpreter
|
||||||
// parses multiple number of command / value pairs from LoRaWAN remote command port (RCMDPORT)
|
// parses multiple number of command / value pairs from LoRaWAN remote command
|
||||||
// checks commands and executes each command with 1 argument per command
|
// port (RCMDPORT) checks commands and executes each command with 1 argument per
|
||||||
|
// command
|
||||||
|
|
||||||
// Basic Config
|
// Basic Config
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
@ -14,297 +15,351 @@ static const char TAG[] = "main";
|
|||||||
|
|
||||||
// table of remote commands and assigned functions
|
// table of remote commands and assigned functions
|
||||||
typedef struct {
|
typedef struct {
|
||||||
const uint8_t nam;
|
const uint8_t nam;
|
||||||
void (*func)(uint8_t);
|
void (*func)(uint8_t);
|
||||||
const bool store;
|
const bool store;
|
||||||
} cmd_t;
|
} cmd_t;
|
||||||
|
|
||||||
// function defined in antenna.cpp
|
// function defined in antenna.cpp
|
||||||
#ifdef HAS_ANTENNA_SWITCH
|
#ifdef HAS_ANTENNA_SWITCH
|
||||||
void antenna_select(const uint8_t _ant);
|
void antenna_select(const uint8_t _ant);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// function defined in adcread.cpp
|
// function defined in adcread.cpp
|
||||||
#ifdef HAS_BATTERY_PROBE
|
#ifdef HAS_BATTERY_PROBE
|
||||||
uint32_t read_voltage(void);
|
uint32_t read_voltage(void);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// function sends result of get commands to LoRaWAN network
|
// function sends result of get commands to LoRaWAN network
|
||||||
void do_transmit(osjob_t* j){
|
void do_transmit(osjob_t *j) {
|
||||||
// check if there is a pending TX/RX job running, if yes then reschedule transmission
|
// check if there is a pending TX/RX job running, if yes then reschedule
|
||||||
if (LMIC.opmode & OP_TXRXPEND) {
|
// transmission
|
||||||
ESP_LOGI(TAG, "LoRa busy, rescheduling");
|
if (LMIC.opmode & OP_TXRXPEND) {
|
||||||
sprintf(display_lmic, "LORA BUSY");
|
ESP_LOGI(TAG, "LoRa busy, rescheduling");
|
||||||
os_setTimedCallback(&rcmdjob, os_getTime()+sec2osticks(RETRANSMIT_RCMD), do_transmit);
|
sprintf(display_lmic, "LORA BUSY");
|
||||||
}
|
os_setTimedCallback(&rcmdjob, os_getTime() + sec2osticks(RETRANSMIT_RCMD),
|
||||||
LMIC_setTxData2(RCMDPORT, rcmd_data, rcmd_data_size, 0); // send data unconfirmed on RCMD Port
|
do_transmit);
|
||||||
ESP_LOGI(TAG, "%d bytes queued to send", rcmd_data_size);
|
}
|
||||||
sprintf(display_lmic, "PACKET QUEUED");
|
LMIC_setTxData2(RCMDPORT, rcmd_data, rcmd_data_size,
|
||||||
|
0); // send data unconfirmed on RCMD Port
|
||||||
|
ESP_LOGI(TAG, "%d bytes queued to send", rcmd_data_size);
|
||||||
|
sprintf(display_lmic, "PACKET QUEUED");
|
||||||
}
|
}
|
||||||
|
|
||||||
// help function to transmit result of get commands, since callback function do_transmit() cannot have params
|
// help function to transmit result of get commands, since callback function
|
||||||
void transmit(xref2u1_t mydata, u1_t mydata_size){
|
// do_transmit() cannot have params
|
||||||
rcmd_data = mydata;
|
void transmit(xref2u1_t mydata, u1_t mydata_size) {
|
||||||
rcmd_data_size = mydata_size;
|
rcmd_data = mydata;
|
||||||
do_transmit(&rcmdjob);
|
rcmd_data_size = mydata_size;
|
||||||
|
do_transmit(&rcmdjob);
|
||||||
}
|
}
|
||||||
|
|
||||||
// help function to assign LoRa datarates to numeric spreadfactor values
|
// help function to assign LoRa datarates to numeric spreadfactor values
|
||||||
void switch_lora (uint8_t sf, uint8_t tx) {
|
void switch_lora(uint8_t sf, uint8_t tx) {
|
||||||
if ( tx > 20 ) return;
|
if (tx > 20)
|
||||||
cfg.txpower = tx;
|
return;
|
||||||
switch (sf) {
|
cfg.txpower = tx;
|
||||||
case 7: LMIC_setDrTxpow(DR_SF7,tx); cfg.lorasf=sf; break;
|
switch (sf) {
|
||||||
case 8: LMIC_setDrTxpow(DR_SF8,tx); cfg.lorasf=sf; break;
|
case 7:
|
||||||
case 9: LMIC_setDrTxpow(DR_SF9,tx); cfg.lorasf=sf; break;
|
LMIC_setDrTxpow(DR_SF7, tx);
|
||||||
case 10: LMIC_setDrTxpow(DR_SF10,tx); cfg.lorasf=sf; break;
|
cfg.lorasf = sf;
|
||||||
case 11:
|
break;
|
||||||
#if defined(CFG_eu868)
|
case 8:
|
||||||
LMIC_setDrTxpow(DR_SF11,tx); cfg.lorasf=sf; break;
|
LMIC_setDrTxpow(DR_SF8, tx);
|
||||||
#elif defined(CFG_us915)
|
cfg.lorasf = sf;
|
||||||
LMIC_setDrTxpow(DR_SF11CR,tx); cfg.lorasf=sf; break;
|
break;
|
||||||
#endif
|
case 9:
|
||||||
case 12:
|
LMIC_setDrTxpow(DR_SF9, tx);
|
||||||
#if defined(CFG_eu868)
|
cfg.lorasf = sf;
|
||||||
LMIC_setDrTxpow(DR_SF12,tx); cfg.lorasf=sf; break;
|
break;
|
||||||
#elif defined(CFG_us915)
|
case 10:
|
||||||
LMIC_setDrTxpow(DR_SF12CR,tx); cfg.lorasf=sf; break;
|
LMIC_setDrTxpow(DR_SF10, tx);
|
||||||
#endif
|
cfg.lorasf = sf;
|
||||||
default: break;
|
break;
|
||||||
}
|
case 11:
|
||||||
|
#if defined(CFG_eu868)
|
||||||
|
LMIC_setDrTxpow(DR_SF11, tx);
|
||||||
|
cfg.lorasf = sf;
|
||||||
|
break;
|
||||||
|
#elif defined(CFG_us915)
|
||||||
|
LMIC_setDrTxpow(DR_SF11CR, tx);
|
||||||
|
cfg.lorasf = sf;
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
case 12:
|
||||||
|
#if defined(CFG_eu868)
|
||||||
|
LMIC_setDrTxpow(DR_SF12, tx);
|
||||||
|
cfg.lorasf = sf;
|
||||||
|
break;
|
||||||
|
#elif defined(CFG_us915)
|
||||||
|
LMIC_setDrTxpow(DR_SF12CR, tx);
|
||||||
|
cfg.lorasf = sf;
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// set of functions that can be triggered by remote commands
|
// set of functions that can be triggered by remote commands
|
||||||
void set_reset(uint8_t val) {
|
void set_reset(uint8_t val) {
|
||||||
switch (val) {
|
switch (val) {
|
||||||
case 0: // restart device
|
case 0: // restart device
|
||||||
ESP_LOGI(TAG, "Remote command: restart device");
|
ESP_LOGI(TAG, "Remote command: restart device");
|
||||||
sprintf(display_lora, "Reset pending");
|
sprintf(display_lora, "Reset pending");
|
||||||
vTaskDelay(10000/portTICK_PERIOD_MS); // wait for LMIC to confirm LoRa downlink to server
|
vTaskDelay(
|
||||||
esp_restart();
|
10000 /
|
||||||
break;
|
portTICK_PERIOD_MS); // wait for LMIC to confirm LoRa downlink to server
|
||||||
case 1: // reset MAC counter
|
esp_restart();
|
||||||
ESP_LOGI(TAG, "Remote command: reset MAC counter");
|
break;
|
||||||
reset_counters(); // clear macs
|
case 1: // reset MAC counter
|
||||||
reset_salt(); // get new salt
|
ESP_LOGI(TAG, "Remote command: reset MAC counter");
|
||||||
sprintf(display_lora, "Reset counter");
|
reset_counters(); // clear macs
|
||||||
break;
|
reset_salt(); // get new salt
|
||||||
case 2: // reset device to factory settings
|
sprintf(display_lora, "Reset counter");
|
||||||
ESP_LOGI(TAG, "Remote command: reset device to factory settings");
|
break;
|
||||||
sprintf(display_lora, "Factory reset");
|
case 2: // reset device to factory settings
|
||||||
eraseConfig();
|
ESP_LOGI(TAG, "Remote command: reset device to factory settings");
|
||||||
break;
|
sprintf(display_lora, "Factory reset");
|
||||||
}
|
eraseConfig();
|
||||||
|
break;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void set_rssi(uint8_t val) {
|
void set_rssi(uint8_t val) {
|
||||||
cfg.rssilimit = val * -1;
|
cfg.rssilimit = val * -1;
|
||||||
ESP_LOGI(TAG, "Remote command: set RSSI limit to %d", cfg.rssilimit);
|
ESP_LOGI(TAG, "Remote command: set RSSI limit to %d", cfg.rssilimit);
|
||||||
};
|
};
|
||||||
|
|
||||||
void set_sendcycle(uint8_t val) {
|
void set_sendcycle(uint8_t val) {
|
||||||
cfg.sendcycle = val;
|
cfg.sendcycle = val;
|
||||||
ESP_LOGI(TAG, "Remote command: set payload send cycle to %d seconds", cfg.sendcycle*2);
|
ESP_LOGI(TAG, "Remote command: set payload send cycle to %d seconds",
|
||||||
|
cfg.sendcycle * 2);
|
||||||
};
|
};
|
||||||
|
|
||||||
void set_wifichancycle(uint8_t val) {
|
void set_wifichancycle(uint8_t val) {
|
||||||
cfg.wifichancycle = val;
|
cfg.wifichancycle = val;
|
||||||
// modify wifi channel rotation IRQ
|
// modify wifi channel rotation IRQ
|
||||||
timerAlarmWrite(channelSwitch, cfg.wifichancycle * 10000, true); // reload interrupt after each trigger of channel switch cycle
|
timerAlarmWrite(
|
||||||
ESP_LOGI(TAG, "Remote command: set Wifi channel switch interval to %.1f seconds", cfg.wifichancycle/float(100));
|
channelSwitch, cfg.wifichancycle * 10000,
|
||||||
|
true); // reload interrupt after each trigger of channel switch cycle
|
||||||
|
ESP_LOGI(TAG,
|
||||||
|
"Remote command: set Wifi channel switch interval to %.1f seconds",
|
||||||
|
cfg.wifichancycle / float(100));
|
||||||
};
|
};
|
||||||
|
|
||||||
void set_blescantime(uint8_t val) {
|
void set_blescantime(uint8_t val) {
|
||||||
cfg.blescantime = val;
|
cfg.blescantime = val;
|
||||||
ESP_LOGI(TAG, "Remote command: set BLE scan time to %.1f seconds", cfg.blescantime/float(100));
|
ESP_LOGI(TAG, "Remote command: set BLE scan time to %.1f seconds",
|
||||||
#ifdef BLECOUNTER
|
cfg.blescantime / float(100));
|
||||||
// stop & restart BLE scan task to apply new parameter
|
#ifdef BLECOUNTER
|
||||||
if (cfg.blescan)
|
// stop & restart BLE scan task to apply new parameter
|
||||||
{
|
if (cfg.blescan) {
|
||||||
stop_BLEscan();
|
stop_BLEscan();
|
||||||
start_BLEscan();
|
start_BLEscan();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
void set_countmode(uint8_t val) {
|
void set_countmode(uint8_t val) {
|
||||||
switch (val) {
|
switch (val) {
|
||||||
case 0: // cyclic unconfirmed
|
case 0: // cyclic unconfirmed
|
||||||
cfg.countermode = 0;
|
cfg.countermode = 0;
|
||||||
ESP_LOGI(TAG, "Remote command: set counter mode to cyclic unconfirmed");
|
ESP_LOGI(TAG, "Remote command: set counter mode to cyclic unconfirmed");
|
||||||
break;
|
break;
|
||||||
case 1: // cumulative
|
case 1: // cumulative
|
||||||
cfg.countermode = 1;
|
cfg.countermode = 1;
|
||||||
ESP_LOGI(TAG, "Remote command: set counter mode to cumulative");
|
ESP_LOGI(TAG, "Remote command: set counter mode to cumulative");
|
||||||
break;
|
break;
|
||||||
default: // cyclic confirmed
|
default: // cyclic confirmed
|
||||||
cfg.countermode = 2;
|
cfg.countermode = 2;
|
||||||
ESP_LOGI(TAG, "Remote command: set counter mode to cyclic confirmed");
|
ESP_LOGI(TAG, "Remote command: set counter mode to cyclic confirmed");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void set_screensaver(uint8_t val) {
|
void set_screensaver(uint8_t val) {
|
||||||
ESP_LOGI(TAG, "Remote command: set screen saver to %s ", val ? "on" : "off");
|
ESP_LOGI(TAG, "Remote command: set screen saver to %s ", val ? "on" : "off");
|
||||||
switch (val) {
|
switch (val) {
|
||||||
case 1: cfg.screensaver = val; break;
|
case 1:
|
||||||
default: cfg.screensaver = 0; break;
|
cfg.screensaver = val;
|
||||||
}
|
break;
|
||||||
|
default:
|
||||||
|
cfg.screensaver = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void set_display(uint8_t val) {
|
void set_display(uint8_t val) {
|
||||||
ESP_LOGI(TAG, "Remote command: set screen to %s", val ? "on" : "off");
|
ESP_LOGI(TAG, "Remote command: set screen to %s", val ? "on" : "off");
|
||||||
switch (val) {
|
switch (val) {
|
||||||
case 1: cfg.screenon = val; break;
|
case 1:
|
||||||
default: cfg.screenon = 0; break;
|
cfg.screenon = val;
|
||||||
}
|
break;
|
||||||
|
default:
|
||||||
|
cfg.screenon = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void set_gps(uint8_t val) {
|
void set_gps(uint8_t val) {
|
||||||
ESP_LOGI(TAG, "Remote command: set GPS to %s", val ? "on" : "off");
|
ESP_LOGI(TAG, "Remote command: set GPS to %s", val ? "on" : "off");
|
||||||
switch (val) {
|
switch (val) {
|
||||||
case 1: cfg.gpsmode = val; break;
|
case 1:
|
||||||
default: cfg.gpsmode = 0; break;
|
cfg.gpsmode = val;
|
||||||
}
|
break;
|
||||||
|
default:
|
||||||
|
cfg.gpsmode = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void set_lorasf(uint8_t val) {
|
void set_lorasf(uint8_t val) {
|
||||||
ESP_LOGI(TAG, "Remote command: set LoRa SF to %d", val);
|
ESP_LOGI(TAG, "Remote command: set LoRa SF to %d", val);
|
||||||
switch_lora(val, cfg.txpower);
|
switch_lora(val, cfg.txpower);
|
||||||
};
|
};
|
||||||
|
|
||||||
void set_loraadr(uint8_t val) {
|
void set_loraadr(uint8_t val) {
|
||||||
ESP_LOGI(TAG, "Remote command: set LoRa ADR mode to %s", val ? "on" : "off");
|
ESP_LOGI(TAG, "Remote command: set LoRa ADR mode to %s", val ? "on" : "off");
|
||||||
switch (val) {
|
switch (val) {
|
||||||
case 1: cfg.adrmode = val; break;
|
case 1:
|
||||||
default: cfg.adrmode = 0; break;
|
cfg.adrmode = val;
|
||||||
}
|
break;
|
||||||
LMIC_setAdrMode(cfg.adrmode);
|
default:
|
||||||
|
cfg.adrmode = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
LMIC_setAdrMode(cfg.adrmode);
|
||||||
};
|
};
|
||||||
|
|
||||||
void set_blescan(uint8_t val) {
|
void set_blescan(uint8_t val) {
|
||||||
ESP_LOGI(TAG, "Remote command: set BLE scanner to %s", val ? "on" : "off");
|
ESP_LOGI(TAG, "Remote command: set BLE scanner to %s", val ? "on" : "off");
|
||||||
switch (val) {
|
switch (val) {
|
||||||
case 0:
|
case 0:
|
||||||
cfg.blescan = 0;
|
cfg.blescan = 0;
|
||||||
macs_ble = 0; // clear BLE counter
|
macs_ble = 0; // clear BLE counter
|
||||||
#ifdef BLECOUNTER
|
#ifdef BLECOUNTER
|
||||||
stop_BLEscan();
|
stop_BLEscan();
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
cfg.blescan = 1;
|
cfg.blescan = 1;
|
||||||
#ifdef BLECOUNTER
|
#ifdef BLECOUNTER
|
||||||
start_BLEscan();
|
start_BLEscan();
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void set_wifiant(uint8_t val) {
|
void set_wifiant(uint8_t val) {
|
||||||
ESP_LOGI(TAG, "Remote command: set Wifi antenna to %s", val ? "external" : "internal");
|
ESP_LOGI(TAG, "Remote command: set Wifi antenna to %s",
|
||||||
switch (val) {
|
val ? "external" : "internal");
|
||||||
case 1: cfg.wifiant = val; break;
|
switch (val) {
|
||||||
default: cfg.wifiant = 0; break;
|
case 1:
|
||||||
}
|
cfg.wifiant = val;
|
||||||
#ifdef HAS_ANTENNA_SWITCH
|
break;
|
||||||
antenna_select(cfg.wifiant);
|
default:
|
||||||
#endif
|
cfg.wifiant = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#ifdef HAS_ANTENNA_SWITCH
|
||||||
|
antenna_select(cfg.wifiant);
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
void set_vendorfilter(uint8_t val) {
|
void set_vendorfilter(uint8_t val) {
|
||||||
ESP_LOGI(TAG, "Remote command: set vendorfilter mode to %s", val ? "on" : "off");
|
ESP_LOGI(TAG, "Remote command: set vendorfilter mode to %s",
|
||||||
switch (val) {
|
val ? "on" : "off");
|
||||||
case 1: cfg.vendorfilter = val; break;
|
switch (val) {
|
||||||
default: cfg.vendorfilter = 0; break;
|
case 1:
|
||||||
}
|
cfg.vendorfilter = val;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
cfg.vendorfilter = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void set_rgblum(uint8_t val) {
|
void set_rgblum(uint8_t val) {
|
||||||
// Avoid wrong parameters
|
// Avoid wrong parameters
|
||||||
cfg.rgblum = (val>=0 && val<=100) ? (uint8_t) val : RGBLUMINOSITY;
|
cfg.rgblum = (val >= 0 && val <= 100) ? (uint8_t)val : RGBLUMINOSITY;
|
||||||
ESP_LOGI(TAG, "Remote command: set RGB Led luminosity %d", cfg.rgblum);
|
ESP_LOGI(TAG, "Remote command: set RGB Led luminosity %d", cfg.rgblum);
|
||||||
};
|
};
|
||||||
|
|
||||||
void set_lorapower(uint8_t val) {
|
void set_lorapower(uint8_t val) {
|
||||||
ESP_LOGI(TAG, "Remote command: set LoRa TXPOWER to %d", val);
|
ESP_LOGI(TAG, "Remote command: set LoRa TXPOWER to %d", val);
|
||||||
switch_lora(cfg.lorasf, val);
|
switch_lora(cfg.lorasf, val);
|
||||||
};
|
};
|
||||||
|
|
||||||
void get_config (uint8_t val) {
|
void get_config(uint8_t val) {
|
||||||
ESP_LOGI(TAG, "Remote command: get configuration");
|
ESP_LOGI(TAG, "Remote command: get configuration");
|
||||||
transmit((byte*)&cfg, sizeof(cfg));
|
transmit((byte *)&cfg, sizeof(cfg));
|
||||||
};
|
};
|
||||||
|
|
||||||
void get_uptime (uint8_t val) {
|
void get_uptime(uint8_t val) {
|
||||||
ESP_LOGI(TAG, "Remote command: get uptime");
|
ESP_LOGI(TAG, "Remote command: get uptime");
|
||||||
transmit((byte*)&uptimecounter, sizeof(uptimecounter));
|
transmit((byte *)&uptimecounter, sizeof(uptimecounter));
|
||||||
};
|
};
|
||||||
|
|
||||||
void get_cputemp (uint8_t val) {
|
void get_cputemp(uint8_t val) {
|
||||||
ESP_LOGI(TAG, "Remote command: get cpu temperature");
|
ESP_LOGI(TAG, "Remote command: get cpu temperature");
|
||||||
float temp = temperatureRead();
|
float temp = temperatureRead();
|
||||||
transmit((byte*)&temp, sizeof(temp));
|
transmit((byte *)&temp, sizeof(temp));
|
||||||
};
|
};
|
||||||
|
|
||||||
void get_voltage (uint8_t val) {
|
void get_voltage(uint8_t val) {
|
||||||
ESP_LOGI(TAG, "Remote command: get battery voltage");
|
ESP_LOGI(TAG, "Remote command: get battery voltage");
|
||||||
#ifdef HAS_BATTERY_PROBE
|
#ifdef HAS_BATTERY_PROBE
|
||||||
uint16_t voltage = read_voltage();
|
uint16_t voltage = read_voltage();
|
||||||
#else
|
#else
|
||||||
uint16_t voltage = 0;
|
uint16_t voltage = 0;
|
||||||
#endif
|
#endif
|
||||||
transmit((byte*)&voltage, sizeof(voltage));
|
transmit((byte *)&voltage, sizeof(voltage));
|
||||||
};
|
};
|
||||||
|
|
||||||
void get_gps (uint8_t val) {
|
void get_gps(uint8_t val) {
|
||||||
ESP_LOGI(TAG, "Remote command: get gps status");
|
ESP_LOGI(TAG, "Remote command: get gps status");
|
||||||
#ifdef HAS_GPS
|
#ifdef HAS_GPS
|
||||||
gps_read();
|
gps_read();
|
||||||
transmit((byte*)&gps_status, sizeof(gps_status));
|
transmit((byte *)&gps_status, sizeof(gps_status));
|
||||||
ESP_LOGI(TAG, "lat=%f / lon=%f | Sats=%u | HDOP=%u | Alti=%u", gps_status.latitude / 1000000, gps_status.longitude / 1000000, gps_status.satellites, gps_status.hdop, gps_status.altitude);
|
ESP_LOGI(TAG, "lat=%f / lon=%f | Sats=%u | HDOP=%u | Alti=%u",
|
||||||
#else
|
gps_status.latitude / 1000000, gps_status.longitude / 1000000,
|
||||||
ESP_LOGE(TAG, "GPS not present");
|
gps_status.satellites, gps_status.hdop, gps_status.altitude);
|
||||||
#endif
|
#else
|
||||||
|
ESP_LOGE(TAG, "GPS not present");
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
// assign previously defined functions to set of numeric remote commands
|
// assign previously defined functions to set of numeric remote commands
|
||||||
// format: opcode, function, flag (1 = do make settings persistent / 0 = don't)
|
// format: opcode, function, flag (1 = do make settings persistent / 0 = don't)
|
||||||
//
|
//
|
||||||
cmd_t table[] = {
|
cmd_t table[] = {{0x01, set_rssi, true}, {0x02, set_countmode, true},
|
||||||
{0x01, set_rssi, true},
|
{0x03, set_gps, true}, {0x04, set_display, true},
|
||||||
{0x02, set_countmode, true},
|
{0x05, set_lorasf, true}, {0x06, set_lorapower, true},
|
||||||
{0x03, set_gps, true},
|
{0x07, set_loraadr, true}, {0x08, set_screensaver, true},
|
||||||
{0x04, set_display, true},
|
{0x09, set_reset, false}, {0x0a, set_sendcycle, true},
|
||||||
{0x05, set_lorasf, true},
|
{0x0b, set_wifichancycle, true}, {0x0c, set_blescantime, true},
|
||||||
{0x06, set_lorapower, true},
|
{0x0d, set_vendorfilter, false}, {0x0e, set_blescan, true},
|
||||||
{0x07, set_loraadr, true},
|
{0x0f, set_wifiant, true}, {0x10, set_rgblum, true},
|
||||||
{0x08, set_screensaver, true},
|
{0x80, get_config, false}, {0x81, get_uptime, false},
|
||||||
{0x09, set_reset, false},
|
{0x82, get_cputemp, false}, {0x83, get_voltage, false},
|
||||||
{0x0a, set_sendcycle, true},
|
{0x84, get_gps, false}};
|
||||||
{0x0b, set_wifichancycle, true},
|
|
||||||
{0x0c, set_blescantime, true},
|
|
||||||
{0x0d, set_vendorfilter, false},
|
|
||||||
{0x0e, set_blescan, true},
|
|
||||||
{0x0f, set_wifiant, true},
|
|
||||||
{0x10, set_rgblum, true},
|
|
||||||
{0x80, get_config, false},
|
|
||||||
{0x81, get_uptime, false},
|
|
||||||
{0x82, get_cputemp, false},
|
|
||||||
{0x83, get_voltage, false},
|
|
||||||
{0x84, get_gps, false}
|
|
||||||
};
|
|
||||||
|
|
||||||
// check and execute remote command
|
// check and execute remote command
|
||||||
void rcommand(uint8_t cmd, uint8_t arg) {
|
void rcommand(uint8_t cmd, uint8_t arg) {
|
||||||
int i = sizeof(table) / sizeof(table[0]); // number of commands in command table
|
int i =
|
||||||
bool store_flag = false;
|
sizeof(table) / sizeof(table[0]); // number of commands in command table
|
||||||
while(i--) {
|
bool store_flag = false;
|
||||||
if(cmd == table[i].nam) { // check if valid command
|
while (i--) {
|
||||||
table[i].func(arg); // then execute assigned function
|
if (cmd == table[i].nam) { // check if valid command
|
||||||
if ( table[i].store ) store_flag = true; // set save flag if function needs to store configuration
|
table[i].func(arg); // then execute assigned function
|
||||||
break; // exit check loop, since command was found
|
if (table[i].store)
|
||||||
}
|
store_flag =
|
||||||
|
true; // set save flag if function needs to store configuration
|
||||||
|
break; // exit check loop, since command was found
|
||||||
}
|
}
|
||||||
if (store_flag) saveConfig(); // if save flag is set: store new configuration in NVS to make it persistent
|
}
|
||||||
|
if (store_flag)
|
||||||
|
saveConfig(); // if save flag is set: store new configuration in NVS to make
|
||||||
|
// it persistent
|
||||||
}
|
}
|
@ -6,23 +6,22 @@
|
|||||||
// RGB Led instance
|
// RGB Led instance
|
||||||
SmartLed rgb_led(LED_WS2812, 1, HAS_RGB_LED);
|
SmartLed rgb_led(LED_WS2812, 1, HAS_RGB_LED);
|
||||||
|
|
||||||
float rgb_CalcColor(float p, float q, float t)
|
float rgb_CalcColor(float p, float q, float t) {
|
||||||
{
|
if (t < 0.0f)
|
||||||
if (t < 0.0f)
|
t += 1.0f;
|
||||||
t += 1.0f;
|
if (t > 1.0f)
|
||||||
if (t > 1.0f)
|
t -= 1.0f;
|
||||||
t -= 1.0f;
|
|
||||||
|
|
||||||
if (t < 1.0f / 6.0f)
|
if (t < 1.0f / 6.0f)
|
||||||
return p + (q - p) * 6.0f * t;
|
return p + (q - p) * 6.0f * t;
|
||||||
|
|
||||||
if (t < 0.5f)
|
if (t < 0.5f)
|
||||||
return q;
|
return q;
|
||||||
|
|
||||||
if (t < 2.0f / 3.0f)
|
if (t < 2.0f / 3.0f)
|
||||||
return p + ((q - p) * (2.0f / 3.0f - t) * 6.0f);
|
return p + ((q - p) * (2.0f / 3.0f - t) * 6.0f);
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
@ -30,45 +29,41 @@ float rgb_CalcColor(float p, float q, float t)
|
|||||||
// HslColor using H, S, L values (0.0 - 1.0)
|
// HslColor using H, S, L values (0.0 - 1.0)
|
||||||
// L should be limited to between (0.0 - 0.5)
|
// L should be limited to between (0.0 - 0.5)
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
RGBColor rgb_hsl2rgb(float h, float s, float l)
|
RGBColor rgb_hsl2rgb(float h, float s, float l) {
|
||||||
{
|
RGBColor RGB_color;
|
||||||
RGBColor RGB_color;
|
float r;
|
||||||
float r;
|
float g;
|
||||||
float g;
|
float b;
|
||||||
float b;
|
|
||||||
|
|
||||||
if (s == 0.0f || l == 0.0f)
|
if (s == 0.0f || l == 0.0f) {
|
||||||
{
|
r = g = b = l; // achromatic or black
|
||||||
r = g = b = l; // achromatic or black
|
} else {
|
||||||
}
|
float q = l < 0.5f ? l * (1.0f + s) : l + s - (l * s);
|
||||||
else
|
float p = 2.0f * l - q;
|
||||||
{
|
r = rgb_CalcColor(p, q, h + 1.0f / 3.0f);
|
||||||
float q = l < 0.5f ? l * (1.0f + s) : l + s - (l * s);
|
g = rgb_CalcColor(p, q, h);
|
||||||
float p = 2.0f * l - q;
|
b = rgb_CalcColor(p, q, h - 1.0f / 3.0f);
|
||||||
r = rgb_CalcColor(p, q, h + 1.0f / 3.0f);
|
}
|
||||||
g = rgb_CalcColor(p, q, h);
|
|
||||||
b = rgb_CalcColor(p, q, h - 1.0f / 3.0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
RGB_color.R = (uint8_t)(r * 255.0f);
|
RGB_color.R = (uint8_t)(r * 255.0f);
|
||||||
RGB_color.G = (uint8_t)(g * 255.0f);
|
RGB_color.G = (uint8_t)(g * 255.0f);
|
||||||
RGB_color.B = (uint8_t)(b * 255.0f);
|
RGB_color.B = (uint8_t)(b * 255.0f);
|
||||||
|
|
||||||
return RGB_color;
|
return RGB_color;
|
||||||
}
|
}
|
||||||
|
|
||||||
void rgb_set_color(uint16_t hue) {
|
void rgb_set_color(uint16_t hue) {
|
||||||
if (hue == COLOR_NONE) {
|
if (hue == COLOR_NONE) {
|
||||||
// Off
|
// Off
|
||||||
rgb_led[0] = Rgb(0,0,0);
|
rgb_led[0] = Rgb(0, 0, 0);
|
||||||
} else {
|
} else {
|
||||||
// see http://www.workwithcolor.com/blue-color-hue-range-01.htm
|
// see http://www.workwithcolor.com/blue-color-hue-range-01.htm
|
||||||
// H (is color from 0..360) should be between 0.0 and 1.0
|
// H (is color from 0..360) should be between 0.0 and 1.0
|
||||||
// S is saturation keep it to 1
|
// S is saturation keep it to 1
|
||||||
// L is brightness should be between 0.0 and 0.5
|
// L is brightness should be between 0.0 and 0.5
|
||||||
// cfg.rgblum is between 0 and 100 (percent)
|
// cfg.rgblum is between 0 and 100 (percent)
|
||||||
RGBColor target = rgb_hsl2rgb( hue / 360.0f, 1.0f, 0.005f * cfg.rgblum);
|
RGBColor target = rgb_hsl2rgb(hue / 360.0f, 1.0f, 0.005f * cfg.rgblum);
|
||||||
//uint32_t color = target.R<<16 | target.G<<8 | target.B;
|
// uint32_t color = target.R<<16 | target.G<<8 | target.B;
|
||||||
rgb_led[0] = Rgb(target.R, target.G, target.B);
|
rgb_led[0] = Rgb(target.R, target.G, target.B);
|
||||||
}
|
}
|
||||||
// Show
|
// Show
|
||||||
|
@ -3,27 +3,26 @@
|
|||||||
|
|
||||||
// value for HSL color
|
// value for HSL color
|
||||||
// see http://www.workwithcolor.com/blue-color-hue-range-01.htm
|
// see http://www.workwithcolor.com/blue-color-hue-range-01.htm
|
||||||
#define COLOR_RED 0
|
#define COLOR_RED 0
|
||||||
#define COLOR_ORANGE 30
|
#define COLOR_ORANGE 30
|
||||||
#define COLOR_ORANGE_YELLOW 45
|
#define COLOR_ORANGE_YELLOW 45
|
||||||
#define COLOR_YELLOW 60
|
#define COLOR_YELLOW 60
|
||||||
#define COLOR_YELLOW_GREEN 90
|
#define COLOR_YELLOW_GREEN 90
|
||||||
#define COLOR_GREEN 120
|
#define COLOR_GREEN 120
|
||||||
#define COLOR_GREEN_CYAN 165
|
#define COLOR_GREEN_CYAN 165
|
||||||
#define COLOR_CYAN 180
|
#define COLOR_CYAN 180
|
||||||
#define COLOR_CYAN_BLUE 210
|
#define COLOR_CYAN_BLUE 210
|
||||||
#define COLOR_BLUE 240
|
#define COLOR_BLUE 240
|
||||||
#define COLOR_BLUE_MAGENTA 275
|
#define COLOR_BLUE_MAGENTA 275
|
||||||
#define COLOR_MAGENTA 300
|
#define COLOR_MAGENTA 300
|
||||||
#define COLOR_PINK 350
|
#define COLOR_PINK 350
|
||||||
#define COLOR_WHITE 360
|
#define COLOR_WHITE 360
|
||||||
#define COLOR_NONE 999
|
#define COLOR_NONE 999
|
||||||
|
|
||||||
struct RGBColor
|
struct RGBColor {
|
||||||
{
|
uint8_t R;
|
||||||
uint8_t R;
|
uint8_t G;
|
||||||
uint8_t G;
|
uint8_t B;
|
||||||
uint8_t B;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Exported Functions
|
// Exported Functions
|
||||||
|
@ -36,48 +36,52 @@
|
|||||||
|
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
|
||||||
uint32_t rokkit(const char * data, int len) {
|
uint32_t rokkit(const char *data, int len) {
|
||||||
uint32_t hash, tmp;
|
uint32_t hash, tmp;
|
||||||
int rem;
|
int rem;
|
||||||
|
|
||||||
if (len <= 0 || data == 0) return 0;
|
if (len <= 0 || data == 0)
|
||||||
hash = len;
|
return 0;
|
||||||
rem = len & 3;
|
hash = len;
|
||||||
len >>= 2;
|
rem = len & 3;
|
||||||
|
len >>= 2;
|
||||||
|
|
||||||
/* Main loop */
|
/* Main loop */
|
||||||
while (len > 0) {
|
while (len > 0) {
|
||||||
hash += *((uint16_t*)data);
|
hash += *((uint16_t *)data);
|
||||||
tmp = (*((uint16_t*)(data+2)) << 11) ^ hash;
|
tmp = (*((uint16_t *)(data + 2)) << 11) ^ hash;
|
||||||
hash = (hash << 16) ^ tmp;
|
hash = (hash << 16) ^ tmp;
|
||||||
data += 2*2;
|
data += 2 * 2;
|
||||||
hash += hash >> 11;
|
hash += hash >> 11;
|
||||||
len--;
|
len--;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Handle end cases */
|
/* Handle end cases */
|
||||||
switch (rem) {
|
switch (rem) {
|
||||||
case 3: hash += *((uint16_t*)data);
|
case 3:
|
||||||
hash ^= hash << 16;
|
hash += *((uint16_t *)data);
|
||||||
hash ^= ((signed char)data[2]) << 18;
|
hash ^= hash << 16;
|
||||||
hash += hash >> 11;
|
hash ^= ((signed char)data[2]) << 18;
|
||||||
break;
|
hash += hash >> 11;
|
||||||
case 2: hash += *((uint16_t*)data);
|
break;
|
||||||
hash ^= hash << 11;
|
case 2:
|
||||||
hash += hash >> 17;
|
hash += *((uint16_t *)data);
|
||||||
break;
|
hash ^= hash << 11;
|
||||||
case 1: hash += (signed char)*data;
|
|
||||||
hash ^= hash << 10;
|
|
||||||
hash += hash >> 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Force "avalanching" of final 127 bits */
|
|
||||||
hash ^= hash << 3;
|
|
||||||
hash += hash >> 5;
|
|
||||||
hash ^= hash << 4;
|
|
||||||
hash += hash >> 17;
|
hash += hash >> 17;
|
||||||
hash ^= hash << 25;
|
break;
|
||||||
hash += hash >> 6;
|
case 1:
|
||||||
|
hash += (signed char)*data;
|
||||||
|
hash ^= hash << 10;
|
||||||
|
hash += hash >> 1;
|
||||||
|
}
|
||||||
|
|
||||||
return hash;
|
/* Force "avalanching" of final 127 bits */
|
||||||
|
hash ^= hash << 3;
|
||||||
|
hash += hash >> 5;
|
||||||
|
hash ^= hash << 4;
|
||||||
|
hash += hash >> 17;
|
||||||
|
hash ^= hash << 25;
|
||||||
|
hash += hash >> 6;
|
||||||
|
|
||||||
|
return hash;
|
||||||
}
|
}
|
||||||
|
1639
src/vendor_array.h
1639
src/vendor_array.h
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user