Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/github.ulai/lethd' into he…
Browse files Browse the repository at this point in the history
…rmeld
  • Loading branch information
plan44 committed Jan 14, 2019
2 parents 6941670 + 34f699f commit 7e281e8
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
AC_INIT([lethd], [1.97], [luz@plan44.ch], [lethd], [https://plan44.ch/])
AC_INIT([lethd], [1.9.1], [luz@plan44.ch], [lethd], [https://plan44.ch/])
AC_PREREQ([2.59])

AC_CONFIG_AUX_DIR(configure_aux)
Expand Down
34 changes: 31 additions & 3 deletions src/neuron.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ ErrorPtr Neuron::processRequest(ApiRequestPtr aRequest)
if (cmd=="fire") {
return fire(aRequest);
}
if (cmd=="glow") {
return glow(aRequest);
}
if (cmd=="mute") {
return mute(aRequest);
}
return inherited::processRequest(aRequest);
}

Expand All @@ -112,6 +118,27 @@ ErrorPtr Neuron::fire(ApiRequestPtr aRequest)
}


ErrorPtr Neuron::glow(ApiRequestPtr aRequest)
{
LOG(LOG_INFO, "neuron glow");
if(axonState != AxonIdle || bodyState != BodyIdle) return Error::ok();
phi = 0;
bodyState = BodyGlowing;
glowBrightness = 0.5;
ticketAnimateBody.executeOnce(boost::bind(&Neuron::animateBody, this, _1));
return Error::ok();
}

ErrorPtr Neuron::mute(ApiRequestPtr aRequest)
{
JsonObjectPtr o = aRequest->getRequest()->get("on");
if (!o) {
return LethdApiError::err("missing 'on'");
}
isMuted = o->boolValue();
return Error::ok();
}

// MARK: ==== neuron operation


Expand Down Expand Up @@ -146,6 +173,7 @@ void Neuron::fire(double aValue)
axonState = AxonFiring;
phi = 0;
bodyState = BodyGlowing;
glowBrightness = 1;
ticketAnimateAxon.executeOnce(boost::bind(&Neuron::animateAxon, this, _1));
ticketAnimateBody.executeOnce(boost::bind(&Neuron::animateBody, this, _1));
}
Expand All @@ -154,7 +182,7 @@ void Neuron::measure(MLTimer &aTimer)
{
double value = sensor->value();
avg = (avg * (movingAverageCount - 1) + value) / movingAverageCount;
if(avg > threshold) fire(avg);
if(!isMuted && avg > threshold) fire(avg);
ticketMeasure.executeOnce(boost::bind(&Neuron::measure, this, _1), 10 * MilliSecond);
}

Expand Down Expand Up @@ -194,9 +222,9 @@ void Neuron::animateBody(MLTimer &aTimer)
for(int i = 0; i < numBodyLeds; i++) {
uint8_t c = sin(phi) * 255;
if(bodyState == BodyGlowing && abs(i - pos) < 4) {
if(ledChain2) ledChain2->setColorXY(i, 0, 0, 255, 178);
if(ledChain2) ledChain2->setColorXY(i, 0, 0, glowBrightness * 255.0, glowBrightness * 178);
} else {
if(ledChain2) ledChain2->setColorXY(i, 0, 0, c, 0.7 * c);
if(ledChain2) ledChain2->setColorXY(i, 0, 0, glowBrightness * c, glowBrightness * 0.7 * c);
}
}
if(ledChain2) ledChain2->show();
Expand Down
5 changes: 5 additions & 0 deletions src/neuron.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ namespace p44 {

int pos = 0;
double phi = 0;
double glowBrightness = 1;

bool isMuted = false;

public:

Expand Down Expand Up @@ -88,6 +91,8 @@ namespace p44 {
void animateBody(MLTimer &aTimer);

ErrorPtr fire(ApiRequestPtr aRequest);
ErrorPtr glow(ApiRequestPtr aRequest);
ErrorPtr mute(ApiRequestPtr aRequest);

void neuronSpike(double aValue);

Expand Down

0 comments on commit 7e281e8

Please sign in to comment.