acidportal

- 😈 Worlds smallest Evil Portal on a LilyGo T-QT
git clone git://git.acid.vegas/acidportal.git
Log | Files | Refs | Archive | README | LICENSE

user.cpp (2785B)

      1 #if 1 // Change to 0 to disable this code (must enable ONE user*.cpp only!)
      2 
      3 // This file provides a crude way to "drop in" user code to the eyes,
      4 // allowing concurrent operations without having to maintain a bunch of
      5 // special derivatives of the eye code (which is still undergoing a lot
      6 // of development). Just replace the source code contents of THIS TAB ONLY,
      7 // compile and upload to board. Shouldn't need to modify other eye code.
      8 
      9 // User globals can go here, recommend declaring as static, e.g.:
     10 // static int foo = 42;
     11 
     12 // Called once near the end of the setup() function.
     13 void user_setup(void) {
     14 }
     15 
     16 // Called periodically during eye animation. This is invoked in the
     17 // interval before starting drawing on the last eye so it won't exacerbate
     18 // visible tearing in eye rendering.
     19 // This function BLOCKS, it does NOT multitask with the eye animation code,
     20 // and performance here will have a direct impact on overall refresh rates,
     21 // so keep it simple. Avoid loops (e.g. if animating something like a servo
     22 // or NeoPixels in response to some trigger) and instead rely on state
     23 // machines or similar. Additionally, calls to this function are NOT time-
     24 // constant -- eye rendering time can vary frame to frame, so animation or
     25 // other over-time operations won't look very good using simple +/-
     26 // increments, it's better to use millis() or micros() and work
     27 // algebraically with elapsed times instead.
     28 void user_loop(void) {
     29 /*
     30   Suppose we have a global bool "animating" (meaning something is in
     31   motion) and global uint32_t's "startTime" (the initial time at which
     32   something triggered movement) and "transitionTime" (the total time
     33   over which movement should occur, expressed in microseconds).
     34   Maybe it's servos, maybe NeoPixels, or something different altogether.
     35   This function might resemble something like (pseudocode):
     36 
     37   if(!animating) {
     38     Not in motion, check sensor for trigger...
     39     if(read some sensor) {
     40       Motion is triggered! Record startTime, set transition
     41       to 1.5 seconds and set animating flag:
     42       startTime      = micros();
     43       transitionTime = 1500000;
     44       animating      = true;
     45       No motion actually takes place yet, that will begin on
     46       the next pass through this function.
     47     }
     48   } else {
     49     Currently in motion, ignore trigger and move things instead...
     50     uint32_t elapsed = millis() - startTime;
     51     if(elapsed < transitionTime) {
     52       Part way through motion...how far along?
     53       float ratio = (float)elapsed / (float)transitionTime;
     54       Do something here based on ratio, 0.0 = start, 1.0 = end
     55     } else {
     56       End of motion reached.
     57       Take whatever steps here to move into final position (1.0),
     58       and then clear the "animating" flag:
     59       animating = false;
     60     }
     61   }
     62 */
     63 }
     64 
     65 #endif // 0