Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I can't understand your code... :(
#1
Sad 
Hi,
Please explain me how your code is built up, because I can't understand how your code was written. I can write programms in C / C++ but please explain (or structure) me your code Big Grin .
Hope you have time for this. Angel
See ya.
I mean the code for the wristwatch. ^^
Sorry for bad english, I'm german.
Reply
#2
(11-25-2014, 07:58 PM)Sinan Wrote: Hi,
Please explain me how your code is built up, because I can't understand how your code was written. I can write programms in C / C++ but please explain (or structure) me your code  Big Grin .
Hope you have time for this.  Angel
See ya.
I mean the code for the wristwatch. ^^
Sorry for bad english, I'm german.

The code for the watch is organised into modules. Code that deals with microcontroller peripherals like SPI and UART are in the drivers folder. Code for external devices like the OLED and RTC are in the devices folder. Same goes for apps, games, menus and a few other things.
The program starts in main.c. It first initialises everything by calling all the (module)_init() functions then the main loop starts. The main loop calls all the (module)_update() functions which makes everything do their stuff, like the battery module will see if its time to update the battery voltage and if it is time it will do an update by calling the ADC module function adc_read(). Then it will go to the buttons module and update the button press statues, so on and so on.

It does it a lot of stuff, you'll have to go through the rest of the code yourself.
Reply
#3
Okay thanks for the quick awnser! Smile You mean that I can code my own game as .h and .cpp and it would show it in the menu or do I have to define it in the menu.cpp? (I dont mean define it as headers but do i have to write the game functions in the menu.cpp?)
Reply
#4
(11-26-2014, 02:12 PM)Sinan Wrote: Okay thanks for the quick awnser! Smile You mean that I can code my own game as .h and .cpp and it would show it in the menu or do I have to define it in the menu.cpp? (I dont mean define it as headers but do i have to write the game functions in the menu.cpp?)

Yeah almost. In menus/games.c change OPTION_COUNT to 3 and add this line into the itemLoader function:
Code:
setMenuOption_P(2, PSTR("your game name"), NULL, yourgame_start);

Looking at the games in games/ folder, the main function you will need is yourgame_start(), which is called when you select the menu option. In that function you should close the menu and set the draw and button functions:

Code:
void yourgame_start()
{
    menu_close();

    display_setDrawFunc(draw);
    buttons_setFuncs(btnRight, btnExit, btnLeft);
}

static bool btnExit()
{
    animation_start(display_load, ANIM_MOVE_OFF);
    return true;
}

static bool btnRight()
{

    return false;
}

static bool btnLeft()
{

    return false;
}

static display_t draw()
{
// main game code here

    return DISPLAY_BUSY;
}

The button functions should return true so the the function is not called again until next button press or false to continually call the function while the button is pressed. draw() should always return DISPLAY_BUSY.
Reply
#5
Hi,
I wrote my own game module.
But how can I create a textmenu for it? Like you did for the alarms.
But I would like to have the following style:

"Item 1 [number to edit]"
"Item 2 [number to edit]"
"..."
"..."
"Status line"

Thanks and regards from Germany
Rob.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)