Пример #1
0
int16_t
parse_cmd_adc_get(char *cmd, char *output, uint16_t len)
{
  uint16_t adc;
  uint8_t channel;
  uint8_t ret = 0;
  if (cmd[0] && cmd[1])
  {
    channel = cmd[1] - '0';
    if (channel < ADC_CHANNELS)
    {
      adc = adc_get(channel);
      channel = ADC_CHANNELS;
      goto adc_out;
    }
    else
      return ECMD_ERR_PARSE_ERROR;
  }
  for (channel = 0; channel < ADC_CHANNELS; channel++)
  {
    adc = adc_get(channel);
  adc_out:
    output[0] = NIBBLE_TO_HEX(LO4(HI8(adc)));
    output[1] = NIBBLE_TO_HEX(HI4(LO8(adc)));
    output[2] = NIBBLE_TO_HEX(LO4(adc));
    output[3] = ' ';
    output[4] = 0;
    ret += 4;
    output += 4;
  }
  return ECMD_FINAL(ret);
}
Пример #2
0
uint8_t byte2hex (uint8_t value, char *string)
{
  // convert high nibble into hex ascii
  string[0] = NIBBLE_TO_HEX(HI4(value));

  // convert low nibble into hex ascii
  string[1] = NIBBLE_TO_HEX(LO4(value));

  return (2);
}
Пример #3
0
static uint8_t print_port(char *output, uint8_t len, uint8_t port, uint8_t value) 
{
#ifndef TEENSY_SUPPORT
        return snprintf_P(output, len,
                PSTR("port %d: 0x%02x"),
                port, value);
#else
        memcpy_P(output, PSTR("port P: 0x"), strlen("port P: 0x"));
        /* Convert to number :) */
        output[5] = port + 48;
        output[10] = NIBBLE_TO_HEX((value >> 4) & 0x0F);
        output[11] = NIBBLE_TO_HEX(value & 0x0F);
        return 12;
#endif
}