Four Letter Word generator based on an associative word dictionary.

Dependencies:   _24LCXXX

Dependents:   vfd_modular_clock_mbed

Four Letter Word generator based on an associative word dictionary.

Needs an EEPROM to function (can be programmed onto a 24LC512 I2C EEPROM, or available as a pre-programmed add-on board)

Comes with a censored mode that removes expletives as well as a fully uncensored mode.

For details see:

Revision:
6:f3455eff2ae4
Parent:
5:8748fd0dce7c
--- a/flw.cpp	Fri Feb 20 10:06:00 2015 +0000
+++ b/flw.cpp	Mon Feb 23 02:43:20 2015 +0000
@@ -30,7 +30,7 @@
 
 #define EEPROM_ADDR 0b1010000
 
-void FourLetterWord::rot13(char* w)
+void FourLetterWordBase::rot13(char* w)
 {
     while (*w != '\0') {
         if (*w >= 'A' && *w <= 'M') {
@@ -44,7 +44,7 @@
     }
 }
 
-bool FourLetterWord::binary_search(const char *key, int imin, int imax)
+bool FourLetterWordBase::binary_search(const char *key, int imin, int imax)
 {
   int pos;
   int cond = 0;
@@ -65,26 +65,13 @@
   return false;
 }
 
-
-uint8_t FourLetterWord::read_byte(unsigned int addr) {
-  uint8_t rdata = 0xFF;
-  
-  _24lc.nbyte_read(addr, &rdata, 1);
-  return rdata;
-}
-
-void FourLetterWord::read_buffer(unsigned int addr, uint8_t *buffer, int length) {
-  _24lc.nbyte_read(addr, buffer, length);
-}
-
-
-void FourLetterWord::begin(uint32_t seed, bool censored)
+void FourLetterWordBase::begin(uint32_t seed, bool censored)
 {
   m_lfsr = seed + 1;
   m_censored = censored;
 }
 
-uint32_t FourLetterWord::randomize()
+uint32_t FourLetterWordBase::randomize()
 {
   // http://en.wikipedia.org/wiki/Linear_feedback_shift_register
   // Galois LFSR: taps: 32 31 29 1; characteristic polynomial: x^32 + x^31 + x^29 + x + 1 */
@@ -92,7 +79,7 @@
   return m_lfsr;  
 }
 
-bool FourLetterWord::hasEeprom()
+bool FourLetterWordBase::hasEeprom()
 {
    uint8_t b1 = read_byte(0); 
    uint8_t b2 = read_byte(1); 
@@ -102,7 +89,7 @@
    return false;
 }
 
-char* FourLetterWord::get_word_censored()
+char* FourLetterWordBase::get_word_censored()
 {
   char* w = get_word_uncensored();
   
@@ -118,7 +105,7 @@
   return w;
 }
 
-char* FourLetterWord::get_word_uncensored()
+char* FourLetterWordBase::get_word_uncensored()
 {
   unsigned char low = 0xFF, high = 0xFF;
   unsigned char count = 0;
@@ -139,7 +126,7 @@
   return m_current_word;
 }
 
-char* FourLetterWord::getWord(bool adjustCase)
+char* FourLetterWordBase::getWord(bool adjustCase)
 {
   char* ret;
   
@@ -155,3 +142,33 @@
   
   return ret;
 }
+
+/////////////////////////////////////////////////////
+// EEPROM
+
+uint8_t FourLetterWord::read_byte(unsigned int addr) {
+  uint8_t rdata = 0xFF;
+  
+  _24lc.nbyte_read(addr, &rdata, 1);
+  return rdata;
+}
+
+void FourLetterWord::read_buffer(unsigned int addr, uint8_t *buffer, int length) {
+  _24lc.nbyte_read(addr, buffer, length);
+}
+
+/////////////////////////////////////////////////////
+// Data stored in local array
+
+uint8_t FourLetterWordLocal::read_byte(unsigned int addr) {
+  return data[addr];  
+}
+
+void FourLetterWordLocal::read_buffer(unsigned int addr, uint8_t *buffer, int length) {
+  unsigned char* ptr = (unsigned char*)data;
+  ptr += addr;
+  memcpy(buffer, ptr, length); 
+}
+
+
+