Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
# Conflicts:
#	README.md
  • Loading branch information
NicolasBesson committed Jun 10, 2017
2 parents 920cfdc + 50ba4d4 commit ff62828
Show file tree
Hide file tree
Showing 19 changed files with 1,001 additions and 23 deletions.
92 changes: 92 additions & 0 deletions BlueRCCar/BlueRCCar.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
///////////////////////////////// License //////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Copyright 2017 Nicolas BESSON - BeeAtHome
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
///////////////////////////////////////////////////////////////////////////////

/******************************************************************************
* ____ _ _____ _____ _____
* | _ \| | | __ \ / ____/ ____|
* | |_) | |_ _ ___ | |__) | | | | __ _ _ __
* | _ <| | | | |/ _ \ | _ /| | | | / _` | '__|
* | |_) | | |_| | __/ | | \ \| |___| |___| (_| | |
* |____/|_|\__,_|\___| |_| \_\\_____\_____\__,_|_|
* Version 1.0
*
******************************************************************************/

#include <SoftwareSerial.h>
#include "Protocol.h"
#include "RCDriver.h"

/*
* ATTiny 85 pinout
*
* +-\/-+
* A0 PB5 1| |8 Vcc
* A3 PB3 2| |7 PB2 D0 A1
* A2 PB4 3| |6 PB1 D1
* GND 4| |5 PB0 D2
* +----+
*/

#define PIN_BLUETOOTH_RX PB3
#define PIN_BLUETOOTH_TX PB4
#define PIN_BLUETOOTH_STATE PB1
#define PIN_PCF8564_SDA PB0
#define PIN_PCF8564_SCL PB2

//
SoftwareSerial bluetoothSerial(PIN_BLUETOOTH_TX, PIN_BLUETOOTH_RX); // RX, TX
Protocol bluetoothProtocol;
RCDriver rcDriver;

void setup()
{
// Configure PIOs
pinMode(PIN_BLUETOOTH_STATE, INPUT);

// Enable Bluetooth Serial
bluetoothSerial.begin(9600);

// Enable rcDriver
rcDriver.begin();
}

void loop()
{
int data = 0x00;

// Data available from Bluetooth Serial
if (bluetoothSerial.available() > 0)
{
// Read the data
data = bluetoothSerial.read();

// Decode the protocol
bluetoothProtocol.command((unsigned char)data);
}
else
{

}

// Update driver based on received protocol
rcDriver.setState(bluetoothProtocol.getState());
rcDriver.enableExtra(bluetoothProtocol.isExtraEnabled());
rcDriver.setSpeed(bluetoothProtocol.getSpeed());

rcDriver.run();
}
22 changes: 22 additions & 0 deletions BlueRCCar/BlueRCCar.sln
Original file line number Diff line number Diff line change
@@ -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}") = "BlueRCCar", "BlueRCCar.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
105 changes: 105 additions & 0 deletions BlueRCCar/BlueRCCar.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?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>
</RootNamespace>
<ProjectName>BlueRCCar</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)..\..\..\_Tools\arduino-1.6.9-windows\arduino-1.6.9\hardware\arduino\avr\libraries\SoftwareSerial\src;$(ProjectDir)..\..\..\Users\nicolas\Documents\Arduino\libraries\TinyWireM;$(ProjectDir)..\..\..\_Tools\arduino-1.6.9-windows\arduino-1.6.9\libraries;$(ProjectDir)..\..\..\_Tools\arduino-1.6.9-windows\arduino-1.6.9\hardware\arduino\avr\libraries;$(ProjectDir)..\..\..\Users\nicolas\AppData\Local\arduino15\packages\attiny\hardware\avr\1.0.2\libraries;$(ProjectDir)..\..\..\Users\nicolas\Documents\Arduino\libraries;$(ProjectDir)..\..\..\_Tools\arduino-1.6.9-windows\arduino-1.6.9\hardware\arduino\avr\cores\arduino;$(ProjectDir)..\..\..\Users\nicolas\AppData\Local\arduino15\packages\attiny\hardware\avr\1.0.2\variants\tiny8;$(ProjectDir)..\BlueRCCar;$(ProjectDir)..\..\..\_Tools\arduino-1.6.9-windows\arduino-1.6.9\hardware\tools\avr\avr\include\;$(ProjectDir)..\..\..\_Tools\arduino-1.6.9-windows\arduino-1.6.9\hardware\tools\avr\avr\include\avr\;$(ProjectDir)..\..\..\_Tools\arduino-1.6.9-windows\arduino-1.6.9\hardware\tools\avr\lib\gcc\avr\4.8.1\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<ForcedIncludeFiles>$(ProjectDir)__vm\.BlueRCCar.vsarduino.h;%(ForcedIncludeFiles)</ForcedIncludeFiles>
<IgnoreStandardIncludePath>false</IgnoreStandardIncludePath>
<PreprocessorDefinitions>__AVR_ATtiny85__;__AVR_ATTINY85__;F_CPU=8000000L;ARDUINO=10609;ARDUINO_attiny;ARDUINO_ARCH_AVR;__cplusplus=201103L;%(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>
<PreprocessorDefinitions>__AVR_ATtiny85__;__AVR_ATTINY85__;F_CPU=1000000L;ARDUINO=10609;ARDUINO_attiny;ARDUINO_ARCH_AVR;__cplusplus=201103L;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ProjectCapability Include="VisualMicro" />
</ItemGroup>
<ItemGroup>
<None Include="BlueRCCar.ino">
<FileType>CppCode</FileType>
</None>
</ItemGroup>
<ItemGroup>
<ClInclude Include="PCF8574.h" />
<ClInclude Include="Protocol.h" />
<ClInclude Include="RCDriver.h" />
<ClInclude Include="__vm\.BlueRCCar.vsarduino.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="PCF8574.cpp" />
<ClCompile Include="Protocol.cpp" />
<ClCompile Include="RCDriver.cpp" />
</ItemGroup>
<PropertyGroup>
<DebuggerFlavor>VisualMicroDebugger</DebuggerFlavor>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
<ProjectExtensions>
<VisualStudio>
<UserProperties vm.upload.useprogrammer="1" custom_attiny_ATtinyX5_attiny85_clock="internal1" />
</VisualStudio>
</ProjectExtensions>
</Project>
52 changes: 52 additions & 0 deletions BlueRCCar/PCF8574.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
///////////////////////////////// License //////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Copyright 2017 Nicolas BESSON - BeeAtHome
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
///////////////////////////////////////////////////////////////////////////////
#include "PCF8574.h"


PCF8574::PCF8574():
ucDeviceAddress(PCF8574_ADDRESS_000)
{
}

PCF8574::~PCF8574()
{
}

void PCF8574::begin(unsigned char ucDeviceAddress)
{
this->ucDeviceAddress = ucDeviceAddress;
TinyWireM.begin();
}

void PCF8574::write(unsigned char data)
{
TinyWireM.beginTransmission(ucDeviceAddress);
TinyWireM.send(data); // Access Command Register
TinyWireM.endTransmission(); // Send to the slave
}

unsigned char PCF8574::read()
{
unsigned char data = 0x00;

TinyWireM.requestFrom(ucDeviceAddress, 1);
while (TinyWireM.available() == 0);
data = TinyWireM.receive();

return data;
}
100 changes: 100 additions & 0 deletions BlueRCCar/PCF8574.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
///////////////////////////////// License //////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Copyright 2017 Nicolas BESSON - BeeAtHome
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
///////////////////////////////////////////////////////////////////////////////

#ifndef _PCF8574_H
#define _PCF8574_H

#include <USI_TWI_Master.h>
#include <TinyWireM.h>

// Device Addresses
#define PCF8574_ADDRESS_000 0x20
#define PCF8574_ADDRESS_001 0x21
#define PCF8574_ADDRESS_010 0x22
#define PCF8574_ADDRESS_011 0x23
#define PCF8574_ADDRESS_100 0x24
#define PCF8574_ADDRESS_101 0x25
#define PCF8574_ADDRESS_110 0x26
#define PCF8574_ADDRESS_111 0x27

#define PCF8574A_ADDRESS_000 0x38
#define PCF8574A_ADDRESS_001 0x39
#define PCF8574A_ADDRESS_010 0x3A
#define PCF8574A_ADDRESS_011 0x3B
#define PCF8574A_ADDRESS_100 0x3C
#define PCF8574A_ADDRESS_101 0x3D
#define PCF8574A_ADDRESS_110 0x3E
#define PCF8574A_ADDRESS_111 0x3F


#define PCF8574_PIO(x) (0x1 << x)

#define PCF8574_PIO_0 PCF8574_PIO(0)
#define PCF8574_PIO_1 PCF8574_PIO(1)
#define PCF8574_PIO_2 PCF8574_PIO(2)
#define PCF8574_PIO_3 PCF8574_PIO(3)
#define PCF8574_PIO_4 PCF8574_PIO(4)
#define PCF8574_PIO_5 PCF8574_PIO(5)
#define PCF8574_PIO_6 PCF8574_PIO(6)
#define PCF8574_PIO_7 PCF8574_PIO(7)

#define PCF8574_PIO_MASK(x) (x)

/// <summary>
/// PCF8574 device manager
/// </summary>
class PCF8574
{
public:
/// <summary>
/// Initializes a new instance of the <see cref="PCF8574"/> class.
/// </summary>
PCF8574();

/// <summary>
/// Finalizes an instance of the <see cref="PCF8574"/> class.
/// </summary>
~PCF8574();

/// <summary>
/// Begins with the specified device address.
/// </summary>
/// <param name="ucDeviceAddress">The device address.</param>
void begin(unsigned char ucDeviceAddress);

/// <summary>
/// Writes device PIOs.
/// </summary>
/// <param name="data">The device PIO States</param>
void write(unsigned char data);

/// <summary>
/// Reads device PIOs.
/// </summary>
/// <returns>Device PIO States</returns>
unsigned char read();

private:
/// <summary>
/// The device address
/// </summary>
unsigned char ucDeviceAddress;
};


#endif // __PCF8574_H__
Loading

0 comments on commit ff62828

Please sign in to comment.