Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Phonebook library for #144. * Phonebook applet for #144. * Phonebook now supports fall-through. Now + is the next line, 0 is the next word. #144
- Loading branch information
1 parent
1be6672
commit 906f09f
Showing
11 changed files
with
240 additions
and
5 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
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
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
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
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,73 @@ | ||
/*! \file phonebook.h | ||
\brief Phonebook application. | ||
*/ | ||
|
||
#include "api.h" | ||
|
||
//! Pointer to the current phonebook entry. | ||
static const char* pbptr; | ||
|
||
|
||
//! Initialize the phonebook. | ||
void phonebook_init(){ | ||
pbptr=phonebook; | ||
} | ||
|
||
//! Draw the Phonebook | ||
void phonebook_draw(int forced){ | ||
//Draw the word. | ||
lcd_string(pbptr); | ||
} | ||
|
||
|
||
//! Exits the phonebook. | ||
int phonebook_exit(){ | ||
//Return 0 so we can move back to the clock. | ||
return 0; | ||
} | ||
|
||
|
||
//! A button has been pressed for the phonebook. | ||
int phonebook_keypress(char ch){ | ||
switch(ch){ | ||
//Third (fallthrough) row shows one word each of the current row. | ||
case '1': | ||
pbptr=pb_firstword(pbptr); | ||
break; | ||
case '2': | ||
pbptr=pb_firstword(pbptr); | ||
pbptr=pb_nextword(pbptr); | ||
break; | ||
case '3': | ||
pbptr=pb_firstword(pbptr); | ||
pbptr=pb_nextword(pbptr); | ||
pbptr=pb_nextword(pbptr); | ||
break; | ||
case '-': | ||
pbptr=pb_firstword(pbptr); | ||
pbptr=pb_nextword(pbptr); | ||
pbptr=pb_nextword(pbptr); | ||
pbptr=pb_nextword(pbptr); | ||
break; | ||
|
||
|
||
//Bottom row moves the line or entry. | ||
case '0': | ||
pbptr=pb_nextword(pbptr); | ||
break; | ||
case '+': | ||
pbptr=pb_nextline(pbptr); | ||
break; | ||
default: | ||
return 0; //no need to redraw | ||
} | ||
return 1; //redraw | ||
} | ||
|
||
|
||
|
||
//! A fallthrough button in the third row for the phonebook. | ||
int phonebook_fallthrough(char ch){ | ||
phonebook_draw(phonebook_keypress(ch)); | ||
return 0; | ||
} |
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 @@ | ||
/*! \file phonebook.h | ||
\brief Phonebook application. | ||
*/ | ||
|
||
|
||
#ifndef PHONEBOOK | ||
#error "PHONEBOOK is undefined in config.h. Are you using an old template?" | ||
#endif | ||
|
||
//! Initialize the phonebook. | ||
void phonebook_init(); | ||
//! Draw the Phonebook | ||
void phonebook_draw(int forced); | ||
//! Exits the phonebook. | ||
int phonebook_exit(); | ||
|
||
//! A button has been pressed for the phonebook. | ||
int phonebook_keypress(char ch); | ||
|
||
//! A fallthrough button in the third row for the phonebook. | ||
int phonebook_fallthrough(char ch); |
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
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 |
---|---|---|
|
@@ -3,3 +3,4 @@ pocsag | |
hebrew | ||
jukebox | ||
beats | ||
phonebook |
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
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,102 @@ | ||
#include "phonebook.h" | ||
|
||
#ifndef STANDALONE | ||
#include "api.h" | ||
#endif | ||
|
||
//Fake phonebook only in standalone mode. | ||
#ifdef STANDALONE | ||
#define PHONEBOOK \ | ||
"Travis " "555-3811" "\n" \ | ||
"bob " "555-0321" "\n" \ | ||
"Jim " "555-9379" "\n" \ | ||
"Last " "555-2358" "\n" | ||
|
||
|
||
|
||
#include<stdint.h> | ||
#include<stdio.h> | ||
#include<string.h> | ||
|
||
int main(){ | ||
const char* p=phonebook; | ||
char w[9]=" "; | ||
for(int i=0; i<10; i++){ | ||
for(int j=0; j<10; j++){ | ||
memcpy(w,p,8); | ||
printf("\t_%s_",w); | ||
p=pb_nextword(p); | ||
} | ||
printf("\n"); | ||
p=pb_nextline(p); | ||
} | ||
return 0; | ||
} | ||
|
||
#endif | ||
|
||
|
||
|
||
//! This is variable for the phonebook. | ||
const char phonebook[] = PHONEBOOK; | ||
|
||
|
||
|
||
//! Given a pointer, this goes back to the beginning of the line. | ||
const char* pb_firstword(const char* word){ | ||
while(word-->phonebook){ | ||
//One step forward from a newline. | ||
if(*word=='\n') | ||
return word+1; | ||
} | ||
|
||
return phonebook; | ||
} | ||
|
||
|
||
//! Given a pointer, it finds the very next word while looping to the first of a line. | ||
const char* pb_nextword(const char* word){ | ||
//Step forward eight letters, unless we find a terminator. | ||
for(int i=0; i<8; i++){ | ||
word++; | ||
|
||
//On a null or newline, jump back to the beginning of the line. | ||
if(!*word || *word=='\n') | ||
return pb_firstword(word); | ||
} | ||
|
||
//One more to check. | ||
word++; | ||
switch(*word){ | ||
case '\n': | ||
case 0: | ||
//If a newline or null, we jump back to the start. | ||
return pb_firstword(--word); | ||
default: | ||
return --word; | ||
} | ||
} | ||
|
||
|
||
//! Given a pointer, this finds the next line. | ||
const char* pb_nextline(const char* word){ | ||
while(phonebook < ++word +sizeof(phonebook)){ | ||
//Revert to the first line on a null. | ||
if(!*word) | ||
return phonebook; | ||
|
||
|
||
//A newline is either preceeded by more text or by a null. | ||
if(*word=='\n'){ | ||
word++; | ||
|
||
if(*word)//Return the text. | ||
return word; | ||
else//Revert to the first line on a null. | ||
return phonebook; | ||
} | ||
} | ||
|
||
//Jump back to the beginning when we go too far. | ||
return phonebook; | ||
} |
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,13 @@ | ||
//! Given a pointer, this goes back to the beginning of the line. | ||
const char* pb_firstword(const char* word); | ||
|
||
|
||
//! Given a pointer, it finds the very next word while looping to the first of a line. | ||
const char* pb_nextword(const char* word); | ||
|
||
//! Given a pointer, this finds the next line. | ||
const char* pb_nextline(const char* word); | ||
|
||
|
||
//! This is variable for the phonebook. | ||
extern const char phonebook[]; |