Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: _24LCXXX
Dependents: vfd_modular_clock_mbed
flw.h
00001 /* 00002 * Four Letter Word Generator 00003 * (C) 2015 Akafugu Corporation 00004 * 00005 * This program is free software; you can redistribute it and/or modify it under the 00006 * terms of the GNU General Public License as published by the Free Software 00007 * Foundation; either version 2 of the License, or (at your option) any later 00008 * version. 00009 * 00010 * This program is distributed in the hope that it will be useful, but WITHOUT ANY 00011 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 00012 * PARTICULAR PURPOSE. See the GNU General Public License for more details. 00013 * 00014 */ 00015 00016 #ifndef FLW_H__ 00017 #define FLW_H__ 00018 00019 #include <inttypes.h> 00020 #include <stdbool.h> 00021 00022 #include "_24LCXXX.h" 00023 00024 class FourLetterWordBase 00025 { 00026 protected: 00027 bool m_censored; 00028 unsigned long m_offset; 00029 char m_current_word[6]; 00030 uint32_t m_lfsr; 00031 00032 uint32_t randomize(); 00033 00034 void rot13(char* w); 00035 bool binary_search(const char *key, int imin, int imax); 00036 00037 char* get_word_censored(); 00038 char* get_word_uncensored(); 00039 00040 public: 00041 FourLetterWordBase() : 00042 m_censored(true), 00043 m_offset(0), 00044 m_lfsr(0xbeefcace) {} 00045 00046 virtual uint8_t read_byte(unsigned int addr) = 0; 00047 virtual void read_buffer(unsigned int addr, uint8_t *buffer, int length) = 0; 00048 00049 void begin(uint32_t seed = 0xbeefcace, bool censored = true); 00050 void setCensored(bool c) { m_censored = c; } 00051 bool hasEeprom(); 00052 char* getWord(bool adjustCase = false); 00053 }; 00054 00055 class FourLetterWord : public FourLetterWordBase 00056 { 00057 private: 00058 _24LCXXX _24lc; 00059 00060 public: 00061 FourLetterWord(I2C *i2c, uint8_t addr = 0x50) : FourLetterWordBase(), _24lc(i2c, addr) {} 00062 00063 virtual uint8_t read_byte(unsigned int addr); 00064 virtual void read_buffer(unsigned int addr, uint8_t *buffer, int length); 00065 }; 00066 00067 extern const unsigned char flw_data[]; 00068 00069 class FourLetterWordLocal : public FourLetterWordBase 00070 { 00071 private: 00072 const unsigned char* data; 00073 00074 public: 00075 FourLetterWordLocal() : FourLetterWordBase(), data(flw_data) {} 00076 00077 virtual uint8_t read_byte(unsigned int addr); 00078 virtual void read_buffer(unsigned int addr, uint8_t *buffer, int length); 00079 }; 00080 00081 #endif
Generated on Fri Jul 15 2022 18:40:04 by
