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:
2:ff0163bc298d
--- a/flw.h	Fri Feb 20 10:06:00 2015 +0000
+++ b/flw.h	Mon Feb 23 02:43:20 2015 +0000
@@ -19,13 +19,11 @@
 #include <inttypes.h>
 #include <stdbool.h>
 
-
 #include "_24LCXXX.h"
 
-class FourLetterWord
+class FourLetterWordBase
 {
-private:
-    _24LCXXX _24lc;
+protected:
     bool m_censored;
     unsigned long m_offset;
     char m_current_word[6];
@@ -35,25 +33,49 @@
     
     void rot13(char* w);
     bool binary_search(const char *key, int imin, int imax);
-    uint8_t read_byte(unsigned int addr);
-    void read_buffer(unsigned int addr, uint8_t *buffer, int length);
     
     char* get_word_censored();
     char* get_word_uncensored();
 
 public:
-    FourLetterWord(I2C *i2c, uint8_t addr = 0x50) :
-      _24lc(i2c, addr),
-      m_censored(true),
-      m_offset(0),
-      m_lfsr(0xbeefcace) {}
+    FourLetterWordBase() :
+        m_censored(true),
+        m_offset(0),
+        m_lfsr(0xbeefcace) {}
+
+    virtual uint8_t read_byte(unsigned int addr) = 0;
+    virtual void read_buffer(unsigned int addr, uint8_t *buffer, int length) = 0;
 
     void begin(uint32_t seed = 0xbeefcace, bool censored = true);
-    
     void setCensored(bool c) { m_censored = c; }
-    
     bool hasEeprom();
     char* getWord(bool adjustCase = false);
 };
 
+class FourLetterWord : public FourLetterWordBase
+{
+private:
+    _24LCXXX _24lc;
+    
+public:
+    FourLetterWord(I2C *i2c, uint8_t addr = 0x50) : FourLetterWordBase(), _24lc(i2c, addr) {}
+
+    virtual uint8_t read_byte(unsigned int addr);
+    virtual void read_buffer(unsigned int addr, uint8_t *buffer, int length);
+};
+
+extern const unsigned char flw_data[];
+
+class FourLetterWordLocal : public FourLetterWordBase
+{
+private:
+    const unsigned char* data; 
+
+public:
+    FourLetterWordLocal() : FourLetterWordBase(), data(flw_data) {}
+
+    virtual uint8_t read_byte(unsigned int addr);
+    virtual void read_buffer(unsigned int addr, uint8_t *buffer, int length);
+};
+
 #endif
\ No newline at end of file