<commit_before>/*
 *          Car rev display and shift indicator for Project Cars
 *          
 * This works via the UDP telemetry function. You'll need to enable it in the settings of the game.
 * I've had good results with settings around 5 (20 fps).
 * 
 */
const uint8_t PCARS_dimcolor = 20;
WiFiUDP UDP;
const unsigned int PCARS_localUdpPort = 5606; // local port to listen on
char PCARS_packet[2048];

char PCARS_tempChar[2]; // Temporary array for u16 conversion

u16 PCARS_RPM;
u16 PCARS_maxRPM;

long PCARS_lastRead = millis() - 2001;
float PCARS_rpmRatio;


void userSetup()
{
  UDP.begin(PCARS_localUdpPort);
}

void userConnected()
{
  // new wifi, who dis?
}

void userLoop()
{
  PCARS_readValues();
  if (PCARS_lastRead > millis() - 2000) {
    PCARS_buildcolorbars();
  }
}

void PCARS_readValues() {

  int PCARS_packetSize = UDP.parsePacket();
  if (PCARS_packetSize) {
    int len = UDP.read(PCARS_packet, PCARS_packetSize);
    if (len > 0) {
      PCARS_packet[len] = 0;
    }
    if (len == 1367) { // Telemetry packet. Ignoring everything else.
      PCARS_lastRead = millis();

      arlsLock(realtimeTimeoutMs, REALTIME_MODE_GENERIC);
      // current RPM
      memcpy(&PCARS_tempChar, &PCARS_packet[124], 2);
      PCARS_RPM = (PCARS_tempChar[1] << 8) + PCARS_tempChar[0];

      // max RPM
      memcpy(&PCARS_tempChar, &PCARS_packet[126], 2);
      PCARS_maxRPM = (PCARS_tempChar[1] << 8) + PCARS_tempChar[0];

      if (PCARS_maxRPM) {
        PCARS_rpmRatio = constrain((float)PCARS_RPM / (float)PCARS_maxRPM, 0, 1);
      } else {
        PCARS_rpmRatio = 0.0;
      }
    }
  }
}
void PCARS_buildcolorbars() {
  boolean activated = false;
  float ledratio = 0;

  for (uint16_t i = 0; i < ledCount; i++) {
    if (PCARS_rpmRatio < .95 || (millis() % 100 > 70 )) {

      ledratio = (float)i / (float)ledCount;
      if (ledratio < PCARS_rpmRatio) {
        activated = true;
      } else {
        activated = false;
      }
      if (ledratio > 0.66) {
        setRealtimePixel(i, 0, 0, PCARS_dimcolor + ((255 - PCARS_dimcolor)*activated), 0);
      } else if (ledratio > 0.33) {
        setRealtimePixel(i, PCARS_dimcolor + ((255 - PCARS_dimcolor)*activated), 0, 0, 0);
      } else {
        setRealtimePixel(i, 0, PCARS_dimcolor + ((255 - PCARS_dimcolor)*activated), 0, 0);
      }
    }
    else {
      setRealtimePixel(i, 0, 0, 0, 0);

    }
  }
  colorUpdated(5);
  strip.show();
}<commit_msg>make PCARS usermod compatible with WLED > 0.10.0<commit_after>/*
 *          Car rev display and shift indicator for Project Cars
 *          
 * This works via the UDP telemetry function. You'll need to enable it in the settings of the game.
 * I've had good results with settings around 5 (20 fps).
 * 
 */
const uint8_t PCARS_dimcolor = 20;
WiFiUDP UDP;
const unsigned int PCARS_localUdpPort = 5606; // local port to listen on
char PCARS_packet[2048];

char PCARS_tempChar[2]; // Temporary array for u16 conversion

u16 PCARS_RPM;
u16 PCARS_maxRPM;

long PCARS_lastRead = millis() - 2001;
float PCARS_rpmRatio;

void PCARS_readValues() {

  int PCARS_packetSize = UDP.parsePacket();
  if (PCARS_packetSize) {
    int len = UDP.read(PCARS_packet, PCARS_packetSize);
    if (len > 0) {
      PCARS_packet[len] = 0;
    }
    if (len == 1367) { // Telemetry packet. Ignoring everything else.
      PCARS_lastRead = millis();

      realtimeLock(realtimeTimeoutMs, REALTIME_MODE_GENERIC);
      // current RPM
      memcpy(&PCARS_tempChar, &PCARS_packet[124], 2);
      PCARS_RPM = (PCARS_tempChar[1] << 8) + PCARS_tempChar[0];

      // max RPM
      memcpy(&PCARS_tempChar, &PCARS_packet[126], 2);
      PCARS_maxRPM = (PCARS_tempChar[1] << 8) + PCARS_tempChar[0];

      if (PCARS_maxRPM) {
        PCARS_rpmRatio = constrain((float)PCARS_RPM / (float)PCARS_maxRPM, 0, 1);
      } else {
        PCARS_rpmRatio = 0.0;
      }
    }
  }
}
void PCARS_buildcolorbars() {
  boolean activated = false;
  float ledratio = 0;

  for (uint16_t i = 0; i < ledCount; i++) {
    if (PCARS_rpmRatio < .95 || (millis() % 100 > 70 )) {

      ledratio = (float)i / (float)ledCount;
      if (ledratio < PCARS_rpmRatio) {
        activated = true;
      } else {
        activated = false;
      }
      if (ledratio > 0.66) {
        setRealtimePixel(i, 0, 0, PCARS_dimcolor + ((255 - PCARS_dimcolor)*activated), 0);
      } else if (ledratio > 0.33) {
        setRealtimePixel(i, PCARS_dimcolor + ((255 - PCARS_dimcolor)*activated), 0, 0, 0);
      } else {
        setRealtimePixel(i, 0, PCARS_dimcolor + ((255 - PCARS_dimcolor)*activated), 0, 0);
      }
    }
    else {
      setRealtimePixel(i, 0, 0, 0, 0);

    }
  }
  colorUpdated(5);
  strip.show();
}

void userSetup()
{
  UDP.begin(PCARS_localUdpPort);
}

void userConnected()
{
  // new wifi, who dis?
}

void userLoop()
{
  PCARS_readValues();
  if (PCARS_lastRead > millis() - 2000) {
    PCARS_buildcolorbars();
  }
}
{'fraction_non_alphanumeric': 0.12622349102773248, 'fraction_numerical': 0.03874388254486134, 'mean_word_length': 2.8531029065200313, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3309186', 'n_tokens_mistral': 2051, 'n_tokens_neox': 1774, 'n_words': 436}