Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
F
fwatch
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
8
Issues
8
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
fwatch
Commits
cdba83fe
Commit
cdba83fe
authored
Sep 11, 2014
by
Grzegorz Daniluk
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
who wants a game for f*watch ?
parent
2a9d5974
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
252 additions
and
0 deletions
+252
-0
bitmaps.c
sw/bitmaps/bitmaps.c
+46
-0
bitmaps.h
sw/bitmaps/bitmaps.h
+1
-0
game_ico.bmp
sw/bitmaps/game_ico.bmp
+0
-0
Makefile
sw/freertos/Makefile
+1
-0
app_list.h
sw/freertos/src/apps/app_list.h
+1
-0
game.c
sw/freertos/src/apps/game.c
+202
-0
menu_struct.c
sw/freertos/src/apps/menu_struct.c
+1
-0
No files found.
sw/bitmaps/bitmaps.c
View file @
cdba83fe
...
...
@@ -329,6 +329,52 @@ static const uint8_t battery_data[] = {
0x00
};
const
struct
rle_bitmap
battery
=
{
15
,
12
,
battery_data
};
static
const
uint8_t
game_ico_data
[]
=
{
0x8f
,
0x0c
,
0x81
,
0x0c
,
0x81
,
0x0c
,
0x81
,
0x0c
,
0x81
,
0x02
,
0x83
,
0x05
,
0x81
,
0x01
,
0x85
,
0x04
,
0x81
,
0x00
,
0x87
,
0x03
,
0x81
,
0x00
,
0x87
,
0x03
,
0x81
,
0x00
,
0x87
,
0x03
,
0x81
,
0x00
,
0x87
,
0x03
,
0x81
,
0x01
,
0x85
,
0x04
,
0x81
,
0x02
,
0x83
,
0x05
,
0x81
,
0x0c
,
0x8f
};
const
struct
rle_bitmap
game_ico
=
{
15
,
15
,
game_ico_data
};
static
const
uint8_t
battery_charging_data
[]
=
{
0x8d
,
0x00
,
...
...
sw/bitmaps/bitmaps.h
View file @
cdba83fe
...
...
@@ -12,6 +12,7 @@ struct rle_bitmap
extern
const
struct
rle_bitmap
comp_circle
;
extern
const
struct
rle_bitmap
battery
;
extern
const
struct
rle_bitmap
game_ico
;
extern
const
struct
rle_bitmap
battery_charging
;
extern
const
struct
rle_bitmap
gps_searching
;
extern
const
struct
rle_bitmap
comp_ico
;
...
...
sw/bitmaps/game_ico.bmp
0 → 100644
View file @
cdba83fe
774 Bytes
sw/freertos/Makefile
View file @
cdba83fe
...
...
@@ -192,6 +192,7 @@ src/apps/application.c \
src/apps/clock.c
\
src/apps/example_app.c
\
src/apps/compass.c
\
src/apps/game.c
\
src/apps/menu.c
\
src/apps/menu_struct.c
\
src/main.c
\
...
...
sw/freertos/src/apps/app_list.h
View file @
cdba83fe
...
...
@@ -34,6 +34,7 @@ extern application menu;
extern
application
clock_app
;
extern
application
example
;
extern
application
compass
;
extern
application
game
;
#endif
/* APP_LIST_H */
sw/freertos/src/apps/game.c
0 → 100644
View file @
cdba83fe
/*
* Copyright (C) 2014 Julian Lewis
* @author Grzegorz Daniluk <grzegorz.daniluk@cern.ch>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* Very simple "game"
*/
#include "application.h"
#include "widgets/status_bar.h"
#include <drivers/LSM303C/lsm303c.h>
#include <sincos.h>
#include <usbdesc.h>
#define S_WIN_X0 5
#define S_WIN_Y0 25
#define S_WIN_X1 122
#define S_WIN_Y1 122
#define BALL_R 5
#define STEP 10
#define FACT_MOD 4
#define SCSTEP 500
#define MODE_NORM 0
#define MODE_HIGH 1
unsigned
int
win_x0
,
win_y0
,
win_x1
,
win_y1
;
unsigned
int
score
,
highscore
;
int
mode
;
int
ball_x
,
ball_y
;
static
void
game_redraw
(
struct
ui_widget
*
w
)
{
char
buf
[
30
];
gfx_clear
(
&
w
->
dc
,
0
);
if
(
mode
==
MODE_HIGH
)
{
sprintf
(
buf
,
"Highscore:"
);
gfx_centered_text
(
&
w
->
dc
,
&
font_helv17b
,
30
,
buf
,
COLOR_BLACK
);
sprintf
(
buf
,
"%u"
,
highscore
);
gfx_centered_text
(
&
w
->
dc
,
&
font_helv17
,
50
,
buf
,
COLOR_BLACK
);
}
else
{
sprintf
(
buf
,
"Score: %u"
,
score
);
gfx_centered_text
(
&
w
->
dc
,
&
font_helv17
,
5
,
buf
,
COLOR_BLACK
);
gfx_line
(
&
w
->
dc
,
win_x0
,
win_y0
,
win_x0
,
win_y1
,
COLOR_BLACK
);
gfx_line
(
&
w
->
dc
,
win_x0
,
win_y0
,
win_x1
,
win_y0
,
COLOR_BLACK
);
gfx_line
(
&
w
->
dc
,
win_x0
,
win_y1
,
win_x1
,
win_y1
,
COLOR_BLACK
);
gfx_line
(
&
w
->
dc
,
win_x1
,
win_y0
,
win_x1
,
win_y1
,
COLOR_BLACK
);
gfx_fill_circle
(
&
w
->
dc
,
ball_x
,
ball_y
,
BALL_R
,
COLOR_BLACK
);
}
}
static
void
game_event
(
struct
ui_widget
*
w
,
const
struct
event
*
evt
)
{
w
->
flags
|=
WF_DIRTY
;
}
struct
ui_widget
game_widget
=
{
game_redraw
,
game_event
,
{
0
,
0
,
127
,
127
},
0
,
WF_ACTIVE
|
WF_VISIBLE
};
struct
ui_widget
game_screen
=
{
NULL
,
NULL
,
{
0
,
0
,
127
,
127
},
0
,
WF_ACTIVE
|
WF_VISIBLE
};
void
game_main
(
void
*
params
)
{
(
void
)(
params
);
struct
event
evt
;
lsm303_smpl
acc
;
int
fakap
=
0
;
char
buf
[
30
];
int
old_x
,
old_y
;
int
dir
=
0
,
fact
;
lsm303_init
();
USBD_Init
(
&
initstruct
);
buzzer_set_freq
(
4000
);
ball_x
=
64
;
ball_y
=
64
;
old_x
=
64
;
old_y
=
64
;
score
=
0
;
highscore
=
0
;
win_x0
=
S_WIN_X0
;
win_x1
=
S_WIN_X1
;
win_y0
=
S_WIN_Y0
;
win_y1
=
S_WIN_Y1
;
ui_clear
();
ui_init_widget
(
&
game_screen
);
ui_init_widget
(
&
game_widget
);
ui_add_widget
(
&
game_widget
);
ui_add_child
(
&
game_screen
,
&
game_widget
);
ui_add_widget
(
&
game_screen
);
/*draw screen for the first time*/
ui_update
(
NULL
);
/*main loop*/
while
(
1
)
{
if
(
xQueueReceive
(
appQueue
,
&
evt
,
0
))
{
switch
(
evt
.
type
)
{
case
BUTTON_PRESSED
:
if
(
evt
.
data
.
button
==
BUT_TR
)
{
vibra_disable
();
buzzer_disable
();
return
;
}
if
(
evt
.
data
.
button
==
BUT_BR
)
mode
=
MODE_HIGH
;
if
(
evt
.
data
.
button
==
BUT_BL
)
mode
=
MODE_NORM
;
}
}
lsm303_get_sample
(
DEV_ACC
,
&
acc
);
ball_x
-=
acc
.
x
/
100
;
ball_y
-=
acc
.
y
/
100
;
if
(
ball_x
>=
win_x1
-
BALL_R
)
{
ball_x
=
win_x1
-
BALL_R
;
fakap
=
1
;
}
if
(
ball_x
<=
win_x0
+
BALL_R
)
{
ball_x
=
win_x0
+
BALL_R
;
fakap
=
1
;
}
if
(
ball_y
>=
win_y1
-
BALL_R
)
{
ball_y
=
win_y1
-
BALL_R
;
fakap
=
1
;
}
if
(
ball_y
<=
win_y0
+
BALL_R
)
{
ball_y
=
win_y0
+
BALL_R
;
fakap
=
1
;
}
if
(
ball_x
>
win_x0
+
BALL_R
&&
ball_x
<
win_x1
-
BALL_R
&&
ball_y
>
win_y0
+
BALL_R
&&
ball_y
<
win_y1
-
BALL_R
)
fakap
=
0
;
if
(
fakap
)
{
/* uhh.. that's bad, PUNISHMENT !!! */
score
=
0
;
win_x0
=
S_WIN_X0
;
win_x1
=
S_WIN_X1
;
win_y0
=
S_WIN_Y0
;
win_y1
=
S_WIN_Y1
;
vibra_enable
();
buzzer_enable
();
vTaskDelay
(
100
);
vibra_disable
();
buzzer_disable
();
}
else
{
/*1. the more you move the more points you get*/
/*2. the smaller box is, the more points you get */
fact
=
(
score
/
SCSTEP
)
%
FACT_MOD
;
score
+=
(
fact
+
1
)
*
(
ABS
(
ball_x
-
old_x
)
+
ABS
(
ball_y
-
old_y
));
if
(
score
>
highscore
)
highscore
=
score
;
vibra_disable
();
buzzer_disable
();
/*update box based on score*/
win_x0
=
S_WIN_X0
+
fact
*
STEP
;
win_y0
=
S_WIN_Y0
+
fact
*
STEP
;
win_x1
=
S_WIN_X1
-
fact
*
STEP
;
win_y1
=
S_WIN_Y1
-
fact
*
STEP
;
}
old_x
=
ball_x
;
old_y
=
ball_y
;
ui_update
(
&
evt
);
}
}
application
game
=
{
.
name
=
"Ball game"
,
.
main
=
game_main
};
sw/freertos/src/apps/menu_struct.c
View file @
cdba83fe
...
...
@@ -51,6 +51,7 @@ menu_list main_menu = {
{
{
APP
,
&
example_icon
,
{
.
app
=
&
example
}
},
{
APP
,
&
comp_ico
,
{
.
app
=
&
compass
}
},
{
APP
,
&
game_ico
,
{
.
app
=
&
game
}
},
{
SUBMENU
,
&
settings_icon
,
{
.
submenu
=
&
settings_menu
}
},
{
END
,
NULL
,
{
NULL
}
}
}
...
...
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