Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Monster M4sk: user control of eyes, user config from config.eye, user wiichuck control eyes&neopixels #915

Open
wants to merge 33 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
2b4827c
M4_Eyes.ino: add a set of user_callable functions to control the eyes…
TonyLHansen Nov 2, 2019
79d3589
Merge branch 'master' into master
TonyLHansen Nov 5, 2019
abec3a9
Merge branch 'master' into master
TonyLHansen Nov 6, 2019
bced28b
Merge branch 'master' into master
TonyLHansen Nov 6, 2019
9a0ea23
Merge branch 'master' into master
TonyLHansen Nov 8, 2019
3863073
Merge branch 'master' into master
TonyLHansen Nov 12, 2019
6263a01
Merge branch 'master' into master
TonyLHansen Nov 14, 2019
f36b7d6
Merge branch 'master' into master
TonyLHansen Nov 19, 2019
5d63771
Merge branch 'master' into master
TonyLHansen Nov 19, 2019
8e8d0ee
Merge branch 'master' into master
TonyLHansen Nov 21, 2019
24074a4
Merge branch 'master' into master
TonyLHansen Dec 9, 2019
e31f3f0
Merge branch 'master' into master
TonyLHansen Dec 16, 2019
fc48cd4
Merge branch 'master' into master
TonyLHansen Dec 18, 2019
72e7c0b
Merge branch 'master' into master
TonyLHansen Dec 21, 2019
2b625de
Merge branch 'master' into master
TonyLHansen Jan 1, 2020
6110f14
Merge branch 'master' into master
TonyLHansen Jan 4, 2020
d37f0ac
Merge branch 'master' into master
TonyLHansen Jan 8, 2020
b3b3d19
Merge branch 'master' into master
TonyLHansen Jan 14, 2020
8a56899
Merge branch 'master' into master
TonyLHansen Jan 17, 2020
2258778
Merge branch 'master' into master
TonyLHansen Jan 29, 2020
dadd025
Merge branch 'master' into master
TonyLHansen Feb 7, 2020
2ff55c5
Merge branch 'master' into master
TonyLHansen Feb 9, 2020
77122c8
Merge branch 'master' into master
TonyLHansen Feb 19, 2020
f41231e
Merge branch 'master' into master
TonyLHansen Apr 2, 2020
407ae11
Merge branch 'master' into master
TonyLHansen Apr 7, 2020
e0a94c0
Merge branch 'master' into master
TonyLHansen Apr 24, 2020
9c4df1d
Merge branch 'master' into master
TonyLHansen May 4, 2020
224eb59
Merge branch 'master' into master
TonyLHansen May 23, 2020
b8a41f0
Merge branch 'master' into master
TonyLHansen May 25, 2020
e28f8af
Merge branch 'master' into master
TonyLHansen May 27, 2020
7cdeccc
Merge branch 'master' into master
TonyLHansen May 29, 2020
07428a1
Merge branch 'master' into master
TonyLHansen Jun 4, 2020
c461360
Merge branch 'master' into master
TonyLHansen Oct 29, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 29 additions & 1 deletion M4_Eyes/M4_Eyes.ino
Expand Up @@ -133,6 +133,33 @@ uint32_t availableRAM(void) {
return &top - (char *)sbrk(0); // Top of stack minus end of heap
}

// USER CALLABLE FUNCTIONS

// set the booped flag
void eyesWide(bool t) {
booped = t;
}

// start a blink
void eyesBlink() {
timeToNextBlink = 0;
}

// force the eyes to a position on the screen
void eyesToCorner(float x, float y, bool immediate) {
moveEyesRandomly = false;
eyeTargetX = x;
eyeTargetY = y;
if (immediate)
eyeMoveDuration = 0;
}

// return the eyes to normal random movement
void eyesNormal() {
moveEyesRandomly = true;
}


// SETUP FUNCTION - CALLED ONCE AT PROGRAM START ---------------------------

void setup() {
Expand Down Expand Up @@ -884,7 +911,8 @@ void loop() {
lightSensorPin = -1; // Stop trying to use the light sensor
} else {
lastLightReadTime = t - LIGHT_INTERVAL + 30000; // Try again in 30 ms
} }
}
}
}
irisValue = (irisValue * 0.97) + (lastLightValue * 0.03); // Filter response for smooth reaction
} else {
Expand Down
13 changes: 13 additions & 0 deletions M4_Eyes/file.cpp
Expand Up @@ -284,6 +284,7 @@ void loadConfig(char *filename) {
#endif // ADAFRUIT_MONSTER_M4SK_EXPRESS
}
file.close();
user_setup(doc);
} else {
Serial.println("Can't open config file, using default settings");
}
Expand Down Expand Up @@ -455,3 +456,15 @@ ImageReturnCode loadTexture(char *filename, uint16_t **data,

return status;
}

// Utility functions for use by user functions to grab an integer value from the config file
// using dwim() and providing a default value.
int32_t getDocInt(StaticJsonDocument<2048> &doc, const char *nm, int32_t def) {
return dwim(doc[nm], def);
}
int32_t getDocInt(StaticJsonDocument<2048> &doc, const char *nm, const char *nm2, int32_t def) {
return dwim(doc[nm][nm2], def);
}
int32_t getDocInt(StaticJsonDocument<2048> &doc, const char *nm, const char *nm2, const char *nm3, int32_t def) {
return dwim(doc[nm][nm2][nm3], def);
}
13 changes: 12 additions & 1 deletion M4_Eyes/globals.h
Expand Up @@ -72,7 +72,7 @@ GLOBAL_VAR float trackFactor GLOBAL_INIT(0.5);

// Random eye motion: provided by the base project, but overridable by user code.
GLOBAL_VAR bool moveEyesRandomly GLOBAL_INIT(true); // Clear to suppress random eye motion and let user code control it
GLOBAL_VAR float eyeTargetX GLOBAL_INIT(0.0); // THen set these continuously in user_loop.
GLOBAL_VAR float eyeTargetX GLOBAL_INIT(0.0); // Then set these continuously in user_loop.
GLOBAL_VAR float eyeTargetY GLOBAL_INIT(0.0); // Range is from -1.0 to +1.0.

// Pin definition stuff will go here
Expand Down Expand Up @@ -210,6 +210,9 @@ extern bool filesystem_change_flag GLOBAL_INIT(true);
extern void loadConfig(char *filename);
extern ImageReturnCode loadEyelid(char *filename, uint8_t *minArray, uint8_t *maxArray, uint8_t init, uint32_t maxRam);
extern ImageReturnCode loadTexture(char *filename, uint16_t **data, uint16_t *width, uint16_t *height, uint32_t maxRam);
extern int32_t getDocInt(StaticJsonDocument<2048> &doc, const char *nm, int32_t def);
extern int32_t getDocInt(StaticJsonDocument<2048> &doc, const char *nm, const char *nm2, int32_t def);
extern int32_t getDocInt(StaticJsonDocument<2048> &doc, const char *nm, const char *nm2, const char *nm3, int32_t def);

// Functions in memory.cpp
extern uint32_t availableRAM(void);
Expand All @@ -232,5 +235,13 @@ extern float screen2map(int in);
extern float map2screen(int in);

// Functions in user.cpp
#include <ArduinoJson.h> // JSON config file functions
extern void user_setup(void);
extern void user_setup(StaticJsonDocument<2048> &doc);
extern void user_loop(void);

// user callable functions
extern void eyesWide(bool);
extern void eyesBlink();
extern void eyesToCorner(float x, float y, bool immediate);
extern void eyesNormal();
6 changes: 6 additions & 0 deletions M4_Eyes/user.cpp
Expand Up @@ -15,6 +15,12 @@
void user_setup(void) {
}

// Called once after the processing of the configuration file. This allows
// user configuration to also be done based on the config file.
#include <ArduinoJson.h> // JSON config file functions
void user_setup(StaticJsonDocument<2048> &doc) {
}

// Called periodically during eye animation. This is invoked in the
// interval before starting drawing on the last eye (left eye on MONSTER
// M4SK, sole eye on HalloWing M0) so it won't exacerbate visible tearing
Expand Down
6 changes: 6 additions & 0 deletions M4_Eyes/user_fizzgig.cpp
Expand Up @@ -60,6 +60,12 @@ void user_setup(void) {
}
}

// Called once after the processing of the configuration file. This allows
// user configuration to also be done based on the config file.
#include <ArduinoJson.h> // JSON config file functions
void user_setup(StaticJsonDocument<2048> &doc) {
}

void user_loop(void) {
if(playing) {
// While WAV is playing, wiggle servo between middle and open-mouth positions:
Expand Down
6 changes: 6 additions & 0 deletions M4_Eyes/user_hid.cpp
Expand Up @@ -38,6 +38,12 @@ void user_setup(void) {
while( !USBDevice.mounted() ) delay(1);
}

// Called once after the processing of the configuration file. This allows
// user configuration to also be done based on the config file.
#include <ArduinoJson.h> // JSON config file functions
void user_setup(StaticJsonDocument<2048> &doc) {
}

void user_loop(void) {
if ( !usb_hid.ready() ) {
Serial.println("not ready");
Expand Down
6 changes: 6 additions & 0 deletions M4_Eyes/user_neopixel.cpp
Expand Up @@ -14,6 +14,12 @@ void user_setup(void) {

long firstPixelHue = 0;

// Called once after the processing of the configuration file. This allows
// user configuration to also be done based on the config file.
#include <ArduinoJson.h> // JSON config file functions
void user_setup(StaticJsonDocument<2048> &doc) {
}

void user_loop(void) {
for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip...
// Offset pixel hue by an amount to make one full revolution of the
Expand Down
6 changes: 6 additions & 0 deletions M4_Eyes/user_touchneopixels.cpp
Expand Up @@ -245,6 +245,12 @@ void user_setup(void) {
changeBehavior(0, micros());
}

// Called once after the processing of the configuration file. This allows
// user configuration to also be done based on the config file.
#include <ArduinoJson.h> // JSON config file functions
void user_setup(StaticJsonDocument<2048> &doc) {
}

void user_loop(void) {
uint32_t elapsedSince = micros();
if(elapsedSince - lastTouchSample > TOUCH_SAMPLE_TIME) {
Expand Down
10 changes: 7 additions & 3 deletions M4_Eyes/user_watch.cpp
Expand Up @@ -2,7 +2,7 @@
// CORRESPONDING LINE IN HeatSensor.cpp MUST ALSO BE ENABLED!

#include "globals.h"
#include "heatSensor.h"
#include "HeatSensor.h"

// For heat sensing
HeatSensor heatSensor;
Expand All @@ -25,6 +25,11 @@ void user_setup(void) {
heatSensor.setup();
}

// Called once after the processing of the configuration file. This allows
// user configuration to also be done via the config file.
void user_setup(StaticJsonDocument<2048> &doc) {
}

// Called periodically during eye animation. This is invoked in the
// interval before starting drawing on the last eye (left eye on MONSTER
// M4SK, sole eye on HalloWing M0) so it won't exacerbate visible tearing
Expand All @@ -35,8 +40,7 @@ void user_loop(void) {
heatSensor.find_focus();

// Set values for the new X and Y.
eyeTargetX = heatSensor.x;
eyeTargetY = -heatSensor.y;
eyesToCorner(heatSensor.x, -heatSensor.y, false);
}

#endif // 0