Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template<typename Type>
- class InProgmem {
- friend class Font;
- Type const val; // InProgmem<Type> should be as big as Type
- InProgmem(Type const &val) : val(val) {} // Keep the compiler quiet
- // Prevent copying, makes problems otherwise
- InProgmem(const InProgmem<Type>& other) : val(other.val) {};
- InProgmem<Type>& operator = (const InProgmem<Type>& other)
- { return *this; }
- public:
- #if defined AVR
- operator Type() const {
- Type out;
- memcpy_P(&out, this, sizeof(Type));
- return out;
- }
- #else
- // If running on a computer just return the value
- operator Type() const {
- return val;
- }
- #endif
- } __attribute__((packed));
- struct MyData {
- InProgmem<int> a, b;
- };
- PROGMEM int const dataInProgmem[] = {23, 42};
- void setup() {
- Serial.begin(9600);
- MyData *data = (MyData*)&dataInProgmem;
- Serial.println(data->a);
- Serial.println(data->b);
- }
- void loop() {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement