migrate to snprintf_P with progmem strings

This commit is contained in:
uvos 2022-03-10 22:21:22 +01:00
parent 3da07a3b45
commit ecf35c620c
3 changed files with 14 additions and 11 deletions

View file

@ -2,13 +2,14 @@
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <avr/pgmspace.h>
#include "serial.h"
#include "writepin.h"
void printTrainState(int id, Serial* serial)
{
snprintf(buffer, SNPRINTF_BUFFER_SIZE,
"TRAIN NUMBER: %u ADDRESS: %u CURRENT PACKET: %x SPEED: %i FUNCTIONS: %s FUNCTIONMASK: %s QUIRKS: %s\n",
snprintf_P(buffer, SNPRINTF_BUFFER_SIZE,
PSTR("TRAIN NUMBER: %u ADDRESS: %u CURRENT PACKET: %x SPEED: %i FUNCTIONS: %s FUNCTIONMASK: %s QUIRKS: %s\n"),
id, trains[id].getAddress(),
trains[id].getLastPacket(), trains[id].getSpeed(),
bit_rep[trains[id].getFunctions() & 0x0F], bit_rep[trains[id].getFunctionMask() & 0x0F],
@ -62,7 +63,7 @@ int trainDispatch(char* inBuffer, Serial* serial)
{
for(uint16_t j = 0; j < 255; j++)
{
snprintf(buffer, SNPRINTF_BUFFER_SIZE, "TRYING ADDR: %x\n", j);
snprintf_P(buffer, SNPRINTF_BUFFER_SIZE, PSTR("TRYING ADDR: %x\n"), j);
serial->write(buffer, strlen(buffer));
cli();
for(uint8_t k = 0; k < 10; k++)
@ -116,7 +117,7 @@ int trainDispatch(char* inBuffer, Serial* serial)
for(uint16_t j = 0; j < 1024 && !serial->dataIsWaiting(); j++)
{
trains[id].sendRaw(j);
snprintf(buffer, SNPRINTF_BUFFER_SIZE, "TRYING: %x\n", j);
snprintf_P(buffer, SNPRINTF_BUFFER_SIZE, PSTR("TRYING: %x\n"), j);
serial->write(buffer, strlen(buffer));
sei();
_delay_ms(250);
@ -133,7 +134,7 @@ int trainDispatch(char* inBuffer, Serial* serial)
{
cli();
uint16_t i = strtol(token, nullptr, 16 );
snprintf(buffer, SNPRINTF_BUFFER_SIZE, "SENDING: %x to %x\n", i, trains[id].getAddress());
snprintf_P(buffer, SNPRINTF_BUFFER_SIZE, PSTR("SENDING: %x to %x\n"), i, trains[id].getAddress());
serial->write(buffer, strlen(buffer));
for(uint8_t j = 0; j < 100; j++)
{