Compare commits
9 Commits
0f80e087da
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
88fbbc103b
|
|||
|
76fe86a3bc
|
|||
| 6bf43409e4 | |||
|
2374365f0e
|
|||
|
f5f7184965
|
|||
|
|
a2eb47bc59 | ||
| c84d17a4d9 | |||
|
3fecb101b7
|
|||
|
4ce7cc1475
|
@@ -30,6 +30,17 @@
|
||||
cursor: pointer;
|
||||
display: inline-block;
|
||||
}
|
||||
#edit_config {
|
||||
position: absolute;
|
||||
background-color: var(--background-second);
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
/* height: 100%; */
|
||||
}
|
||||
#edit_config form {
|
||||
margin: 40px auto;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
@@ -66,6 +77,19 @@
|
||||
</thead>
|
||||
<tbody id="clients"></tbody>
|
||||
</table>
|
||||
<div id="edit_config" style="display:none">
|
||||
<form>
|
||||
<input type="hidden" name="boart" />
|
||||
name: <input type="text" name="name" id="edit_name" /><br/>
|
||||
stuur trim max: <input type="range" name="ch0_max" id="edit_ch0_max" max="8192" min="4096" /><br/>
|
||||
stuur trim mid: <input type="range" name="ch0_mid" id="edit_ch0_mid" max="8192" min="0" /><br/>
|
||||
stuur trim min: <input type="range" name="ch0_min" id="edit_ch0_min" max="4096" min="0" /><br/>
|
||||
motor trim max: <input type="range" name="ch1_max" id="edit_ch1_max" max="8192" min="4096" /><br/>
|
||||
motor trim mid: <input type="range" name="ch1_mid" id="edit_ch1_mid" max="8192" min="0" /><br/>
|
||||
motor trim min: <input type="range" name="ch1_min" id="edit_ch1_min" max="4096" min="0" /><br/>
|
||||
<button class="btn" onclick="updateConfig()">toepassen</button> <button class="btn" onclick="document.getElementById('edit_config').style.display = 'none'">anulleren</button>
|
||||
</form>
|
||||
</div>
|
||||
</main>
|
||||
<script>
|
||||
const passEl = document.getElementById('pass');
|
||||
@@ -174,7 +198,14 @@
|
||||
|
||||
function getBoatLog(e)
|
||||
{
|
||||
alert("loggy log");
|
||||
// let cmd = prompt("enter command");
|
||||
let boat = getDataFomEl(e.target);
|
||||
// console.log("send cmd", boat, cmd);
|
||||
// conn.send(passEl.value + ";sendcmd;" + boat['id'] + ";" + cmd);
|
||||
|
||||
conn.send(passEl.value + ";sendcmd;" + boat['id'] + ";servotrim:0");
|
||||
conn.send(passEl.value + ";sendcmd;" + boat['id'] + ";servotrim:1");
|
||||
|
||||
}
|
||||
|
||||
function reqBoats()
|
||||
@@ -307,4 +338,4 @@
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
||||
@@ -130,13 +130,16 @@ async def getlog(client, data):
|
||||
|
||||
async def sendcmd(data):
|
||||
"""send command to boat"""
|
||||
for b in Boats:
|
||||
if b['id'] == data[2]:
|
||||
del data[0]
|
||||
del data[1]
|
||||
data = ";".join(data)
|
||||
await sendToBoat(b, data)
|
||||
return
|
||||
if len(data) > 3:
|
||||
for b in Boats:
|
||||
if b['id'] == data[2]:
|
||||
del data[2]
|
||||
del data[1]
|
||||
del data[0]
|
||||
print(data)
|
||||
data = ";".join(data)
|
||||
await sendToBoat(b, data + "\n")
|
||||
return
|
||||
|
||||
async def kick_client(clientId):
|
||||
"""kick a client"""
|
||||
@@ -157,7 +160,7 @@ async def on_message(message, client):
|
||||
data = message.replace('\n', '').split(';')
|
||||
if data[0] != client["id"]:
|
||||
print("invalid id: " + str(data[0]) + " != " + str(client["id"]))
|
||||
else:
|
||||
elif len(data) >= 2:
|
||||
if data[1] == "boats":
|
||||
await echo_boats(client)
|
||||
elif data[1] == "ctrl":
|
||||
@@ -190,6 +193,8 @@ async def on_message(message, client):
|
||||
print("WARN: invalid command (admin): '" + data[1] + "'")
|
||||
else:
|
||||
print("WARN: invalid command (" + client['id'] + "): '" + data[1] + "'")
|
||||
else:
|
||||
print("WARN: to little arguments")
|
||||
|
||||
async def new_client(clientId, ws):
|
||||
"""handler for every new client connection"""
|
||||
|
||||
@@ -68,6 +68,38 @@ int cmd_contrl(char* line, void* cli)
|
||||
return out;
|
||||
}
|
||||
|
||||
// servotrim:0 410;614;819
|
||||
int cmd_servotrim(char* line, void* cli)
|
||||
{
|
||||
uint8_t ch;
|
||||
int out = 0;
|
||||
char msg[40];
|
||||
|
||||
char* arg = getNextArg(line, ':');
|
||||
if (arg == NULL)
|
||||
{
|
||||
snprintf(&msg[0], 40, "no arguments given, expect at least one\n");
|
||||
CLI_stringOut((CLI_t*)cli, &msg[0]);
|
||||
out = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
readInt(arg, &ch);
|
||||
arg = getNextArg(arg, ' ');
|
||||
if (arg != NULL)
|
||||
{
|
||||
readInt(arg, &Servos[ch].pulse_min);
|
||||
arg = getNextArg(arg, ':');
|
||||
readInt(arg, &Servos[ch].pulse_mid);
|
||||
arg = getNextArg(arg, ':');
|
||||
readInt(arg, &Servos[ch].pulse_max);
|
||||
}
|
||||
snprintf(&msg[0], 40, "servo ch %d: %d:%d:%d\n", Servos[ch].pulse_min, Servos[ch].pulse_mid, Servos[ch].pulse_max);
|
||||
CLI_stringOut((CLI_t*)cli, &msg[0]);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
extern volatile bool running;
|
||||
int cmd_shutdown(char* line, void* cli)
|
||||
{
|
||||
@@ -161,6 +193,7 @@ const CMD_t Commands[] = {
|
||||
#if TARGET == TARGET_RX
|
||||
{ "d", &cmd_contrl },
|
||||
{ "status", &cmd_status },
|
||||
{ "servotrim", &cmd_servotrim},
|
||||
#elif TARGET == TARGET_TX
|
||||
{ "led", &setLed },
|
||||
#endif
|
||||
|
||||
@@ -111,7 +111,7 @@ void app_main() {
|
||||
#if TARGET == TARGET_RX
|
||||
CLI_t cli_ws_client;
|
||||
#elif TARGET == TARGET_TX
|
||||
CLI_t cli_ws_client[3];
|
||||
CLI_t cli_ws_client[3];
|
||||
#endif
|
||||
|
||||
LOG_D("main: main loop starting in state %d", MainState);
|
||||
@@ -293,7 +293,9 @@ void app_main() {
|
||||
led_setRGB(0, 0, 0);
|
||||
#endif
|
||||
|
||||
#if TARGET == TARGET_RX
|
||||
servo_deinit();
|
||||
#endif
|
||||
CLI_deinit(&cli_uart);
|
||||
CMDList_deinit(cmdList);
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
#define SERVO_DUTY_MIN ( 410) // 2**13 * (1000/20000) // 1000us of the 20ms
|
||||
#define SERVO_DUTY_MAX ( 819) // 2**13 * (2000/20000) // 2000us of the 20ms
|
||||
// #define SERVO_DUTY_MAX (1024) // 2**13 * (2500/20000) // 2500us of the 20ms
|
||||
#define SERVO_DUTY_MID ( 614) // 2**13 * (1500/20000) // 2500us of the 20ms
|
||||
#define SERVO_DUTY_MID ( 614) // 2**13 * (1500/20000) // 1500us of the 20ms
|
||||
|
||||
#define SERVO_DUTY_DIFF (SERVO_DUTY_MAX - SERVO_DUTY_MIN)
|
||||
|
||||
@@ -27,8 +27,8 @@ void servo_init(void)
|
||||
Servos[0].ledc_ch = LEDC_CHANNEL_0;
|
||||
Servos[0].pulse_min = SERVO_DUTY_MIN;
|
||||
Servos[0].pulse_mid = SERVO_DUTY_MID;
|
||||
Servos[0].pulse_max = SERVO_DUTY_MAX - 100;
|
||||
Servos[0].mid_delay = 10;
|
||||
Servos[0].pulse_max = SERVO_DUTY_MAX;
|
||||
Servos[0].mid_delay = 0;
|
||||
Servos[0].mid_delay_timer = 0;
|
||||
Servos[0].reversed = false;
|
||||
|
||||
@@ -37,9 +37,9 @@ void servo_init(void)
|
||||
Servos[1].pulse_min = SERVO_DUTY_MIN;
|
||||
Servos[1].pulse_mid = SERVO_DUTY_MID;
|
||||
Servos[1].pulse_max = SERVO_DUTY_MAX;
|
||||
Servos[1].mid_delay = 0;
|
||||
Servos[1].mid_delay = 5;
|
||||
Servos[1].mid_delay_timer = 0;
|
||||
Servos[1].reversed = false;
|
||||
Servos[1].reversed = true;
|
||||
|
||||
// Prepare and then apply the LEDC PWM timer configuration
|
||||
ledc_timer_config_t ledc_timer = {
|
||||
@@ -79,25 +79,19 @@ void servo_deinit(void)
|
||||
void servo_set(uint8_t ch, uint8_t pos)
|
||||
{
|
||||
if (Servos_ch_swap)
|
||||
{
|
||||
if (ch == 0)
|
||||
{
|
||||
ch = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
ch = 0;
|
||||
}
|
||||
{
|
||||
ch = (ch == 0) ? 1 : 0;
|
||||
}
|
||||
|
||||
double pos_double = ((int16_t)pos - 128) / 128.0;
|
||||
|
||||
if (Servos[ch].reversed)
|
||||
{
|
||||
pos = -((int16_t)pos) + 255;
|
||||
pos_double = -pos_double;
|
||||
}
|
||||
|
||||
double pos_double = ((double) pos) - 128;
|
||||
|
||||
if (pos_double < 0)
|
||||
if (pos_double < 0.0)
|
||||
{
|
||||
if (Servos[ch].mid_delay_timer > 0)
|
||||
{
|
||||
@@ -109,7 +103,7 @@ void servo_set(uint8_t ch, uint8_t pos)
|
||||
Servos[ch].mid_delay_timer = -Servos[ch].mid_delay;
|
||||
}
|
||||
}
|
||||
else if (pos_double > 0)
|
||||
else if (pos_double > 0.0)
|
||||
{
|
||||
if (Servos[ch].mid_delay_timer < 0)
|
||||
{
|
||||
@@ -125,12 +119,12 @@ void servo_set(uint8_t ch, uint8_t pos)
|
||||
uint32_t duty;
|
||||
if (pos_double > 0.0)
|
||||
{
|
||||
duty = (pos_double/128.0 * (Servos[ch].pulse_max - Servos[ch].pulse_mid)) + Servos[ch].pulse_mid;
|
||||
duty = (pos_double * (Servos[ch].pulse_max - Servos[ch].pulse_mid)) + Servos[ch].pulse_mid;
|
||||
}
|
||||
else
|
||||
{
|
||||
duty = (pos_double/128.0 * (Servos[ch].pulse_mid - Servos[ch].pulse_min)) + Servos[ch].pulse_mid;
|
||||
}
|
||||
duty = (pos_double * (Servos[ch].pulse_mid - Servos[ch].pulse_min)) + Servos[ch].pulse_mid;
|
||||
}
|
||||
|
||||
if (duty < SERVO_DUTY_MIN)
|
||||
{
|
||||
|
||||
@@ -42,7 +42,7 @@ static void ws_event_handler(void* handler_args, esp_event_base_t base, int32_t
|
||||
break;
|
||||
|
||||
case WEBSOCKET_EVENT_DATA:
|
||||
// LOG_D("ws_event_handler: data recieved opcode %d", data->op_code);
|
||||
LOG_D("ws_event_handler: data recieved opcode %d", data->op_code);
|
||||
if (data->op_code == 0x02)
|
||||
{
|
||||
LOG_D("ws_event_handler: binary data recieved");
|
||||
@@ -212,7 +212,7 @@ void ws_sendData(ws_client_t client)
|
||||
{
|
||||
if ((client->txBuffer_wp > 0) && esp_websocket_client_is_connected(client->handle))
|
||||
{
|
||||
// LOG_D("ws_sendData: (%d b) '%.*s'", client->txBuffer_wp, client->txBuffer_wp, (char *)&client->txBuffer[0]);
|
||||
LOG_D("ws_sendData: (%d b) '%.*s'", client->txBuffer_wp, client->txBuffer_wp, (char *)&client->txBuffer[0]);
|
||||
esp_websocket_client_send_text(client->handle, (char *)&client->txBuffer[0], client->txBuffer_wp, 1000 * portTICK_PERIOD_MS);
|
||||
client->txBuffer_wp = 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user