Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template <typename pins_conn>
- class lcd
- {
- public:
- lcd() = default;
- void attach()
- {
- con.attach();
- }
- constexpr bool is_4bits() const
- {
- return con.is_4bits;
- }
- pins_conn con;
- };
- struct conn_4bits
- {
- void attach()
- {
- // Attach 4 pins
- }
- void send_cmd(int cmd)
- {
- // Send 4 bits command
- }
- int d4, d5, d6, d7;
- int is_4bits = 1;
- };
- struct conn_8bits
- {
- void attach()
- {
- // Attach 8 pins
- }
- void send_cmd(int cmd)
- {
- // Send 8 bits command
- }
- int d0, d1, d2, d3, d4, d5, d6, d7;
- int is_4bits = 0;
- };
- template <typename lcd_con>
- void do_something_with_lcd(lcd<lcd_con>& lcd)
- {
- // Do something
- }
- int main()
- {
- lcd<conn_4bits> lcd_4bits;
- lcd<conn_8bits> lcd_8bits;
- // Setup
- lcd_4bits.con.d4 = 1;
- lcd_8bits.con.d0 = 2;
- // Etc
- lcd_4bits.attach();
- lcd_8bits.attach();
- if (lcd_4bits.is_4bits())
- {
- // Do something...
- }
- do_something_with_lcd(lcd_4bits);
- do_something_with_lcd(lcd_8bits);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement