I somehow got the Electron into a state where anytime it is connected to a computer (Windows), it takes over the mouse.
I was able to put it into DFU mode and re-flash firmware v0.7.0, But as soon as I connect it via USB to a computer, it acts like a rogue mouse - cursor moves around on the screen, randomly right clicks, etc.
With the firmware re-flashed (but the device not connected to a computer), it can do an OTA flash of user code. I’ve even re-flashed v0.7.0 more than once - same problem.
But any time I connect this to a computer (I’ve tried more than one), it takes over mouse functions randomly.
If I flash my "real" project code, all is well. But I've been trying to resolve a problem with a GPS module (separate thread) and I've been playing with the TinyGPS example code, pruning it down and tuning it to see whether I'm dealing with a software issue or something related to RF interference or power noise.
The pruned down code that reliably makes the mouse go wild is:
// This #include statement was automatically added by the Spark IDE.
#include "TinyGPS.h"
#include "Serial5/Serial5.h"
SYSTEM_THREAD(ENABLED);
TinyGPS gps;
char szInfo[64];
long lastsleep = 0;
void setup() {
Serial5.begin(9600);
Serial.begin(9600);
Serial.println("Starting");
}
void loop(){
bool isValidGPS = false;
while (Serial5.available()){
char c = Serial5.read();
Serial.print(c);
if (gps.encode(c))
isValidGPS = true;
}
if (isValidGPS){
float lat, lon;
unsigned long age;
gps.f_get_position(&lat, &lon, &age);
sprintf(szInfo, "%.6f,%.6f", (lat == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : lat), (lon == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : lon));
Serial.println(szInfo);
}
else {
if (millis() > lastsleep) {
lastsleep = millis() + 2000;
Serial.println("No fix");
}
}
}
I've also tried eliminating the sprinf and replacing it with just plain Serial.print statements - no difference.
The issue @bko pointed out was unknown to me. I read that post and it seems that is the issue you are running into. There is probably a character sequence in the data you are outputting to serial that is triggering the mouse movement. I would do what that post suggests and disable serial mice via the registry.