/*
 * splitflap_positions.c
 *
 *  Created on: 16.10.2022
 *      Author: jonas
 */

#include <stdint.h>
#include "splitflap.h"
#include "splitflap_positions.h"


/* all letters of the splitflap in the correct order */
static const struct {
  Flap_t letter;
  uint16_t positionSteps;
} flapPositions[] = {
		/* all letters of the splitflap in the correct order */
		{.letter = ' ', .positionSteps = 0   },
		{.letter = 'A', .positionSteps = 13  },
		{.letter = 'B', .positionSteps = 26  },
		{.letter = 'C', .positionSteps = 38  },
		{.letter = 'D', .positionSteps = 51  },
		{.letter = 'E', .positionSteps = 64  },
		{.letter = 'F', .positionSteps = 77  },
		{.letter = 'G', .positionSteps = 90  },
		{.letter = 'H', .positionSteps = 102 },
		{.letter = 'I', .positionSteps = 115 },
		{.letter = 'J', .positionSteps = 128 },
		{.letter = 'K', .positionSteps = 141 },
		{.letter = 'L', .positionSteps = 154 },
		{.letter = 'M', .positionSteps = 166 },
		{.letter = 'N', .positionSteps = 179 },
		{.letter = 'O', .positionSteps = 192 },
		{.letter = 'P', .positionSteps = 205 },
		{.letter = 'Q', .positionSteps = 218 },
		{.letter = 'R', .positionSteps = 230 },
		{.letter = 'S', .positionSteps = 243 },
		{.letter = 'T', .positionSteps = 256 },
		{.letter = 'U', .positionSteps = 269 },
		{.letter = 'V', .positionSteps = 282 },
		{.letter = 'W', .positionSteps = 294 },
		{.letter = 'X', .positionSteps = 307 },
		{.letter = 'Y', .positionSteps = 320 },
		{.letter = 'Z', .positionSteps = 333 },
		{.letter = '0', .positionSteps = 346 },
		{.letter = '1', .positionSteps = 358 },
		{.letter = '2', .positionSteps = 371 },
		{.letter = '3', .positionSteps = 384 },
		{.letter = '4', .positionSteps = 397 },
		{.letter = '5', .positionSteps = 410 },
		{.letter = '6', .positionSteps = 422 },
		{.letter = '7', .positionSteps = 435 },
		{.letter = '8', .positionSteps = 448 },
		{.letter = '9', .positionSteps = 461 },
		{.letter = '!', .positionSteps = 474 },
		{.letter = '?', .positionSteps = 486 },
		{.letter = ':', .positionSteps = 499 }
};

uint8_t SF_Position_Get(Flap_t letter, Position_t* stepsPosition) {
  /* search letter in table */
  for(int i=0; i<sizeof(flapPositions)/sizeof(flapPositions[0]); i++) {
    if (letter==flapPositions[i].letter) { /* found */
      *stepsPosition = flapPositions[i].positionSteps;
      return ERR_OK;
    }
  }
  /* not found */
  return ERR_FAILED;
}
