<commit_before>/*
 * cmd_ledstripe.c
 *
 *  Created on: Apr 4, 2015
 *      Author: Ollo
 */

#include "cmd.h"
#include "ledstripe/ledstripe.h"
#include "usbcdc/usbcdc.h"

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#include "ch.h"
#include "hal.h"

#include "chprintf.h"
#include "shell.h"

/******************************************************************************
 * DEFINES
 ******************************************************************************/

#define LED_END_POSTION		0

#define	STARTOFFSET				2
#define HEX_SIZE				2
#define TEXTLINE_MAX_LENGTH 	1024

#define DEBUG_PRINT( ... )	chprintf((BaseSequentialStream *) &SD6, __VA_ARGS__);/**< Uart print */

/******************************************************************************
 * GLOBAL VARIABLES for this module
 ******************************************************************************/

/******************************************************************************
 * LOCAL VARIABLES for this module
 ******************************************************************************/
static WORKING_AREA(waLEDstripBlink, 2048);

/******************************************************************************
 * LOCAL FUNCTIONS for this module
 ******************************************************************************/

static msg_t ledThread(void *arg);

/*
 * This is a periodic thread that does absolutely nothing except flashing
 * a LED.
 */
static msg_t
ledThread(void *arg)
{
  int pos_r = 0;
  int pos_g = 0;
  int pos_b = 0;

  (void) arg;
  chRegSetThreadName("led-test");
  while (TRUE)
    {
      //code for running light
      pos_r %= LEDSTRIPE_FRAMEBUFFER_SIZE;
      pos_g %= LEDSTRIPE_FRAMEBUFFER_SIZE;
      pos_b %= LEDSTRIPE_FRAMEBUFFER_SIZE;
      ledstripe_framebuffer[pos_r].red = 255;
      if (pos_r > 0)
        ledstripe_framebuffer[pos_r - 1].red = 64;
      if (pos_r > 1)
        ledstripe_framebuffer[pos_r - 2].red = 10;
      ledstripe_framebuffer[pos_g].green = 0;
      if (pos_g > 0)
        ledstripe_framebuffer[pos_g - 1].green = 0;
      if (pos_g > 1)
        ledstripe_framebuffer[pos_g - 2].green = 0;
      ledstripe_framebuffer[pos_b].blue = 255;
      ;
      if (pos_b > 0)
        ledstripe_framebuffer[pos_b - 1].blue = 64;
      if (pos_b > 1)
        ledstripe_framebuffer[pos_b - 2].blue = 10;
      chThdSleepMilliseconds(10);
      ledstripe_framebuffer[pos_r].red = 0;
      if (pos_r > 0)
        ledstripe_framebuffer[pos_r - 1].red = 0;
      if (pos_r > 1)
        ledstripe_framebuffer[pos_r - 2].red = 0;
      pos_r++;
      ledstripe_framebuffer[pos_g].green = 0;
      if (pos_g > 0)
        ledstripe_framebuffer[pos_g - 1].green = 0;
      if (pos_g > 1)
        ledstripe_framebuffer[pos_g - 2].green = 0;
      pos_g++;
      ledstripe_framebuffer[pos_b].blue = 0;
      if (pos_b > 0)
        ledstripe_framebuffer[pos_b - 1].blue = 0;
      if (pos_b > 1)
        ledstripe_framebuffer[pos_b - 2].blue = 0;
      pos_b++;
    }

  return RDY_OK;
}



static void readDirectWS2812cmd(BaseSequentialStream *chp)
{
	int i, length, j = 0;
	char textbuffer[TEXTLINE_MAX_LENGTH];
	int r = usbcdc_readAll(textbuffer, TEXTLINE_MAX_LENGTH);
	if(r >= 2 && (textbuffer[0] == 'W' && textbuffer[1] == 'S'))
	{
		if (chp != NULL) {
			chprintf(chp, "Go one: '%s'\r\n", textbuffer);
		}

		DEBUG_PRINT("Go one: '%s'\r\n", textbuffer);
		length = r - 2;
		for(i=0; i < length; i+=3){
			  ledstripe_framebuffer[j].red = 	(uint8_t) textbuffer[i+0];
			  ledstripe_framebuffer[j].green = 	(uint8_t) textbuffer[i+1];
			  ledstripe_framebuffer[j].blue = 	(uint8_t) textbuffer[i+2];
			  j++;
		}
	}
	else
	{
		if (chp != NULL) {
			chprintf(chp, "Found only '%s'\r\n", textbuffer);
		}
	}
}

/******************************************************************************
 * GLOBAL FUNCTIONS for this module
 ******************************************************************************/

void cmd_ledctrl(BaseSequentialStream *chp, int argc, char *argv[])
{
  int i;
  if (argc >= 1 && strcmp(argv[0], "test1") == 0)
    {
      chprintf(chp, "Red ...\r\n");
      for (i = 0; i < LEDSTRIPE_FRAMEBUFFER_SIZE; i++)
        {
          ledstripe_framebuffer[i].red = 255;
          ledstripe_framebuffer[i].green = 0;
          ledstripe_framebuffer[i].blue = 0;
        }
      chThdSleepMilliseconds(5000);
      chprintf(chp, "Green ...\r\n");
      for (i = 0; i < LEDSTRIPE_FRAMEBUFFER_SIZE; i++)
        {
          ledstripe_framebuffer[i].green = 255;
          ledstripe_framebuffer[i].red = 0;
          ledstripe_framebuffer[i].blue = 0;<commit_msg>more debug code into the reading function integrated<commit_after>/*
 * cmd_ledstripe.c
 *
 *  Created on: Apr 4, 2015
 *      Author: Ollo
 */

#include "cmd.h"
#include "ledstripe/ledstripe.h"
#include "usbcdc/usbcdc.h"

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#include "ch.h"
#include "hal.h"

#include "chprintf.h"
#include "shell.h"

/******************************************************************************
 * DEFINES
 ******************************************************************************/

#define LED_END_POSTION		0

#define	STARTOFFSET				2
#define HEX_SIZE				2
#define TEXTLINE_MAX_LENGTH 	1024

#define DEBUG_PRINT( ... )	chprintf((BaseSequentialStream *) &SD6, __VA_ARGS__);/**< Uart print */

/******************************************************************************
 * GLOBAL VARIABLES for this module
 ******************************************************************************/

/******************************************************************************
 * LOCAL VARIABLES for this module
 ******************************************************************************/
static WORKING_AREA(waLEDstripBlink, 2048);

/******************************************************************************
 * LOCAL FUNCTIONS for this module
 ******************************************************************************/

static msg_t ledThread(void *arg);

/*
 * This is a periodic thread that does absolutely nothing except flashing
 * a LED.
 */
static msg_t
ledThread(void *arg)
{
  int pos_r = 0;
  int pos_g = 0;
  int pos_b = 0;

  (void) arg;
  chRegSetThreadName("led-test");
  while (TRUE)
    {
      //code for running light
      pos_r %= LEDSTRIPE_FRAMEBUFFER_SIZE;
      pos_g %= LEDSTRIPE_FRAMEBUFFER_SIZE;
      pos_b %= LEDSTRIPE_FRAMEBUFFER_SIZE;
      ledstripe_framebuffer[pos_r].red = 255;
      if (pos_r > 0)
        ledstripe_framebuffer[pos_r - 1].red = 64;
      if (pos_r > 1)
        ledstripe_framebuffer[pos_r - 2].red = 10;
      ledstripe_framebuffer[pos_g].green = 0;
      if (pos_g > 0)
        ledstripe_framebuffer[pos_g - 1].green = 0;
      if (pos_g > 1)
        ledstripe_framebuffer[pos_g - 2].green = 0;
      ledstripe_framebuffer[pos_b].blue = 255;
      ;
      if (pos_b > 0)
        ledstripe_framebuffer[pos_b - 1].blue = 64;
      if (pos_b > 1)
        ledstripe_framebuffer[pos_b - 2].blue = 10;
      chThdSleepMilliseconds(10);
      ledstripe_framebuffer[pos_r].red = 0;
      if (pos_r > 0)
        ledstripe_framebuffer[pos_r - 1].red = 0;
      if (pos_r > 1)
        ledstripe_framebuffer[pos_r - 2].red = 0;
      pos_r++;
      ledstripe_framebuffer[pos_g].green = 0;
      if (pos_g > 0)
        ledstripe_framebuffer[pos_g - 1].green = 0;
      if (pos_g > 1)
        ledstripe_framebuffer[pos_g - 2].green = 0;
      pos_g++;
      ledstripe_framebuffer[pos_b].blue = 0;
      if (pos_b > 0)
        ledstripe_framebuffer[pos_b - 1].blue = 0;
      if (pos_b > 1)
        ledstripe_framebuffer[pos_b - 2].blue = 0;
      pos_b++;
    }

  return RDY_OK;
}



static void readDirectWS2812cmd(BaseSequentialStream *chp)
{
	int i, j = 0;
	char textbuffer[TEXTLINE_MAX_LENGTH];
	int length = usbcdc_readAll(textbuffer, TEXTLINE_MAX_LENGTH);
	if(length >= 2 && (textbuffer[0] == 'W' && textbuffer[1] == 'S'))
	{
		if (chp != NULL) {
			chprintf(chp, "Go one: '%s'\r\n", textbuffer);
		}

		DEBUG_PRINT("Go one: '");
		for(i=2; i < length; i+=3){
			  ledstripe_framebuffer[j].red = 	(uint8_t) textbuffer[i+0];
			  ledstripe_framebuffer[j].green = 	(uint8_t) textbuffer[i+1];
			  ledstripe_framebuffer[j].blue = 	(uint8_t) textbuffer[i+2];
			  j++;
			  DEBUG_PRINT("%.2X%.2X%.2X ", textbuffer[i+0], textbuffer[i+1], textbuffer[i+2]);
		}
		DEBUG_PRINT("\r\n");
	}
	else
	{
		DEBUG_PRINT("Received only: '%s'\r\n", textbuffer);
	}
}

/******************************************************************************
 * GLOBAL FUNCTIONS for this module
 ******************************************************************************/

void cmd_ledctrl(BaseSequentialStream *chp, int argc, char *argv[])
{
  int i;
  if (argc >= 1 && strcmp(argv[0], "test1") == 0)
    {
      chprintf(chp, "Red ...\r\n");
      for (i = 0; i < LEDSTRIPE_FRAMEBUFFER_SIZE; i++)
        {
          ledstripe_framebuffer[i].red = 255;
          ledstripe_framebuffer[i].green = 0;
          ledstripe_framebuffer[i].blue = 0;
        }
      chThdSleepMilliseconds(5000);
      chprintf(chp, "Green ...\r\n");
      for (i = 0; i < LEDSTRIPE_FRAMEBUFFER_SIZE; i++)
        {
          ledstripe_framebuffer[i].green = 255;
          ledstripe_framebuffer[i].red = 0;
          ledstripe_framebuffer[i].blue = 0;
{'fraction_non_alphanumeric': 0.28379972123941244, 'fraction_numerical': 0.023909081162217218, 'mean_word_length': 3.4932562620423893, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 37, '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': '4646598', 'n_tokens_mistral': 3431, 'n_tokens_neox': 3102, 'n_words': 625}