Skip to content

Commit

Permalink
basic hellworld app infrastructre
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitshetty committed Mar 6, 2017
1 parent 9fadb14 commit 5c4677e
Show file tree
Hide file tree
Showing 13 changed files with 179 additions and 13 deletions.
5 changes: 5 additions & 0 deletions apps/apps.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#ifndef APPS_H
#define APPS_H

#include "helloWorldApp/helloWorldMain.h"
#endif
8 changes: 8 additions & 0 deletions apps/apps.mains.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include "apps.mains.h"

struct Apps apps[APPSIZE] = {
{
.name = "Brightness",
.pointer = helloWorld
}
};
18 changes: 18 additions & 0 deletions apps/apps.mains.h
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions apps/helloWorldApp/helloWorldMain.c
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
11 changes: 11 additions & 0 deletions apps/helloWorldApp/helloWorldMain.h
Original file line number Diff line number Diff line change
@@ -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
Empty file removed apps/helloWorldApp/main.c
Empty file.
Empty file removed apps/helloWorldApp/main.h
Empty file.
2 changes: 1 addition & 1 deletion config.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#define F_CPU 11059200UL

#define APPSIZE 3
#define APPSIZE 2
#define true 1
#define false 0

Expand Down
69 changes: 58 additions & 11 deletions main.c
Original file line number Diff line number Diff line change
@@ -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];
Expand Down Expand Up @@ -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){
Expand Down
23 changes: 22 additions & 1 deletion main.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,37 @@
#include<util/delay.h>
#include<avr/pgmspace.h>
#include<avr/interrupt.h>
#include<avr/sleep.h>
#include <string.h>

#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<<NEGAT))
#define PRESSED_INPUT_POSITIVE (input_status & (1<<POSIT))
#define PRESSED_INPUT_TOP (input_status & (1<<NAVI_TOP))
#define PRESSED_INPUT_DOWN (input_status & (1<<NAVI_DOWN))
#define PRESSED_INPUT_LEFT (input_status & (1<<NAVI_LEFT))
#define PRESSED_INPUT_RIGHT (input_status & (1<<NAVI_RIGHT))

void menu_state_machine (void);
#endif
21 changes: 21 additions & 0 deletions peripheral_drivers/sleep/at_sleep.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "at_sleep.h"

void goto_sleep(void) {
MCUCSR &=~((1<<ISC00)|((1<<ISC01)));
GICR = (1<<INT0);
DDRC |= (1<<PC2);
PORTC|=(1<<PC2);
_delay_ms(500);
PORTC&=~(1<<PC2);

set_dutycycle(0);
screen_clear();
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
sleep_enable();
sleep_cpu();
sleep_disable();
_delay_ms(100);
screen_clear();
set_dutycycle(50);
GICR &= ~(1<<INT0);
}
12 changes: 12 additions & 0 deletions peripheral_drivers/sleep/at_sleep.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef AT_SLEEP_H
#define AT_SLEEP_H

#include "../../config.h"
#include<avr/io.h>
#include<avr/interrupt.h>
#include<avr/sleep.h>
#include<util/delay.h>
#include "../../device_drivers/screen/screen.h"
void goto_sleep(void);

#endif
2 changes: 2 additions & 0 deletions utils/utils.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#ifndef UTILS_H
#define UTILS_H

#include "../config.h"
#include<avr/io.h>


void strcut(char* , char* ,uint8_t ,uint8_t);

#endif

0 comments on commit 5c4677e

Please sign in to comment.