forked from apache/nuttx-apps
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7515553
commit 8a177cd
Showing
11 changed files
with
1,528 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/Kconfig |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
############################################################################ | ||
# apps/games/Make.defs | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. The | ||
# ASF licenses this file to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance with the | ||
# License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
# | ||
############################################################################ | ||
|
||
include $(wildcard $(APPDIR)/games/*/Make.defs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
############################################################################ | ||
# apps/games/Makefile | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. The | ||
# ASF licenses this file to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance with the | ||
# License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
# | ||
############################################################################ | ||
|
||
MENUDESC = "Games" | ||
|
||
include $(APPDIR)/Directory.mk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# | ||
# For a description of the syntax of this configuration file, | ||
# see the file kconfig-language.txt in the NuttX tools repository. | ||
# | ||
|
||
config GAMES_SHIFT | ||
bool "Shift Game" | ||
default n | ||
---help--- | ||
Enable Shift games. Shift is a brick game, like a mix | ||
between Tetris and Crush Candy. The inspiration came | ||
from a Shift game that was available for Android in the | ||
F-Droid store. The original game source code still here: | ||
https://github.com/boombuler/Shift/ but the game only works | ||
for old Android versions (4.x). | ||
NOTE: The source code here is not based on that code from | ||
above github. | ||
|
||
if GAMES_SHIFT | ||
|
||
config GAMES_SHIFT_PROGNAME | ||
string "Program name" | ||
default "shift" | ||
---help--- | ||
This is the name of the program that will be used when the NSH ELF | ||
program is installed. | ||
|
||
config GAMES_SHIFT_PRIORITY | ||
int "Shift Game task priority" | ||
default 100 | ||
|
||
config GAMES_SHIFT_STACKSIZE | ||
int "Shift Game stack size" | ||
default DEFAULT_TASK_STACKSIZE | ||
|
||
# | ||
# Input Device Selection | ||
# | ||
|
||
choice | ||
prompt "Input Device (Joystick, Gesture Sensor, etc)" | ||
default GAMES_SHIFT_USE_CONSOLEKEY | ||
|
||
config GAMES_SHIFT_USE_CONSOLEKEY | ||
bool "Serial Console as Input" | ||
depends on !INPUT_DJOYSTICK && !SENSORS_APDS9960 | ||
|
||
config GAMES_SHIFT_USE_DJOYSTICK | ||
bool "Discrete Joystick as Input" | ||
depends on INPUT_DJOYSTICK | ||
|
||
config GAMES_SHIFT_USE_GESTURE | ||
bool "Gesture Sensor APDS-9960 as Input" | ||
depends on SENSORS_APDS9960 | ||
|
||
endchoice | ||
|
||
endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
############################################################################ | ||
# apps/games/shift/Make.defs | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. The | ||
# ASF licenses this file to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance with the | ||
# License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
# | ||
############################################################################ | ||
|
||
ifeq ($(CONFIG_GAMES_SHIFT),y) | ||
CONFIGURED_APPS += $(APPDIR)/games/shift | ||
endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
############################################################################ | ||
# apps/games/shift/Makefile | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. The | ||
# ASF licenses this file to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance with the | ||
# License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
# | ||
############################################################################ | ||
|
||
include $(APPDIR)/Make.defs | ||
|
||
# Shift game info | ||
|
||
PROGNAME = $(CONFIG_GAMES_SHIFT_PROGNAME) | ||
PRIORITY = $(CONFIG_GAMES_SHIFT_PRIORITY) | ||
STACKSIZE = $(CONFIG_GAMES_SHIFT_STACKSIZE) | ||
MODULE = $(CONFIG_GAMES_SHIFT) | ||
|
||
# Shift game application | ||
|
||
MAINSRC = shift_main.c | ||
|
||
include $(APPDIR)/Application.mk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
/**************************************************************************** | ||
* apps/games/shift/shift_input_console.h | ||
* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. The | ||
* ASF licenses this file to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance with the | ||
* License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
****************************************************************************/ | ||
|
||
/**************************************************************************** | ||
* Included Files | ||
****************************************************************************/ | ||
|
||
#include <nuttx/config.h> | ||
#include <termios.h> | ||
|
||
#include "shift_inputs.h" | ||
|
||
/**************************************************************************** | ||
* Preprocessor Definitions | ||
****************************************************************************/ | ||
|
||
/* Termios functions to have getch on Linux/NuttX */ | ||
|
||
static struct termios g_old; | ||
static struct termios g_new; | ||
|
||
/* Initialize g_new terminal I/O settings */ | ||
|
||
void init_termios(int echo) | ||
{ | ||
tcgetattr(0, &g_old); /* grab old terminal i/o settings */ | ||
g_new = g_old; /* use old settings as starting */ | ||
g_new.c_lflag &= ~ICANON; /* disable buffered I/O */ | ||
g_new.c_lflag &= ~ECHO; /* disable ECHO bit */ | ||
g_new.c_lflag |= echo ? ECHO : 0; /* set echo mode if requested */ | ||
tcsetattr(0, TCSANOW, &g_new); /* apply terminal I/O settings */ | ||
} | ||
|
||
/* Restore g_old terminal i/o settings */ | ||
|
||
void reset_termios(void) | ||
{ | ||
tcsetattr(0, TCSANOW, &g_old); | ||
} | ||
|
||
/* Read 1 character - echo defines echo mode */ | ||
|
||
char getch_(int echo) | ||
{ | ||
char ch; | ||
|
||
init_termios(echo); | ||
ch = getchar(); | ||
reset_termios(); | ||
|
||
return ch; | ||
} | ||
|
||
/* Read 1 character without echo getch() function definition. */ | ||
|
||
char getch(void) | ||
{ | ||
return getch_(0); | ||
} | ||
|
||
/**************************************************************************** | ||
* dev_input_init | ||
****************************************************************************/ | ||
|
||
int dev_input_init(FAR struct input_state_s *dev) | ||
{ | ||
init_termios(0); | ||
|
||
return OK; | ||
} | ||
|
||
/**************************************************************************** | ||
* dev_read_input | ||
****************************************************************************/ | ||
|
||
int dev_read_input(FAR struct input_state_s *dev) | ||
{ | ||
char ch; | ||
|
||
/* Arrows keys return three bytes: 27 91 [65-68] */ | ||
|
||
if ((ch = getch()) == 27) | ||
{ | ||
if ((ch = getch()) == 91) | ||
{ | ||
ch = getch(); | ||
if (ch == 65) | ||
{ | ||
dev->dir = DIR_UP; | ||
} | ||
else if (ch == 66) | ||
{ | ||
dev->dir = DIR_DOWN; | ||
} | ||
else if (ch == 67) | ||
{ | ||
dev->dir = DIR_RIGHT; | ||
} | ||
else if (ch == 68) | ||
{ | ||
dev->dir = DIR_LEFT; | ||
} | ||
} | ||
else | ||
{ | ||
dev->dir = DIR_NONE; | ||
} | ||
} | ||
else | ||
{ | ||
dev->dir = DIR_NONE; | ||
} | ||
|
||
return OK; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/**************************************************************************** | ||
* apps/games/shift/shift_input_gesture.h | ||
* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. The | ||
* ASF licenses this file to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance with the | ||
* License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
****************************************************************************/ | ||
|
||
/**************************************************************************** | ||
* Included Files | ||
****************************************************************************/ | ||
|
||
#include <nuttx/config.h> | ||
|
||
#include <nuttx/sensors/apds9960.h> | ||
|
||
#include "shift_inputs.h" | ||
|
||
/**************************************************************************** | ||
* Preprocessor Definitions | ||
****************************************************************************/ | ||
|
||
#define APDS9960_DEVNAME "/dev/gest0" | ||
|
||
/**************************************************************************** | ||
* dev_input_init | ||
****************************************************************************/ | ||
|
||
int dev_input_init(FAR struct input_state_s *dev) | ||
{ | ||
/* Open the gesture sensor APDS9960 */ | ||
|
||
dev->fd_gest = open(APDS9960_DEVNAME, O_RDONLY | O_NONBLOCK); | ||
if (dev->fd_gest < 0) | ||
{ | ||
int errcode = errno; | ||
printf("ERROR: Failed to open %s: %d\n", APDS9960_DEVNAME, errcode); | ||
return -ENODEV; | ||
} | ||
|
||
return OK; | ||
} | ||
|
||
/**************************************************************************** | ||
* dev_read_input | ||
****************************************************************************/ | ||
|
||
int dev_read_input(FAR struct input_state_s *dev) | ||
{ | ||
int nbytes; | ||
uint8_t gest; | ||
|
||
nbytes = read(dev->fd_gest, (void *)&gest, sizeof(gest)); | ||
if (nbytes == sizeof(gest)) | ||
{ | ||
dev->dir = gest; | ||
} | ||
else | ||
{ | ||
dev->dir = DIR_NONE; | ||
return -EINVAL; | ||
} | ||
|
||
return OK; | ||
} | ||
|
Oops, something went wrong.