dtmf_code

decodes ouput of a dmtf converter chip MT8870 connected to four gpio input pins.
Author: Crococode
License: BSD
Github: hug/gpio/dtmf_code.axo

Inlets

frac32 in1

frac32 i2

frac32 i3

frac32 i4

int32 shift

bool32 trig

Outlets

frac32 out

bool32 tone

bool32 code

Attributes

text code

Declaration
const int32_t thr = (43 << 20);
int32_t out;
int32_t hit;
int32_t trigged;
int32_t val1;
int32_t val2;
int32_t val3;
uint8_t timeout;
uint8_t success;
Init
out = 0;
trigged = 0;
hit = 0;
timeout = 0;
success = 0;
Control Rate
if ((inlet_trig == 1) && (trigged == 0)) {

  if (inlet_i4 < thr) {
    if (inlet_i3 < thr) {
      if (inlet_i2 < thr && inlet_i1 > thr) {
        out = ((36 - inlet_shift) << 20);
      }
      if (inlet_i2 > thr && inlet_i1 < thr) {
        out = ((37 - inlet_shift) << 20);
      }
      if (inlet_i2 > thr && inlet_i1 > thr) {
        out = ((38 - inlet_shift) << 20);
      }
    } else {
      if (inlet_i2 < thr && inlet_i1 < thr) {
        out = ((39 - inlet_shift) << 20);
      }
      if (inlet_i2 < thr && inlet_i1 > thr) {
        out = ((40 - inlet_shift) << 20);
      }
      if (inlet_i2 > thr && inlet_i1 < thr) {
        out = ((41 - inlet_shift) << 20);
      }
      if (inlet_i2 > thr && inlet_i1 > thr) {
        out = ((42 - inlet_shift) << 20);
      }
    }
  } else {
    if (inlet_i3 < thr) {
      if (inlet_i2 < thr && inlet_i1 < thr) {
        out = ((43 - inlet_shift) << 20);
      }
      if (inlet_i2 < thr && inlet_i1 > thr) {
        out = ((44 - inlet_shift) << 20);
      }
      if (inlet_i2 > thr && inlet_i1 < thr) {
        out = ((45 - inlet_shift) << 20);
      }
      if (inlet_i2 > thr && inlet_i1 > thr) {
        out = ((46 - inlet_shift) << 20);
      }
    } else {
      if (inlet_i2 < thr && inlet_i1 < thr) {
        out = ((47 - inlet_shift) << 20);
      }
    }
  }
  timeout++;
  if (timeout > 100) {
    trigged = 1;
    timeout = 0;
    attr_code;
    switch (hit) {
    case 0:
      if (out == ((val1 + 35 + inlet_shift) << 20)) {
        hit++;
      } else {
        hit = 0;
      }
      break;
    case 1:
      if (out == ((val2 + 35 + inlet_shift) << 20)) {
        hit++;
      } else {
        hit = 0;
      }
      break;
    case 2:
      hit = 0;
      if (out == ((val3 + 35 + inlet_shift) << 20)) {
        LogTextMessage("Code %d%d%d unlocked", val1, val2, val3);
        success = 1;
      }
      break;
    }
  }
}

outlet_out = out;
outlet_code = success;
if (trigged == 1) {
  outlet_tone = 1;
  if (inlet_trig != 1) {
    trigged = 0;
    success = 0;
  }
} else {
  outlet_tone = 0;
}

Privacy

© 2024 Zrna Research