Skip to content

Commit

Permalink
Merge pull request #64 from asterics/MPRLS-spike-removal
Browse files Browse the repository at this point in the history
Mprls spike removal
  • Loading branch information
ChrisVeigl authored Jul 14, 2023
2 parents f511732 + c13d5f6 commit 8bfdd35
Show file tree
Hide file tree
Showing 4 changed files with 382 additions and 259 deletions.
50 changes: 25 additions & 25 deletions FLipWare/FLipWare.ino
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,11 @@ struct SensorData sensorData {
};

struct I2CSensorValues sensorValues {
.xRaw=0, .yRaw=0, .pressure=0,
.xRaw=0, .yRaw=0, .pressure=512,
.calib_now=CALIBRATION_PERIOD // calibrate sensors after startup !
};


mutex_t sensorDataMutex; // for synchronizsation of data access between cores
struct SlotSettings slotSettings; // contains all slot settings
uint8_t workingmem[WORKINGMEM_SIZE]; // working memory (command parser, IR-rec/play)
uint8_t actSlot = 0; // number of current slot
Expand All @@ -110,7 +109,7 @@ uint8_t addonUpgrade = BTMODULE_UPGRADE_IDLE; // if not "idle": we are upgrading
void setup() {

// prepare synchronizsation of sensor data exchange between cores
mutex_init(&sensorDataMutex);
mutex_init(&(sensorValues.sensorDataMutex));

//load slotSettings
memcpy(&slotSettings,&defaultSlotSettings,sizeof(struct SlotSettings));
Expand Down Expand Up @@ -181,11 +180,11 @@ void loop() {
lastInteractionUpdate = millis();

// get current sensor data from core1
mutex_enter_blocking(&sensorDataMutex);
mutex_enter_blocking(&(sensorValues.sensorDataMutex));
sensorData.xRaw=sensorValues.xRaw;
sensorData.yRaw=sensorValues.yRaw;
sensorData.pressure=sensorValues.pressure;
mutex_exit(&sensorDataMutex);
mutex_exit(&(sensorValues.sensorDataMutex));

if (StandAloneMode) {

Expand Down Expand Up @@ -240,39 +239,40 @@ void setup1() {
@return none
*/
void loop1() {
static unsigned long lastUpdate=0;
static uint32_t lastMPRLS_ts=0;

// check if there is a message from the other core (sensorboard change, profile ID)
if (rp2040.fifo.available()) {
setSensorBoard(rp2040.fifo.pop());
}

// if the Data Ready Pin of NAU chip signals new data: get force sensor values
if (digitalRead(DRDY_PIN) == HIGH) {
readForce(&sensorValues);
}

// check if the Data Ready Pin of the NAU chip signals new data, if yes: get sensor values!
if (digitalRead(DRDY_PIN) == HIGH)
{
getSensorValues();
// if desired sampling period for MPRLS pressure sensor passed: get pressure sensor value
if (millis()-lastMPRLS_ts >= 1000/MPRLS_SAMPLINGRATE) {
lastMPRLS_ts=millis();
readPressure(&sensorValues);
}

// if calibration running: update calibration counter
if (sensorValues.calib_now) {
sensorValues.calib_now--;
// calibrate sensors in the middle of the calibration period
if(sensorValues.calib_now==CALIBRATION_PERIOD/2) {
calibrateSensors();
}
}


// reset FlipMouse if sensors don't deliver data for several seconds (interface hangs?)
if (!checkSensorWatchdog()) {
//Serial.println("WATCHDOG !!");
watchdog_reboot(0, 0, 10);
while(1);
}

if (millis() >= lastUpdate + UPDATE_INTERVAL) {
lastUpdate = millis();

// get current sensor values
mutex_enter_blocking(&sensorDataMutex);
readPressure(&sensorValues);
readForce(&sensorValues);
mutex_exit(&sensorDataMutex);

// update calibration counter (if calibration running)
if (sensorValues.calib_now) sensorValues.calib_now--;

}

delay(1); // core1: sleep a bit ...
}
6 changes: 4 additions & 2 deletions FLipWare/FlipWare.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@
#include "bluetooth.h"
#include "hid_hal.h"

#define VERSION_STRING "v3.3.1"
#define VERSION_STRING "v3.4"

// V3.4: improved MPRLS pressure sensor processing
// V3.3.1: fixed IR-command name bug
// V3.3: added Bluetooth Joystick
// V3.2: changed pinning to PCB v3.2
Expand Down Expand Up @@ -84,7 +85,7 @@
*/
#define UPDATE_INTERVAL 5 // update interval for performing HID actions (in milliseconds)
#define DEFAULT_CLICK_TIME 8 // time for mouse click (loop iterations from press to release)
#define CALIBRATION_PERIOD 200 // approx. 200*UPDATE_INTERVAL = 1sec calibration time
#define CALIBRATION_PERIOD 1000 // approx. 1000ms calibration time

// RAM buffers and memory constraints
#define WORKINGMEM_SIZE 300 // reserved RAM for working memory (command parser, IR-rec/play)
Expand Down Expand Up @@ -152,6 +153,7 @@ struct I2CSensorValues {
int xRaw,yRaw;
int pressure;
uint16_t calib_now;
mutex_t sensorDataMutex; // for synchronization of data access between cores
};

/**
Expand Down
Loading

0 comments on commit 8bfdd35

Please sign in to comment.