platform: auto-register figments, now that we have json config
This commit is contained in:
		| @@ -140,7 +140,11 @@ Platform::bootSplash() | |||||||
|   Log.trace("Registered tasks:"); |   Log.trace("Registered tasks:"); | ||||||
|   auto it = beginTasks(); |   auto it = beginTasks(); | ||||||
|   while (it != endTasks()) { |   while (it != endTasks()) { | ||||||
|     Log.trace((*it)->name); |     if ((*it)->isFigment()) { | ||||||
|  |       Log.trace("  Figment: %s", (*it)->name); | ||||||
|  |     } else { | ||||||
|  |       Log.trace("  %s", (*it)->name); | ||||||
|  |     } | ||||||
|     ++it; |     ++it; | ||||||
|   } |   } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -54,6 +54,29 @@ class Platform : public Task { | |||||||
|       } |       } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     struct figment_iterator: public std::iterator<std::input_iterator_tag, Figment*> { | ||||||
|  |       TaskRegistration* cur; | ||||||
|  |       explicit figment_iterator() : cur(NULL) {} | ||||||
|  |       explicit figment_iterator(TaskRegistration* head) : cur(head) { | ||||||
|  |         while (cur && !cur->task->isFigment()) { | ||||||
|  |           cur = cur->next; | ||||||
|  |         } | ||||||
|  |       } | ||||||
|  |       figment_iterator& operator++() { | ||||||
|  |         if (cur) { | ||||||
|  |           do { | ||||||
|  |             cur = cur->next; | ||||||
|  |           } while (cur && !cur->task->isFigment()); | ||||||
|  |         } | ||||||
|  |         return *this; | ||||||
|  |       } | ||||||
|  |  | ||||||
|  |       figment_iterator operator++(int) {figment_iterator ret = *this; ++(*this); return ret;} | ||||||
|  |       bool operator==(figment_iterator other) const { return cur == other.cur; } | ||||||
|  |       bool operator!=(figment_iterator other) const { return !(*this == other); } | ||||||
|  |       Figment* operator*() const { return static_cast<Figment*>(cur->task); } | ||||||
|  |     }; | ||||||
|  |  | ||||||
|     struct task_iterator: public std::iterator<std::input_iterator_tag, Task*> { |     struct task_iterator: public std::iterator<std::input_iterator_tag, Task*> { | ||||||
|       TaskRegistration* cur; |       TaskRegistration* cur; | ||||||
|       explicit task_iterator() : cur(NULL) {} |       explicit task_iterator() : cur(NULL) {} | ||||||
| @@ -71,6 +94,14 @@ class Platform : public Task { | |||||||
|       Task* operator*() const { return cur->task; } |       Task* operator*() const { return cur->task; } | ||||||
|     }; |     }; | ||||||
|  |  | ||||||
|  |     static figment_iterator beginFigments() { | ||||||
|  |       return figment_iterator(firstTask); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     static figment_iterator endFigments() { | ||||||
|  |       return figment_iterator(NULL); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     static task_iterator beginTasks() { |     static task_iterator beginTasks() { | ||||||
|       return task_iterator(firstTask); |       return task_iterator(firstTask); | ||||||
|     } |     } | ||||||
|   | |||||||
							
								
								
									
										23
									
								
								src/main.cpp
									
									
									
									
									
								
							
							
						
						
									
										23
									
								
								src/main.cpp
									
									
									
									
									
								
							| @@ -154,22 +154,6 @@ private: | |||||||
| STATIC_ALLOC(BPM); | STATIC_ALLOC(BPM); | ||||||
| STATIC_TASK(BPM); | STATIC_TASK(BPM); | ||||||
|  |  | ||||||
| // Render all layers to the displays |  | ||||||
| Renderer renderer{ |  | ||||||
|     {&dpy}, |  | ||||||
|     { |  | ||||||
|         Static<ChimesAnimation>::instance(), |  | ||||||
|         Static<DrainAnimation>::instance(), |  | ||||||
|         Static<SolidAnimation>::instance(), |  | ||||||
|         Static<Flashlight>::instance(), |  | ||||||
|         Static<UpdateStatus>::instance(), |  | ||||||
|         &inputBlip, |  | ||||||
|         &power, |  | ||||||
|     } |  | ||||||
| }; |  | ||||||
|  |  | ||||||
| REGISTER_TASK(renderer); |  | ||||||
|  |  | ||||||
| Renderer configRenderer{ | Renderer configRenderer{ | ||||||
|     {&dpy}, |     {&dpy}, | ||||||
|     {Static<DrainAnimation>::instance(), /*&configDisplay,*/ Static<InputBlip>::instance(), &power} |     {Static<DrainAnimation>::instance(), /*&configDisplay,*/ Static<InputBlip>::instance(), &power} | ||||||
| @@ -460,7 +444,6 @@ void setup() { | |||||||
|  |  | ||||||
|   Log.notice(u8"💡 Starting FastLED..."); |   Log.notice(u8"💡 Starting FastLED..."); | ||||||
|   Platform::addLEDs(leds, HardwareConfig::MAX_LED_NUM); |   Platform::addLEDs(leds, HardwareConfig::MAX_LED_NUM); | ||||||
|   runner = new MainLoop{std::vector<Task*>{Platform::beginTasks(), Platform::endTasks()}}; |  | ||||||
|  |  | ||||||
|   // Tune in, |   // Tune in, | ||||||
|   if (Platform::bootopts.isSafeMode) { |   if (Platform::bootopts.isSafeMode) { | ||||||
| @@ -473,6 +456,12 @@ void setup() { | |||||||
|     //runner = &configApp; |     //runner = &configApp; | ||||||
|   } else { |   } else { | ||||||
|     Log.notice(u8"🌌 Starting Figment..."); |     Log.notice(u8"🌌 Starting Figment..."); | ||||||
|  |     // Render all layers to the displays | ||||||
|  |     Renderer* renderer = new Renderer({&dpy}, std::vector<Figment*>{Platform::beginFigments(), Platform::endFigments()}); | ||||||
|  |  | ||||||
|  |     std::vector<Task*> defaultTasks{Platform::beginTasks(), Platform::endTasks()}; | ||||||
|  |     defaultTasks.push_back(renderer); | ||||||
|  |     runner = new MainLoop{std::vector<Task*>{defaultTasks.begin(), defaultTasks.end()}}; | ||||||
|   } |   } | ||||||
|   Serial.flush(); |   Serial.flush(); | ||||||
|   runner->start(); |   runner->start(); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user