Add new Arduino project to solution (requires VisualMicro extension for sln build, or use Arduino ide with .ino file).

This commit is contained in:
chris.watts90@outlook.com 2017-07-18 20:31:40 +01:00
parent 4470db67b5
commit 857150ad28
15 changed files with 608 additions and 0 deletions

63
.gitattributes vendored Normal file
View File

@ -0,0 +1,63 @@
###############################################################################
# Set default behavior to automatically normalize line endings.
###############################################################################
* text=auto
###############################################################################
# Set default behavior for command prompt diff.
#
# This is need for earlier builds of msysgit that does not have it on by
# default for csharp files.
# Note: This is only used by command line
###############################################################################
#*.cs diff=csharp
###############################################################################
# Set the merge driver for project and solution files
#
# Merging from the command prompt will add diff markers to the files if there
# are conflicts (Merging from VS is not affected by the settings below, in VS
# the diff markers are never inserted). Diff markers may cause the following
# file extensions to fail to load in VS. An alternative would be to treat
# these files as binary and thus will always conflict and require user
# intervention with every merge. To do so, just uncomment the entries below
###############################################################################
#*.sln merge=binary
#*.csproj merge=binary
#*.vbproj merge=binary
#*.vcxproj merge=binary
#*.vcproj merge=binary
#*.dbproj merge=binary
#*.fsproj merge=binary
#*.lsproj merge=binary
#*.wixproj merge=binary
#*.modelproj merge=binary
#*.sqlproj merge=binary
#*.wwaproj merge=binary
###############################################################################
# behavior for image files
#
# image files are treated as binary by default.
###############################################################################
#*.jpg binary
#*.png binary
#*.gif binary
###############################################################################
# diff behavior for common document formats
#
# Convert binary document formats to text before diffing them. This feature
# is only available from the command line. Turn it on by uncommenting the
# entries below.
###############################################################################
#*.doc diff=astextplain
#*.DOC diff=astextplain
#*.docx diff=astextplain
#*.DOCX diff=astextplain
#*.dot diff=astextplain
#*.DOT diff=astextplain
#*.pdf diff=astextplain
#*.PDF diff=astextplain
#*.rtf diff=astextplain
#*.RTF diff=astextplain

2
.gitignore vendored
View File

@ -6,3 +6,5 @@
**dotsettings
**.DotSettings.user
**/.localhistory/**
**/Debug/**
**/Release/**

View File

@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "IrTransponderValidator", "IrTransponderValidator\IrTransponderValidator.vcxproj", "{C5F80730-F44F-4478-BDAE-6634EFC2CA88}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x86 = Debug|x86
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C5F80730-F44F-4478-BDAE-6634EFC2CA88}.Debug|x86.ActiveCfg = Debug|Win32
{C5F80730-F44F-4478-BDAE-6634EFC2CA88}.Debug|x86.Build.0 = Debug|Win32
{C5F80730-F44F-4478-BDAE-6634EFC2CA88}.Release|x86.ActiveCfg = Release|Win32
{C5F80730-F44F-4478-BDAE-6634EFC2CA88}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,10 @@
#pragma once
#define IR_SENSOR_INPUT 12
#define DISPLAY_CLK_PIN 2
#define DISPLAY_DAT_PIN 3
#define ID_RECOGNISED_EVENT 9930
#define SERIAL_BAUD_RATE 115200

View File

@ -0,0 +1,13 @@
//
//
//
#include "DisplayManager.h"
void DisplayManager::Initialise() {
_display.setSegments(SEG_INIT);
};
void DisplayManager::DisplayValue(int value) {
_display.showNumberDec(value, false);
};

View File

@ -0,0 +1,37 @@
// DisplayManager.h
#ifndef _DISPLAYMANAGER_h
#define _DISPLAYMANAGER_h
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
#include <stdio.h>
#include <TM1637Display.h>
#include "BoardDefs.h"
class DisplayManager {
public:
DisplayManager()
:
_display(DISPLAY_CLK_PIN, DISPLAY_DAT_PIN) {
_display.setBrightness(7);
};
void DisplayValue(int value);
void Initialise(void);
private:
TM1637Display _display;
const uint8_t SEG_INIT[4] = {
SEG_G, // -
SEG_G, // -
SEG_G, // -
SEG_G // -
};
};
#endif

View File

@ -0,0 +1,133 @@
//
//
//
#include "GPIOHelper.h"
void GPIOHelper::Init() {
SensorPulse = 0;
PrintArray(SensorData);
Serial.println(SensorData.size());
for (int i = 0; i < SensorData.size(); i++) {
SensorData.remove(0);
}
pinMode(IR_SENSOR_INPUT, INPUT);
Serial.println("initialised");
}
void GPIOHelper::Reset() {
LastSensorState = 0;
SensorPulse = 0;
SensorData.clear();
}
void GPIOHelper::Check() {
int state = digitalRead(IR_SENSOR_INPUT);
if (state != LastSensorState) {
//Serial.println("new state");
LastSensorState = state;
unsigned long c_time = micros();
unsigned long c_pulse = c_time - SensorPulse;
//Serial.println(c_time);
if (c_pulse >= PULSE_MIN && c_pulse <= PULSE_MAX) {
//valid pulse, process bit..
ProcessBit(c_pulse);
}
else {
if(SensorData.size()>= DATA_BIT_LENGTH)
SensorData.clear();
}
SensorPulse = c_time;
}
return;
}
void GPIOHelper::ProcessBit(unsigned long pulseWidth) {
if (pulseWidth >= PULSE_ONE) {
SensorData.add(1);
}
else {
SensorData.add(0);
}
//Serial.print("pulse: ");
//Serial.println(pulseWidth);
//Serial.println(SensorData.size());
if (SensorData.size() == DATA_BIT_LENGTH) {
//Serial.println("processing packet");
// first two bytes have to be zero
if (SensorData.get(0) == 0 && SensorData.get(1) == 0) {
//Serial.print("SensorDataLen: ");
//Serial.println(SensorData.size());
int datChkSum = SensorData.get(DATA_BIT_LENGTH-1);
SensorData.remove(DATA_BIT_LENGTH-1); //remove "checksum"
SensorData.remove(0); //remove two headers
SensorData.remove(0);
//Serial.println("publishing");
PublishData(SensorData, datChkSum);
while (SensorData.size() != 0) {
SensorData.pop();
}
}
else {
SensorData.remove(0);
}
//Serial.println("Exiting..");
}
return;
}
void GPIOHelper::PublishData(LinkedList<int>& data, int checksum) {
int id = -1;
bool validPacket = false;
unsigned int numOnes = Num_Ones_In_Buffer(data);
unsigned int calcChkSum = numOnes % 2;
/*Serial.print("1 count: ");
Serial.print(numOnes);
Serial.print(", odd number:");
Serial.print(checksum);
Serial.print(", calculated chk:");
Serial.println(calcChkSum);*/
if (calcChkSum == checksum)
validPacket = true;
if (validPacket) {
id = ConvertBitArrayToInt(data);
}
if (validPacket && id != 0) {
Serial.print("Id is: ");
Serial.println(id);
transponderId = id;
_evm.queueEvent(ID_RECOGNISED_EVENT, transponderId);
}
//Serial.println("exiting publish");
return;
}
void GPIOHelper::PrintArray(LinkedList<int>& arr) {
for (int i = 0; i < arr.size(); i++) {
Serial.println(arr.get(i));
}
return;
}
int GPIOHelper::ConvertBitArrayToInt(LinkedList<int>& arr) {
int multiplier = 1;
long bin = 0;
for (int i = arr.size()-1; i>=0; i--)
{
bin = bin + (multiplier * arr.get(i));
multiplier = multiplier* 2;
}
return bin;
}
unsigned int GPIOHelper::Num_Ones_In_Buffer(LinkedList<int>& data) {
unsigned int t = 0;
for (int i = 0; i < data.size(); i++) {
if (data.get(i) == 1) {
t += 1;
}
}
return t;
}

View File

@ -0,0 +1,43 @@
// GPIOHelper.h
#ifndef _GPIOHELPER_h
#define _GPIOHELPER_h
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
#include <stdio.h>
#include <LinkedList.h>
#include <EventManager.h>
#include "BoardDefs.h"
extern int transponderId;
class GPIOHelper {
public:
GPIOHelper(EventManager& evm) :_evm(evm) {};
void Init();
void Reset();
void Check();
private:
#define PULSE_ONE 500
#define PULSE_MIN 100
#define PULSE_MAX 1000
#define DATA_BIT_LENGTH 9
int LastSensorState;
unsigned long SensorPulse;
LinkedList<int> SensorData;
EventManager& _evm;
void ProcessBit(unsigned long pulseWidth);
void PublishData(LinkedList<int>& data, int checksum);
unsigned int Num_Ones_In_Buffer(LinkedList<int>& data);
int ConvertBitArrayToInt(LinkedList<int>& arr);
void PrintArray(LinkedList<int>& arr);
};
#endif

View File

@ -0,0 +1,36 @@
/*
Name: IrTransponderValidator.ino
Created: 7/18/2017 8:26:08 PM
Author: Chris Watts
*/
#include <EventManager.h>
#include "GPIOHelper.h"
#include "DisplayManager.h"
#include "BoardDefs.h"
int transponderId = -1;
EventManager _evtManager;
GPIOHelper gpio(_evtManager);
DisplayManager dispManager;
// the setup function runs once when you press reset or power the board
void setup() {
Serial.begin(SERIAL_BAUD_RATE);
_evtManager.addListener(ID_RECOGNISED_EVENT, myListener);
gpio.Init();
dispManager.Initialise();
}
// the loop function runs over and over again until power down or reset
void loop() {
gpio.Check();
//Serial.println("exiting loop");
_evtManager.processEvent();
}
void myListener(int eventCode, int eventParam)
{
Serial.println("Event Received");
dispManager.DisplayValue(eventParam);
// Do something with the event
}

View File

@ -0,0 +1,97 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{C5F80730-F44F-4478-BDAE-6634EFC2CA88}</ProjectGuid>
<RootNamespace>IrTransponderValidator</RootNamespace>
<ProjectName>IrTransponderValidator</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>
</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>
</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>$(ProjectDir)..\..\..\..\..\Users\chris\Documents\Arduino\libraries\EventManager;$(ProjectDir)..\..\..\..\..\Users\chris\Documents\Arduino\libraries\LinkedList;$(ProjectDir)..\..\..\..\..\Users\chris\Documents\Arduino\libraries\TM1637-1.1.0;$(ProjectDir)..\..\..\..\..\Program Files (x86)\Arduino\libraries;$(ProjectDir)..\..\..\..\..\Program Files (x86)\Arduino\hardware\arduino\avr\libraries;$(ProjectDir)..\..\..\..\..\Users\chris\Documents\Arduino\libraries;$(ProjectDir)..\..\..\..\..\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino;$(ProjectDir)..\..\..\..\..\Program Files (x86)\Arduino\hardware\arduino\avr\variants\eightanaloginputs;$(ProjectDir)..\IrTransponderValidator;$(ProjectDir)..\..\..\..\..\Program Files (x86)\Arduino\hardware\tools\avr\avr\include\;$(ProjectDir)..\..\..\..\..\Program Files (x86)\Arduino\hardware\tools\avr\avr\include\avr\;$(ProjectDir)..\..\..\..\..\Program Files (x86)\Arduino\hardware\tools\avr\lib\gcc\avr\4.8.1\include;$(ProjectDir)..\..\..\..\..\Program Files (x86)\Arduino\hardware\tools\avr\lib\gcc\avr\4.9.2\include;$(ProjectDir)..\..\..\..\..\Program Files (x86)\Arduino\hardware\tools\avr\lib\gcc\avr\4.9.3\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<ForcedIncludeFiles>$(ProjectDir)__vm\.IrTransponderValidator.vsarduino.h;%(ForcedIncludeFiles)</ForcedIncludeFiles>
<IgnoreStandardIncludePath>false</IgnoreStandardIncludePath>
<PreprocessorDefinitions>__AVR_ATmega328p__;__AVR_ATmega328P__;_VMDEBUG=1;F_CPU=16000000L;ARDUINO=10803;ARDUINO_AVR_NANO;ARDUINO_ARCH_AVR;__cplusplus=201103L;_VMICRO_INTELLISENSE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ProjectCapability Include="VisualMicro" />
</ItemGroup>
<PropertyGroup>
<DebuggerFlavor>VisualMicroDebugger</DebuggerFlavor>
</PropertyGroup>
<ItemGroup>
<None Include="IrTransponderValidator.ino">
<FileType>CppCode</FileType>
</None>
</ItemGroup>
<ItemGroup>
<ClInclude Include="BoardDefs.h" />
<ClInclude Include="DisplayManager.h" />
<ClInclude Include="GPIOHelper.h" />
<ClInclude Include="__vm\.IrTransponderValidator.vsarduino.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="DisplayManager.cpp" />
<ClCompile Include="GPIOHelper.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,42 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<None Include="IrTransponderValidator.ino" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="__vm\.IrTransponderValidator.vsarduino.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="BoardDefs.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="DisplayManager.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="GPIOHelper.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="DisplayManager.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="GPIOHelper.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ShowAllFiles>false</ShowAllFiles>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,82 @@
/*
Editor: http://www.visualmicro.com
visual micro and the arduino ide ignore this code during compilation. this code is automatically maintained by visualmicro, manual changes to this file will be overwritten
the contents of the Visual Micro sketch sub folder can be deleted prior to publishing a project
all non-arduino files created by visual micro and all visual studio project or solution files can be freely deleted and are not required to compile a sketch (do not delete your own code!).
note: debugger breakpoints are stored in '.sln' or '.asln' files, knowledge of last uploaded breakpoints is stored in the upload.vmps.xml file. Both files are required to continue a previous debug session without needing to compile and upload again
Hardware: Arduino Nano w/ ATmega328, Platform=avr, Package=arduino
*/
#if defined(_VMICRO_INTELLISENSE)
#ifndef _VSARDUINO_H_
#define _VSARDUINO_H_
#define __AVR_ATmega328p__
#define __AVR_ATmega328P__
#define _VMDEBUG 1
#define F_CPU 16000000L
#define ARDUINO 10803
#define ARDUINO_AVR_NANO
#define ARDUINO_ARCH_AVR
#define __cplusplus 201103L
#define __AVR__
#define __inline__
#define __asm__(...)
#define __extension__
#define __inline__
#define __volatile__
#define GCC_VERSION 40902
#define __cplusplus 201103L
#undef __cplusplus
#define __cplusplus 201103L
#define volatile(va_arg)
#define _CONST
#define __builtin_va_start
#define __builtin_va_end
#define __attribute__(...)
#define NOINLINE __attribute__((noinline))
#define prog_void
#define PGM_VOID_P int
#ifndef __builtin_constant_p
#define __builtin_constant_p __attribute__((__const__))
#endif
#ifndef __builtin_strlen
#define __builtin_strlen __attribute__((__const__))
#endif
#define NEW_H
typedef void *__builtin_va_list;
//extern "C" void __cxa_pure_virtual() {;}
typedef int div_t;
typedef int ldiv_t;
typedef void *__builtin_va_list;
//extern "C" void __cxa_pure_virtual() {;}
#include <Arduino.h>
#include <pins_arduino.h>
#undef F
#define F(string_literal) ((const PROGMEM char *)(string_literal))
#undef PSTR
#define PSTR(string_literal) ((const PROGMEM char *)(string_literal))
#define pgm_read_byte(address_short) uint8_t()
#define pgm_read_word(address_short) uint16_t()
#define pgm_read_dword(address_short) uint32_t()
#define pgm_read_float(address_short) float()
#define pgm_read_ptr(address_short) short()
#include "IrTransponderValidator.ino"
#endif
#endif

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long