Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
See what's new at GitLab
4
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
D
dance-ctl
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Packages & Registries
Packages & Registries
Package Registry
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Martin Natano
dance-ctl
Commits
20377810
Commit
20377810
authored
Dec 14, 2019
by
Martin Natano
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
initial commi
parents
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
110 additions
and
0 deletions
+110
-0
dance_ctl.c/dance_ctl.c.ino
dance_ctl.c/dance_ctl.c.ino
+65
-0
dance_ctl_kb.c/dance_ctl_kb.c.ino
dance_ctl_kb.c/dance_ctl_kb.c.ino
+45
-0
No files found.
dance_ctl.c/dance_ctl.c.ino
0 → 100644
View file @
20377810
#include "HID.h"
static
const
uint8_t
hidReportDescriptor
[]
PROGMEM
=
{
0x05
,
0x01
,
// USAGE_PAGE (Generic Desktop)
0x09
,
0x05
,
// USAGE (Game Pad)
0xa1
,
0x01
,
// COLLECTION (Application)
0xa1
,
0x00
,
// COLLECTION (Physical)
0x85
,
0x03
,
// REPORT_ID (3)
0x05
,
0x09
,
// USAGE_PAGE (Button)
0x19
,
0x01
,
// USAGE_MINIMUM (Button 1)
0x29
,
0x06
,
// USAGE_MAXIMUM (Button 6)
0x15
,
0x00
,
// LOGICAL_MINIMUM (0)
0x25
,
0x01
,
// LOGICAL_MAXIMUM (1)
0x75
,
0x01
,
// REPORT_SIZE (1)
0x95
,
0x06
,
// REPORT_COUNT (6)
0x81
,
0x02
,
// INPUT (Data, Var, Abs)
0x75
,
0x01
,
// REPORT_SIZE (1)
0x95
,
0x02
,
// REPORT_COUNT (2)
0x01
,
0x01
,
// INPUT (Constant)
0xc0
,
// END_COLLECTION
0xc0
,
// END_COLLECTION
};
#define NBUTTONS 6
static
const
int
button_pins
[
NBUTTONS
]
=
{
7
,
8
,
9
,
10
,
11
,
12
};
void
setup
()
{
int
i
;
pinMode
(
LED_BUILTIN
,
OUTPUT
);
for
(
i
=
0
;
i
<
NBUTTONS
;
i
++
)
pinMode
(
button_pins
[
i
],
INPUT_PULLUP
);
static
HIDSubDescriptor
node
(
hidReportDescriptor
,
sizeof
(
hidReportDescriptor
));
HID
().
AppendDescriptor
(
&
node
);
}
// the loop function runs over and over again forever
void
loop
()
{
uint8_t
reportData
;
static
uint8_t
previousReportData
;
int
i
;
reportData
=
0
;
for
(
i
=
0
;
i
<
NBUTTONS
;
i
++
)
{
int
pressed
=
!
digitalRead
(
button_pins
[
i
]);
if
(
pressed
)
reportData
|=
(
1
<<
i
);
}
if
(
reportData
!=
previousReportData
)
{
HID
().
SendReport
(
0x03
,
&
reportData
,
sizeof
(
reportData
));
if
(
reportData
)
digitalWrite
(
LED_BUILTIN
,
HIGH
);
else
digitalWrite
(
LED_BUILTIN
,
LOW
);
previousReportData
=
reportData
;
}
delayMicroseconds
(
1000
);
}
dance_ctl_kb.c/dance_ctl_kb.c.ino
0 → 100644
View file @
20377810
#include "Keyboard.h"
#define NBUTTONS 4
const
int
button_pins
[
NBUTTONS
]
=
{
9
,
10
,
11
,
12
};
const
int
button_keys
[
NBUTTONS
]
=
{
KEY_LEFT_ARROW
,
KEY_DOWN_ARROW
,
KEY_UP_ARROW
,
KEY_RIGHT_ARROW
};
int
button_states
;
void
setup
()
{
int
i
;
pinMode
(
LED_BUILTIN
,
OUTPUT
);
for
(
i
=
0
;
i
<
NBUTTONS
;
i
++
)
pinMode
(
button_pins
[
i
],
INPUT_PULLUP
);
Keyboard
.
begin
();
Serial
.
println
(
"hello"
);
}
// the loop function runs over and over again forever
void
loop
()
{
int
i
;
for
(
i
=
0
;
i
<
NBUTTONS
;
i
++
)
{
int
pressed
=
!
digitalRead
(
button_pins
[
i
]);
//Serial.println(pressed);
if
(
pressed
&&
((
1
<<
i
)
&
button_states
)
==
0
)
{
//Serial.print("button pressed: ");
//Serial.println(i);
Keyboard
.
press
(
button_keys
[
i
]);
button_states
|=
(
1
<<
i
);
}
else
if
(
!
pressed
&&
((
1
<<
i
)
&
button_states
)
!=
0
)
{
Keyboard
.
release
(
button_keys
[
i
]);
//Serial.print("button released: ");
//Serial.println(i);
button_states
&=
~
(
1
<<
i
);
}
}
if
(
button_states
)
digitalWrite
(
LED_BUILTIN
,
HIGH
);
else
digitalWrite
(
LED_BUILTIN
,
LOW
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment