Author Topic: DigiMouse causes too much noise  (Read 3483 times)

rubberduck

  • Newbie
  • *
  • Posts: 5
DigiMouse causes too much noise
« on: October 31, 2019, 04:07:44 am »
Hi,

I wrote a Mouse Jiggler with Attiny85 Board with a switch to (temporarly) disable it but i noticed that disabling had no effect.
The Screensaver did not work as long as the stick was attached.

Then i looked at the USB Traffic with the Device Monitoring Studio and saw that there was an update every few ms. Also the Tool "Idle Clock" showed that the maximum idle time was ~2-3 ms.

I searched around in the Library and found the causing function:
Code: [Select]
void update() {
  usbPoll();

  // instead of above code, use millis arduino system to enforce minimum reporting frequency
  unsigned long time_since_last_report = millis() - last_report_time;
  if (time_since_last_report >= (idle_rate * 4 /* in units of 4ms - usb spec stuff */)) {
    last_report_time += idle_rate * 4;
    must_report = 1;
  }

  // if the report has changed, try force an update anyway
  if (memcmp(last_built_report, last_sent_report, REPORT_SIZE)) {
    must_report = 1;
  }

  // if we want to send a report, signal the host computer to ask us for it with a usb 'interrupt'
  if (must_report) {
    if (usbInterruptIsReady()) {
      must_report = 0;
      buildReport(reportBuffer); // put data into reportBuffer
      clearMove(); // clear deltas
      usbSetInterrupt(reportBuffer, REPORT_SIZE);
    }
  }
}
I copied this function into my sketch with a new name and removed the following part:
Code: [Select]
  // instead of above code, use millis arduino system to enforce minimum reporting frequency
  unsigned long time_since_last_report = millis() - last_report_time;
  if (time_since_last_report >= (idle_rate * 4 /* in units of 4ms - usb spec stuff */)) {
    last_report_time += idle_rate * 4;
    must_report = 1;
  }
This code piece caused Updates with no change which are not sent by a normal Mouse and triggered the Idle-Timer-Reset
When removing this code part the mouse-jiggler can be switched off and on as expected, the usb device keeps connected, i think this is because of the usbPoll(); call at the start of the function. The Jiggles are visible as really small movements every 5-15 Seconds (i'm using random() for this time)

Find attached the complete MouseJiggler including the workaround. It also supports a patched Bootloader which only gets activated on button press. Pressing the Button on Pin P0 for more than 5 Seconds will reset into bootloader and if the button is still pressed on the reset time then the bootloader is active.

granzeier

  • Jr. Member
  • **
  • Posts: 73
Re: DigiMouse causes too much noise
« Reply #1 on: October 31, 2019, 04:21:22 am »
Nice work - thanks.