HOWTO use Mouse in C file?


I am writing an app that uses HID mouse to control connected PC. I have tested my code in *.ino file and it worked.

Now I've decided to move mouse code to hw_mouse.h/c files (located in the same folder as *.ino file).

In hw_mouse.h I have:

#ifndef __HW_MOUSE_H__
#define __HW_MOUSE_H__

void Hw_initMouse(void);


while in hw_mouse.c I have:

#include "Arduino.h"
#include "hw_mouse.h"

void Hw_initMouse(void) {

In *.ino file I have:

#include "hw_mouse.h"

void setup() {

void loop() {

During compilation I get following error:

hw_mouse.c:5:3: error: 'Mouse' undeclared (first use in this function)

Now question is: What should I include in hw_mouse.h or to change in code to have USB HID mouse working?

Thanks in advance for a hints.

or to change in code to have USB HID mouse working?

The first thing to change is the extension. Interfacing C++ and C is NOT a trivial task. Don't go there unnecessarily.

Hi Paul,

thanks for your comment.
It really helped when *.c file changed to *.cpp.

At the same time I have found another thing - it might be helpful for others.

As I started working on my separate files I tried how actually libraries importing work.
It happened that hw_mouse.c/h were that lib and got imported.
When I changed extension for the C file (in my folder with INO file) I was still getting the same error as before.
It happened because #include was loading C file from C:\Users<user_name>\Documents\Arduino\libraries.

After deleting this useless test code from there everything compiles now.