This commit is contained in:
vanarebane 2025-02-24 21:21:15 +02:00
parent b03f617476
commit 44f6f13fe2
5 changed files with 18 additions and 11 deletions

View File

@ -163,21 +163,26 @@
function handleNotifications(event) {
let value = event.target.value;
let buffer = event.target.value;
let a = [];
// Convert raw data bytes to hex values just for the sake of showing something.
// In the "real" world, you'd use data.getUint8, data.getUint16 or even
// TextDecoder to process raw data bytes.
for (let i = 0; i < value.byteLength; i++) {
a.push('0x' + ('00' + value.getUint8(i).toString(16)).slice(-2));
for (let i = 0; i < buffer.byteLength; i++) {
a.push('0x' + ('00' + buffer.getUint8(i).toString(16)).slice(-2));
}
console.log('>> ' + a.join(' '));
//console.log('RAW ', event.target.value);
//let data = bufferToString(value)
let data = new Uint8Array(value)
console.log(data[0]);
// let data = new DataView(buffer, 0)
//let data = new Uint8Array(buffer)
let value = buffer.getUint8(0)+(buffer.getUint8(1)*256)+(buffer.getUint8(2)*256)+(buffer.getUint8(3)*256)
if(buffer.getUint8(2) > 0){
value = (value-196096)
}
console.log(value);
//processNotificationState(data)
}

View File

@ -78,7 +78,7 @@ void MotorTask::run() {
motor.PID_velocity.I = 0;
motor.PID_velocity.D = 0.04;
motor.PID_velocity.output_ramp = 10000;
motor.PID_velocity.limit = 10;
motor.PID_velocity.limit = 100;
motor.init();

View File

@ -87,6 +87,8 @@ void BLETask::run() {
if (deviceConnected && !oldDeviceConnected) {
// do stuff here on connecting
oldDeviceConnected = deviceConnected;
delay(500);
pCharacteristic->notify(); // DOES NOT WORK
}
if (xQueueReceive(knob_state_queue_, &state, portMAX_DELAY) == pdFALSE) {
@ -96,12 +98,12 @@ void BLETask::run() {
// notify changed value
if (deviceConnected) {
if (oldval != state.current_position){
if (current_position != state.current_position){
logf(state.current_position);
pCharacteristic->setValue((uint8_t*)&state.current_position, 2);
pCharacteristic->setValue((uint8_t*)&state.current_position, 4);
pCharacteristic->notify();
oldval = state.current_position;
current_position = state.current_position;
delay(3); // bluetooth stack will go into congestion, if too many packets are sent, in 6 hours test i was able to go as low as 3ms
}
}

View File

@ -59,7 +59,7 @@ class BLETask : public Task<BLETask> {
BLECharacteristic* pCharacteristic = NULL;
// bool BLE_CONNECTED;
bool oldDeviceConnected = false;
uint8_t oldval;
int32_t current_position;
QueueHandle_t knob_state_queue_;

View File

@ -56,7 +56,7 @@ build_flags =
-DNUM_LEDS=8
-DSENSOR_MT6701=1
-DSK_STRAIN=1
-DSK_INVERT_ROTATION=0
-DSK_INVERT_ROTATION=1
-DSK_ALS=1
-DPIN_UH=25 #26