mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
0.1.0 I2C_SCANNER
This commit is contained in:
parent
5ab7ac8d21
commit
9ba6bb8d33
11
libraries/I2C_SCANNER/.arduino-ci.yml
Normal file
11
libraries/I2C_SCANNER/.arduino-ci.yml
Normal file
@ -0,0 +1,11 @@
|
||||
compile:
|
||||
# Choosing to run compilation tests on 2 different Arduino platforms
|
||||
platforms:
|
||||
- uno
|
||||
# - due
|
||||
# - zero
|
||||
# - leonardo
|
||||
- m4
|
||||
- esp32
|
||||
- esp8266
|
||||
# - mega2560
|
4
libraries/I2C_SCANNER/.github/FUNDING.yml
vendored
Normal file
4
libraries/I2C_SCANNER/.github/FUNDING.yml
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
github: RobTillaart
|
||||
|
13
libraries/I2C_SCANNER/.github/workflows/arduino-lint.yml
vendored
Normal file
13
libraries/I2C_SCANNER/.github/workflows/arduino-lint.yml
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
|
||||
name: Arduino-lint
|
||||
|
||||
on: [push, pull_request]
|
||||
jobs:
|
||||
lint:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: arduino/arduino-lint-action@v1
|
||||
with:
|
||||
library-manager: update
|
||||
compliance: strict
|
17
libraries/I2C_SCANNER/.github/workflows/arduino_test_runner.yml
vendored
Normal file
17
libraries/I2C_SCANNER/.github/workflows/arduino_test_runner.yml
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
---
|
||||
name: Arduino CI
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
runTest:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: ruby/setup-ruby@v1
|
||||
with:
|
||||
ruby-version: 2.6
|
||||
- run: |
|
||||
gem install arduino_ci
|
||||
arduino_ci.rb
|
18
libraries/I2C_SCANNER/.github/workflows/jsoncheck.yml
vendored
Normal file
18
libraries/I2C_SCANNER/.github/workflows/jsoncheck.yml
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
name: JSON check
|
||||
|
||||
on:
|
||||
push:
|
||||
paths:
|
||||
- '**.json'
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: json-syntax-check
|
||||
uses: limitusus/json-syntax-check@v1
|
||||
with:
|
||||
pattern: "\\.json$"
|
||||
|
56
libraries/I2C_SCANNER/I2C_SCANNER.cpp
Normal file
56
libraries/I2C_SCANNER/I2C_SCANNER.cpp
Normal file
@ -0,0 +1,56 @@
|
||||
//
|
||||
// FILE: I2C_SCANNER.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.0
|
||||
// DATE: 2022-08-29
|
||||
// PURPOSE: I2C scanner class
|
||||
//
|
||||
|
||||
#include "I2C_SCANNER.h"
|
||||
|
||||
|
||||
|
||||
I2C_SCANNER::I2C_SCANNER(TwoWire *wire)
|
||||
{
|
||||
_wire = wire;
|
||||
}
|
||||
|
||||
|
||||
#if defined (ESP8266) || defined(ESP32)
|
||||
bool I2C_SCANNER::begin(int dataPin, int clockPin)
|
||||
{
|
||||
_wire = &Wire;
|
||||
if ((dataPin < 255) && (clockPin < 255))
|
||||
{
|
||||
_wire->begin(dataPin, clockPin);
|
||||
} else {
|
||||
_wire->begin();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
bool I2C_SCANNER::begin()
|
||||
{
|
||||
_wire->begin();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool I2C_SCANNER::ping(uint8_t address)
|
||||
{
|
||||
_wire->beginTransmission(address);
|
||||
return ( _wire->endTransmission() == 0);
|
||||
}
|
||||
|
||||
|
||||
bool I2C_SCANNER::setClock(uint32_t clockFrequency)
|
||||
{
|
||||
_wire->setClock(clockFrequency);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
54
libraries/I2C_SCANNER/I2C_SCANNER.h
Normal file
54
libraries/I2C_SCANNER/I2C_SCANNER.h
Normal file
@ -0,0 +1,54 @@
|
||||
#pragma once
|
||||
//
|
||||
// FILE: I2C_SCANNER.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.0
|
||||
// DATE: 2022-08-29
|
||||
// PURPOSE: I2C scanner class
|
||||
//
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "Wire.h"
|
||||
|
||||
#define I2C_SCANNER_LIB_VERSION (F("0.1.0"))
|
||||
|
||||
|
||||
class I2C_SCANNER
|
||||
{
|
||||
public:
|
||||
|
||||
I2C_SCANNER(TwoWire *wire = &Wire);
|
||||
|
||||
#if defined (ESP8266) || defined(ESP32)
|
||||
bool begin(int sda, int scl);
|
||||
#endif
|
||||
bool begin();
|
||||
|
||||
bool ping(uint8_t address);
|
||||
|
||||
bool setClock(uint32_t clockFrequency = 100000UL);
|
||||
|
||||
|
||||
|
||||
private:
|
||||
uint8_t _devices[16]; // cache ?
|
||||
TwoWire* _wire;
|
||||
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* ideas
|
||||
*
|
||||
- set Wire
|
||||
- detect Wirecount
|
||||
|
||||
- set output stream
|
||||
|
||||
- set speed, re
|
||||
-
|
||||
|
||||
*/
|
||||
|
||||
// -- END OF FILE --
|
||||
|
21
libraries/I2C_SCANNER/LICENSE
Normal file
21
libraries/I2C_SCANNER/LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2022-2022 Rob Tillaart
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
45
libraries/I2C_SCANNER/README.md
Normal file
45
libraries/I2C_SCANNER/README.md
Normal file
@ -0,0 +1,45 @@
|
||||
|
||||
[![Arduino CI](https://github.com/RobTillaart/I2C_SCANNER/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
|
||||
[![Arduino-lint](https://github.com/RobTillaart/I2C_SCANNER/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/I2C_SCANNER/actions/workflows/arduino-lint.yml)
|
||||
[![JSON check](https://github.com/RobTillaart/I2C_SCANNER/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/I2C_SCANNER/actions/workflows/jsoncheck.yml)
|
||||
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/I2C_SCANNER/blob/master/LICENSE)
|
||||
[![GitHub release](https://img.shields.io/github/release/RobTillaart/I2C_SCANNER.svg?maxAge=3600)](https://github.com/RobTillaart/I2C_SCANNER/releases)
|
||||
|
||||
|
||||
# I2C_SCANNER
|
||||
|
||||
Arduino class to implement an I2C scanner.
|
||||
|
||||
|
||||
## Description
|
||||
|
||||
I2C_SCANNER is a class to build an I2C scanner, either minimal or more complex.
|
||||
|
||||
Goal is to rebuild my multispeed_I2C_scanner with this class.
|
||||
|
||||
|
||||
## Interface
|
||||
|
||||
TODO
|
||||
|
||||
|
||||
## Operation
|
||||
|
||||
See examples.
|
||||
|
||||
|
||||
## Future
|
||||
|
||||
|
||||
#### Must
|
||||
|
||||
- implement functionality
|
||||
- build examples.
|
||||
|
||||
|
||||
#### Should
|
||||
|
||||
- unit tests
|
||||
- documentation
|
||||
- Add all stuff needed.
|
||||
|
@ -0,0 +1,35 @@
|
||||
// FILE: I2C_scanner_minimal.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: demo minimal I2C scanner
|
||||
// URL: https://github.com/RobTillaart/I2C_SCANNER
|
||||
|
||||
|
||||
#include "I2C_SCANNER.h"
|
||||
|
||||
I2C_SCANNER scanner;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
while (!Serial);
|
||||
Serial.println();
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("I2C_SCANNER_LIB_VERSION: ");
|
||||
Serial.println(I2C_SCANNER_LIB_VERSION);
|
||||
|
||||
scanner.begin();
|
||||
|
||||
for (int addr = 0; addr < 128; addr++)
|
||||
{
|
||||
Serial.print(addr);
|
||||
Serial.print("\t");
|
||||
Serial.println(scanner.ping(addr));
|
||||
}
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
}
|
||||
|
||||
// -- END OF FILE --
|
||||
|
@ -0,0 +1,45 @@
|
||||
// FILE: I2C_scanner_simple.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: demo simple scanner
|
||||
// URL: https://github.com/RobTillaart/I2C_SCANNER
|
||||
|
||||
|
||||
#include "I2C_SCANNER.h"
|
||||
|
||||
I2C_SCANNER scanner;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
while (!Serial);
|
||||
Serial.println();
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("I2C_SCANNER_LIB_VERSION: ");
|
||||
Serial.println(I2C_SCANNER_LIB_VERSION);
|
||||
|
||||
scanner.begin();
|
||||
|
||||
for (int addr = 0; addr < 128; addr++)
|
||||
{
|
||||
if (addr % 8 == 0) Serial.println();
|
||||
if (scanner.ping(addr))
|
||||
{
|
||||
Serial.print(addr);
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.print("-");
|
||||
}
|
||||
Serial.print("\t");
|
||||
}
|
||||
Serial.println();
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
// -- END OF FILE --
|
14
libraries/I2C_SCANNER/keywords.txt
Normal file
14
libraries/I2C_SCANNER/keywords.txt
Normal file
@ -0,0 +1,14 @@
|
||||
# Syntax Colouring Map For I2C_SCANNER
|
||||
|
||||
# Data types (KEYWORD1)
|
||||
I2C_SCANNER KEYWORD1
|
||||
|
||||
# Methods and Functions (KEYWORD2)
|
||||
begin KEYWORD2
|
||||
ping KEYWORD2
|
||||
setClock KEYWORD2
|
||||
|
||||
|
||||
# Constants (LITERAL1)
|
||||
I2C_SCANNER_LIB_VERSION LITERAL1
|
||||
|
23
libraries/I2C_SCANNER/library.json
Normal file
23
libraries/I2C_SCANNER/library.json
Normal file
@ -0,0 +1,23 @@
|
||||
{
|
||||
"name": "I2C_SCANNER",
|
||||
"keywords": "I2C,scanner",
|
||||
"description": "Arduino class to implement an I2C scanner.",
|
||||
"authors":
|
||||
[
|
||||
{
|
||||
"name": "Rob Tillaart",
|
||||
"email": "Rob.Tillaart@gmail.com",
|
||||
"maintainer": true
|
||||
}
|
||||
],
|
||||
"repository":
|
||||
{
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/I2C_SCANNER.git"
|
||||
},
|
||||
"version": "0.1.0",
|
||||
"license": "MIT",
|
||||
"frameworks": "arduino",
|
||||
"platforms": "*",
|
||||
"headers": "I2C_SCANNER.h"
|
||||
}
|
11
libraries/I2C_SCANNER/library.properties
Normal file
11
libraries/I2C_SCANNER/library.properties
Normal file
@ -0,0 +1,11 @@
|
||||
name=I2C_SCANNER
|
||||
version=0.1.0
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Arduino class to implement an I2C scanner.
|
||||
paragraph=.
|
||||
category=Other
|
||||
url=https://github.com/RobTillaart/I2C_SCANNER
|
||||
architectures=*
|
||||
includes=I2C_SCANNER.h
|
||||
depends=
|
53
libraries/I2C_SCANNER/test/unit_test_001.cpp
Normal file
53
libraries/I2C_SCANNER/test/unit_test_001.cpp
Normal file
@ -0,0 +1,53 @@
|
||||
//
|
||||
// FILE: unit_test_001.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// DATE: 2022-08-29
|
||||
// PURPOSE: unit tests for the I2C_SCANNER class
|
||||
// https://github.com/RobTillaart/I2C_SCANNER
|
||||
// https://github.com/Arduino-CI/arduino_ci/blob/master/REFERENCE.md
|
||||
//
|
||||
|
||||
// supported assertions
|
||||
// ----------------------------
|
||||
// assertEqual(expected, actual)
|
||||
// assertNotEqual(expected, actual)
|
||||
// assertLess(expected, actual)
|
||||
// assertMore(expected, actual)
|
||||
// assertLessOrEqual(expected, actual)
|
||||
// assertMoreOrEqual(expected, actual)
|
||||
// assertTrue(actual)
|
||||
// assertFalse(actual)
|
||||
// assertNull(actual)
|
||||
|
||||
|
||||
#include <ArduinoUnitTests.h>
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "I2C_SCANNER.h"
|
||||
|
||||
#define A0 0
|
||||
|
||||
|
||||
unittest_setup()
|
||||
{
|
||||
fprintf(stderr, "I2C_SCANNER_LIB_VERSION: %s\n", (char *) I2C_SCANNER_LIB_VERSION);
|
||||
}
|
||||
|
||||
unittest_teardown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
unittest(test_constructor)
|
||||
{
|
||||
I2C_SCANNER scanner;
|
||||
scanner.begin();
|
||||
|
||||
assertEqual(1, 1); // keep build-CI happy
|
||||
}
|
||||
|
||||
|
||||
unittest_main()
|
||||
|
||||
|
||||
// -- END OF FILE --
|
Loading…
Reference in New Issue
Block a user