<commit_before>/*
 * camera_test_app.cpp
 *
 * Author: <NAME>, <NAME>, <NAME>
 * Copyright (c) 2014-2015 HKUST SmartCar Team
 * Refer to LICENSE for details
 */

#include <cstdio>
#include <cstring>
#include <memory>

#include <libsc/k60/led.h>
#include <libsc/k60/ov7725.h>
#include <libsc/k60/st7735r.h>
#include <libsc/k60/system.h>
#include <libsc/k60/timer.h>
#include <libutil/looper.h>
#include <libutil/misc.h>

#include "camera_test_app.h"
#include "car.h"
#include "system_res.h"

using namespace libsc::k60;
using namespace libutil;
using namespace std;

namespace camera
{

void CameraTestApp::Run()
{
	printf("OV7725 Test\n");

	Car *car = GetSystemRes()->car;
	car->GetLcd().Clear(libutil::GetRgb565(0x33, 0xB5, 0xE5));

	const Uint image_size = car->GetCameraW() * car->GetCameraH() / 8;
	unique_ptr<Byte[]> image2(new Byte[image_size]);

	Looper looper;

	std::function<void(const Timer::TimerInt, const Timer::TimerInt)> blink =
			[&](const Timer::TimerInt request, const Timer::TimerInt)
			{
				car->GetLed(0).Switch();
				looper.RunAfter(request, blink);
			};
	looper.RunAfter(200, blink);

	car->GetCamera().Start();
	looper.ResetTiming();
	while (!car->GetButton(1).IsDown())
	{
		if (car->GetCamera().IsAvailable())<commit_msg>Also write encoder values in test app<commit_after>/*
 * camera_test_app.cpp
 *
 * Author: <NAME>, <NAME>, <NAME>
 * Copyright (c) 2014-2015 HKUST SmartCar Team
 * Refer to LICENSE for details
 */

#include <cstdio>
#include <cstring>
#include <memory>

#include <libsc/k60/lcd_typewriter.h>
#include <libsc/k60/led.h>
#include <libsc/k60/ov7725.h>
#include <libsc/k60/st7735r.h>
#include <libsc/k60/system.h>
#include <libsc/k60/timer.h>
#include <libutil/looper.h>
#include <libutil/misc.h>
#include <libutil/string.h>

#include "camera_test_app.h"
#include "car.h"
#include "system_res.h"

using namespace libsc::k60;
using namespace libutil;
using namespace std;

namespace camera
{

void CameraTestApp::Run()
{
	printf("OV7725 Test\n");

	Car *car = GetSystemRes()->car;
	car->GetLcd().Clear(libutil::GetRgb565(0x33, 0xB5, 0xE5));

	const Uint image_size = car->GetCameraW() * car->GetCameraH() / 8;
	unique_ptr<Byte[]> image2(new Byte[image_size]);

	Looper looper;

	std::function<void(const Timer::TimerInt, const Timer::TimerInt)> blink =
			[&](const Timer::TimerInt request, const Timer::TimerInt)
			{
				car->GetLed(0).Switch();
				looper.RunAfter(request, blink);
			};
	looper.RunAfter(200, blink);

	LcdTypewriter::Config writer_conf;
	writer_conf.lcd = &car->GetLcd();
	writer_conf.bg_color = libutil::GetRgb565(0x33, 0xB5, 0xE5);
	LcdTypewriter writer(writer_conf);

	car->GetLcd().SetRegion({0, 128, St7735r::GetW(), LcdTypewriter::GetFontH()});
	writer.WriteString("Encoder:");

	std::function<void(const Timer::TimerInt, const Timer::TimerInt)> encoder =
			[&](const Timer::TimerInt request, const Timer::TimerInt)
			{
				car->UpdateAllEncoders();
				car->GetLcd().SetRegion({0, 144, St7735r::GetW(),
						LcdTypewriter::GetFontH()});
				writer.WriteString(String::Format("%ld, %ld\n",
						car->GetEncoder(0).GetCount(),
						car->GetEncoder(1).GetCount()).c_str());
				looper.RunAfter(request, encoder);
			};
	looper.RunAfter(250, encoder);

	car->GetCamera().Start();
	looper.ResetTiming();
	while (!car->GetButton(1).IsDown())
	{
		if (car->GetCamera().IsAvailable())
{'fraction_non_alphanumeric': 0.1780821917808219, 'fraction_numerical': 0.03901131625967838, 'mean_word_length': 5.25512104283054, 'pattern_counts': {'":': 0, '<': 36, '<?xml version=': 0, '>': 58, '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': '5074922', 'n_tokens_mistral': 1435, 'n_tokens_neox': 1267, 'n_words': 239}