diff --git a/apps/apps.h b/apps/apps.h new file mode 100644 index 0000000..330944b --- /dev/null +++ b/apps/apps.h @@ -0,0 +1,5 @@ +#ifndef APPS_H +#define APPS_H + +#include "helloWorldApp/helloWorldMain.h" +#endif diff --git a/apps/apps.mains.c b/apps/apps.mains.c index e69de29..673d461 100644 --- a/apps/apps.mains.c +++ b/apps/apps.mains.c @@ -0,0 +1,8 @@ +#include "apps.mains.h" + +struct Apps apps[APPSIZE] = { + { + .name = "Brightness", + .pointer = helloWorld + } +}; diff --git a/apps/apps.mains.h b/apps/apps.mains.h index e69de29..2d2e908 100644 --- a/apps/apps.mains.h +++ b/apps/apps.mains.h @@ -0,0 +1,18 @@ +#ifndef APPS_MAINS_H +#define APPS_MAINS_H + +#include "../config.h" +#include "../main.h" +#include "apps.h" + + +typedef void (*functionptr_t)(); +struct Apps{ + char name[16]; + functionptr_t pointer; +}; + + +extern struct Apps apps[APPSIZE]; + +#endif diff --git a/apps/helloWorldApp/helloWorldMain.c b/apps/helloWorldApp/helloWorldMain.c new file mode 100644 index 0000000..b2a4cde --- /dev/null +++ b/apps/helloWorldApp/helloWorldMain.c @@ -0,0 +1,21 @@ +#include "helloWorldMain.h" + +void helloWorld (void) { + uint8_t exit=0; + screen_clear(); + screen_normal(); + + render_sentence_xy("Hello World",20,2); + + while(!exit) { + if(PRESSED_INPUT_NEGATIVE){ + exit = 1; + screen_clear(); + _delay_ms(200); + } + + if (PRESSED_INPUT_POSITIVE) { + screen_invert(); + } + } +} diff --git a/apps/helloWorldApp/helloWorldMain.h b/apps/helloWorldApp/helloWorldMain.h new file mode 100644 index 0000000..0e368fa --- /dev/null +++ b/apps/helloWorldApp/helloWorldMain.h @@ -0,0 +1,11 @@ +#ifndef HELLOWORLDMAIN_H +#define HELLOWORLDMAIN_H + + +#include "../../device_drivers/screen/screen.h" +#include "../../device_drivers/input/input.h" +#include "../../main.h" +extern void helloWorld(void); + + +#endif diff --git a/apps/helloWorldApp/main.c b/apps/helloWorldApp/main.c deleted file mode 100644 index e69de29..0000000 diff --git a/apps/helloWorldApp/main.h b/apps/helloWorldApp/main.h deleted file mode 100644 index e69de29..0000000 diff --git a/config.h b/config.h index c8bb930..dda2d61 100644 --- a/config.h +++ b/config.h @@ -3,7 +3,7 @@ #define F_CPU 11059200UL -#define APPSIZE 3 +#define APPSIZE 2 #define true 1 #define false 0 diff --git a/main.c b/main.c index cbb26ab..05934a6 100755 --- a/main.c +++ b/main.c @@ -1,15 +1,5 @@ #include "main.h" -/* -PD2 positive response -PD3 negative response - -PD4 left -PD5 right -PD6 down -PD7 right -*/ - uint8_t brightness = 100; volatile char datetime[21]; char hhmmss[9]; @@ -42,13 +32,70 @@ int main(){ while(1){ render_sentence_xy(hhmmss,15,2); set_cursor_bank(15,3); - render_sentence_xy("`C Mysuru",27,3); + render_sentence_xy("Mysuru",27,3); screen_invert(); + + + if(PRESSED_INPUT_NEGATIVE){ + goto_sleep(); // in utils + } + + if (PRESSED_INPUT_POSITIVE) { + menu_state_machine(); + } } return 0; } +void menu_state_machine (void) { + //App state machine + _delay_ms(100); + uint8_t current_menu = 0; + uint8_t exit = false; + screen_clear(); + screen_normal(); + while(!exit){ + render_sentence_xy(apps[current_menu].name,20,2); + screen_invert(); + + //When top is selected show previous app + if(PRESSED_INPUT_TOP){ + if(current_menu < APPSIZE -1){ + current_menu++; + }else{ + current_menu = 0; + } + _delay_ms(100); + _delay_ms(50); + screen_clear(); + } + + // If negative, go back to home screen + if(PRESSED_INPUT_NEGATIVE){ + _delay_ms(100); + exit = true; + screen_clear(); + } + + //If down, show next app + if(PRESSED_INPUT_DOWN){ + if(current_menu > 0) + current_menu--; + else + current_menu = APPSIZE -1; + _delay_ms(100); + screen_clear(); + } + + //goto app + if(PRESSED_INPUT_LEFT | PRESSED_INPUT_RIGHT){ + _delay_ms(100); + apps[current_menu].pointer(); + } + } +} + ISR(INT0_vect){ diff --git a/main.h b/main.h index e276b6a..005cb06 100644 --- a/main.h +++ b/main.h @@ -6,16 +6,37 @@ #include #include #include -#include #include #include "peripheral_drivers/serial/serial.h" #include "peripheral_drivers/pwm/pwm.h" #include "peripheral_drivers/i2c/i2c.h" +#include "peripheral_drivers/sleep/at_sleep.h" #include "device_drivers/screen/screen.h" #include "device_drivers/input/input.h" #include "device_drivers/rtc/rtc.h" #include "utils/utils.h" +#include "apps/apps.mains.h" + +/* +PD2 positive response +PD3 negative response + +PD4 left +PD5 right +PD6 down +PD7 right +*/ + + +#define PRESSED_INPUT_NEGATIVE (input_status & (1< +#include +#include +#include +#include "../../device_drivers/screen/screen.h" +void goto_sleep(void); + +#endif diff --git a/utils/utils.h b/utils/utils.h index 5368cca..315ce22 100644 --- a/utils/utils.h +++ b/utils/utils.h @@ -1,8 +1,10 @@ #ifndef UTILS_H #define UTILS_H +#include "../config.h" #include + void strcut(char* , char* ,uint8_t ,uint8_t); #endif