HitLib 1.5.0
VEX V5 LED animation library for PROS
Loading...
Searching...
No Matches
platform.hpp
Go to the documentation of this file.
1#pragma once
2#include <cstdint>
3
23
24#if !defined(HITLIB_PLATFORM_PROS) && !defined(HITLIB_PLATFORM_VEXCODE) && \
25 !defined(HITLIB_PLATFORM_HOST)
26# if defined(__has_include)
27# if __has_include("pros/rtos.hpp")
28# define HITLIB_PLATFORM_PROS 1
29# elif __has_include("v5_vcs.h")
30# define HITLIB_PLATFORM_VEXCODE 1
31# endif
32# endif
33#endif
34
35#ifndef HITLIB_PLATFORM_PROS
36# define HITLIB_PLATFORM_PROS 0
37#endif
38#ifndef HITLIB_PLATFORM_VEXCODE
39# define HITLIB_PLATFORM_VEXCODE 0
40#endif
41// Deliberately never auto-detected: a desktop compiler has no header that
42// identifies it as "the test platform", and silently picking it would turn a
43// misconfigured robot build into one that compiles and drives nothing.
44#ifndef HITLIB_PLATFORM_HOST
45# define HITLIB_PLATFORM_HOST 0
46#endif
47
48#if (HITLIB_PLATFORM_PROS + HITLIB_PLATFORM_VEXCODE + HITLIB_PLATFORM_HOST) > 1
49# error "HitLib: more than one HITLIB_PLATFORM_* macro is set; pick one."
50#elif (HITLIB_PLATFORM_PROS + HITLIB_PLATFORM_VEXCODE + HITLIB_PLATFORM_HOST) == 0
51# error "HitLib: couldn't find PROS (pros/rtos.hpp) or the VEX SDK (v5_vcs.h) on the include path. Define HITLIB_PLATFORM_PROS=1 or HITLIB_PLATFORM_VEXCODE=1."
52#endif
53
54namespace hitlib {
55namespace platform {
56
58uint32_t millis();
59
61void delay(uint32_t ms);
62
70void delayUntil(uint32_t& prevMs, uint32_t ms);
71
77void startTask(void (*entry)(void*), void* arg, const char* name);
78
80class Mutex {
81public:
84
85 Mutex(const Mutex&) = delete;
86 Mutex& operator=(const Mutex&) = delete;
87
88 void take();
89 void give();
90
91private:
92 void* handle;
93};
94
99class AdiLed {
100public:
107 AdiLed(uint8_t smartPort, uint8_t adiPort, uint8_t length);
109
110 AdiLed(const AdiLed&) = delete;
111 AdiLed& operator=(const AdiLed&) = delete;
112
114 void write(const uint32_t* pixels, uint8_t count);
115
116private:
117 void* impl;
118};
119
120#if HITLIB_PLATFORM_HOST
139namespace host {
140
142void setMillis(uint32_t ms);
143
145void advanceMillis(uint32_t ms);
146
149void reset();
150
161const uint32_t* lastFrame();
162
164uint8_t lastFrameCount();
165
168uint32_t writeCount();
169
178void onWrite(void (*hook)());
179
188void onDelay(void (*hook)(uint32_t ms));
189
191uint32_t heldMutexes();
192
200uint32_t contendedTakes();
201
204uint32_t taskCount();
205
215void runTask(uint32_t index, uint32_t cycles);
216
217} // namespace host
218#endif // HITLIB_PLATFORM_HOST
219
220} // namespace platform
221} // namespace hitlib
AdiLed & operator=(const AdiLed &)=delete
AdiLed(const AdiLed &)=delete
void write(const uint32_t *pixels, uint8_t count)
Send count 0xRRGGBB colors to the strip, starting at LED 0.
AdiLed(uint8_t smartPort, uint8_t adiPort, uint8_t length)
Mutex & operator=(const Mutex &)=delete
Mutex(const Mutex &)=delete
Definition platform.hpp:55
void delay(uint32_t ms)
Sleep the calling task for ms milliseconds.
void startTask(void(*entry)(void *), void *arg, const char *name)
Start a background task that runs entry(arg).
void delayUntil(uint32_t &prevMs, uint32_t ms)
Sleep until prevMs + ms, then advance prevMs by ms.
uint32_t millis()
Milliseconds since the program started.
Definition led_group.hpp:12