mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
0.1.2 SIMON
This commit is contained in:
parent
2c7a276fa0
commit
affb0a60aa
@ -6,7 +6,7 @@ jobs:
|
||||
lint:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
- uses: arduino/arduino-lint-action@v1
|
||||
with:
|
||||
library-manager: update
|
||||
|
@ -8,7 +8,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
- uses: ruby/setup-ruby@v1
|
||||
with:
|
||||
ruby-version: 2.6
|
||||
|
@ -10,7 +10,7 @@ jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
- name: json-syntax-check
|
||||
uses: limitusus/json-syntax-check@v1
|
||||
with:
|
||||
|
@ -6,11 +6,18 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
||||
and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
|
||||
## [0.1.2] - 2023-02-02
|
||||
- update GitHub actions
|
||||
- update license 2023
|
||||
- allow define **SIMON_MAXSIZE** from command line.
|
||||
- update readme.md
|
||||
- minor edits
|
||||
|
||||
|
||||
## [0.1.1] - 2022-11-24
|
||||
- Add RP2040 support to build-CI.
|
||||
- Add CHANGELOG.md
|
||||
|
||||
|
||||
## [0.1.0] - 2022-05-26
|
||||
- initial version
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2022-2022 Rob Tillaart
|
||||
Copyright (c) 2022-2023 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
|
||||
|
@ -21,40 +21,53 @@ or access control.
|
||||
|
||||
## Interface
|
||||
|
||||
#### Base
|
||||
```cpp
|
||||
#include "simon.h"
|
||||
```
|
||||
|
||||
#### Construction
|
||||
|
||||
- **SIMON()** constructor.
|
||||
|
||||
- **bool setSequence(uint8_t \* array, uint8_t length)** set the
|
||||
returns false if count > max size or array == NULL
|
||||
- **uint8_t getSequence(uint8_t \* array)** returns length and
|
||||
fills the array with the set sequence.
|
||||
- **bool setSequence(uint8_t \* array, uint8_t length)** set the (secret) sequence.
|
||||
Returns false if length > **SIMON_MAXSIZE** or array == **NULL**.
|
||||
- **uint8_t getSequence(uint8_t \* array)** fills the array with the set sequence.
|
||||
Returns the length of the array.
|
||||
- **bool generateSequence(uint8_t length, uint8_t minimum, uint8_t maximum)** generates a
|
||||
random sequence of given length.
|
||||
Each value is between minimum and maximum inclusive, so ```generateSequence(5, 0, 10);``` may include both 0 and 10.
|
||||
Seed for the random function will be **micros()** for now.
|
||||
|
||||
- **void add(uint8_t value)** add next element to answer.
|
||||
if length becomes too large it is automatically cleared.
|
||||
- **void clear()** clears the current answer.
|
||||
|
||||
#### Core
|
||||
|
||||
- **bool verify()** check if answer matches the sequence.
|
||||
- **void add(uint8_t value)** add next element to the answer.
|
||||
if the length of the answer becomes too large it is automatically cleared.
|
||||
- **void clear()** explicit clears the current answer.
|
||||
- **bool verify()** check if the answer matches the (secret) sequence.
|
||||
- **bool verify(uint8_t \* array, uint8_t length)** check if array matches the sequence.
|
||||
|
||||
|
||||
#### Meta info
|
||||
|
||||
- **uint8_t length()** returns the length of the answer so far.
|
||||
- **uint8_t size()** returns the size of the "hidden" sequence.
|
||||
- **uint8_t maxSize()** returns**SIMON_MAXSIZE**.
|
||||
|
||||
|
||||
## Operation
|
||||
|
||||
A SIMON object holds a sequence of bytes of a given length which
|
||||
is set by **setSequence(array, length)**.
|
||||
The user can then **add()** elements to an internal storage and **verify()** if the the storage matches the original sequence.
|
||||
The user can then **add()** elements to an internal storage
|
||||
and **verify()** if the the storage matches the original sequence.
|
||||
|
||||
|
||||
### Game Simon says
|
||||
## Ideas
|
||||
|
||||
#### Game Simon says
|
||||
|
||||
(not implemented yet)
|
||||
|
||||
The game of **Simon says** has 4 lights, red, blue, yellow and green.
|
||||
It generates a random sequence and the user must repeat that sequence
|
||||
@ -63,8 +76,15 @@ otherwise decreased.
|
||||
|
||||
Also the timing can be shortened to make the game more difficult.
|
||||
|
||||
This can be implemented by generating a random sequence of increasing length
|
||||
every time the user inputs the right sequence.
|
||||
If the user fails to input the right sequence, the random sequence is shortened
|
||||
by one, or worst case "game over" and start over from 1.
|
||||
|
||||
### Lock - access control
|
||||
|
||||
#### Lock - access control
|
||||
|
||||
(not implemented yet)
|
||||
|
||||
The SIMON object can be used to hold a sequence that represents a code.
|
||||
The user must fill in the same code and test if they are the same.
|
||||
@ -74,30 +94,41 @@ A safer lock won't tell the user the length of the code.
|
||||
|
||||
Note that the "secret code" is not encrypted (at least for now)
|
||||
so it is not as safe as it can be.
|
||||
For real security other methods are needed.
|
||||
For real security, other methods are needed.
|
||||
|
||||
|
||||
## Future
|
||||
|
||||
### must
|
||||
#### Must
|
||||
|
||||
- improve documentation
|
||||
- add use of EEPROM to store a sequence over reboots
|
||||
- **SIMON(uint16_t EEPROM_ADDR)** constructor with EEPROM address
|
||||
|
||||
#### Should
|
||||
|
||||
- add examples
|
||||
- simon says game
|
||||
- digital lock
|
||||
|
||||
|
||||
### could
|
||||
### Could
|
||||
|
||||
- encrypted sequence (one way hash)
|
||||
- derived class.
|
||||
- disables **getSequence()** and **size()** and **maxSize()**
|
||||
- add **bool mastermind(uint8_t \* array, uint8_t &black, uint8_t &white)** compare? (good-wrong_location + good-good_location)
|
||||
- time constant version of **verify()**
|
||||
- add **bool mastermind(uint8_t \* array, uint8_t &black, uint8_t &white)** compare?
|
||||
- (good-wrong_location + good-good_location)
|
||||
- needs another type of verification.
|
||||
- class of its own.
|
||||
- MM solver and MM master
|
||||
|
||||
|
||||
#### Wont
|
||||
|
||||
- add use of EEPROM to store a sequence over reboots
|
||||
- **SIMON(uint16_t EEPROM_ADDR)** constructor with EEPROM address
|
||||
- constructor that changes **SIMON_MAXSIZE** or ?
|
||||
- define is OK for now, allows compile time changes.
|
||||
- dynamic allocation of array's?
|
||||
|
||||
- dynamic allocation of array's? Nope
|
||||
|
||||
|
@ -0,0 +1,66 @@
|
||||
//
|
||||
// FILE: SIMON_performance.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: demo
|
||||
// URL: https://github.com/RobTillaart/SIMON
|
||||
|
||||
|
||||
#include "simon.h"
|
||||
|
||||
SIMON simon;
|
||||
|
||||
uint32_t count = 0;
|
||||
uint32_t start, stop;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.print("Start ");
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("SIMON_LIB_VERSION:\t");
|
||||
Serial.println(SIMON_LIB_VERSION);
|
||||
|
||||
Serial.println("10x GENERATE");
|
||||
delay(100);
|
||||
start = micros();
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
simon.generateSequence(4, 0, 9);;
|
||||
}
|
||||
stop = micros();
|
||||
Serial.print("time:\t");
|
||||
Serial.println(stop - start);
|
||||
|
||||
|
||||
Serial.println("10x ADD + CLEAR");
|
||||
delay(100);
|
||||
start = micros();
|
||||
simon.clear();
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
simon.add(i);
|
||||
}
|
||||
stop = micros();
|
||||
Serial.print("time:\t");
|
||||
Serial.println(stop - start);
|
||||
|
||||
|
||||
Serial.println("10x VERIFY");
|
||||
delay(100);
|
||||
start = micros();
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
simon.verify();
|
||||
}
|
||||
stop = micros();
|
||||
Serial.print("time:\t");
|
||||
Serial.println(stop - start);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
}
|
||||
|
||||
// -- END OF FILE --
|
@ -0,0 +1,11 @@
|
||||
IDE 1.8.19
|
||||
Arduino UNO
|
||||
|
||||
SIMON_performance.ino
|
||||
SIMON_LIB_VERSION: 0.1.2
|
||||
10x GENERATE
|
||||
time: 3668
|
||||
10x ADD + CLEAR
|
||||
time: 16
|
||||
10x VERIFY
|
||||
time: 4
|
@ -9,9 +9,11 @@ SIMON KEYWORD1
|
||||
setSequence KEYWORD2
|
||||
generateSequence KEYWORD2
|
||||
getSequence KEYWORD2
|
||||
|
||||
clear KEYWORD2
|
||||
add KEYWORD2
|
||||
verify KEYWORD2
|
||||
|
||||
length KEYWORD2
|
||||
size KEYWORD2
|
||||
maxSize KEYWORD2
|
||||
@ -19,4 +21,5 @@ maxSize KEYWORD2
|
||||
|
||||
# Constants (LITERAL1)
|
||||
SIMON_LIB_VERSION LITERAL1
|
||||
|
||||
SIMON_MAXSIZE LITERAL1
|
||||
|
@ -15,7 +15,7 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/SIMON"
|
||||
},
|
||||
"version": "0.1.1",
|
||||
"version": "0.1.2",
|
||||
"license": "MIT",
|
||||
"frameworks": "arduino",
|
||||
"platforms": "*",
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=SIMON
|
||||
version=0.1.1
|
||||
version=0.1.2
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Arduino library to build the "Simon says" game or a digital lock.
|
||||
|
@ -2,7 +2,7 @@
|
||||
// FILE: simon.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// DATE: 2022-05-26
|
||||
// VERSION: 0.1.1
|
||||
// VERSION: 0.1.2
|
||||
// PURPOSE: Arduino library for SIMON
|
||||
// URL: https://github.com/RobTillaart/SIMON
|
||||
|
||||
|
@ -3,16 +3,19 @@
|
||||
// FILE: simon.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// DATE: 2022-05-26
|
||||
// VERSION: 0.1.1
|
||||
// VERSION: 0.1.2
|
||||
// PURPOSE: Arduino library for SIMON
|
||||
// URL: https://github.com/RobTillaart/SIMON
|
||||
|
||||
|
||||
#include "Arduino.h"
|
||||
|
||||
#define SIMON_LIB_VERSION (F("0.1.1"))
|
||||
#define SIMON_LIB_VERSION (F("0.1.2"))
|
||||
|
||||
|
||||
#ifndef SIMON_MAXSIZE
|
||||
#define SIMON_MAXSIZE 10
|
||||
#endif
|
||||
|
||||
|
||||
class SIMON
|
||||
@ -56,5 +59,5 @@ private:
|
||||
};
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.0
|
||||
// DATE: 2022-05-26
|
||||
// PURPOSE: unit tests for SIMON
|
||||
// PURPOSE: unit tests for SIMON library
|
||||
// https://github.com/RobTillaart/SIMON
|
||||
//
|
||||
|
||||
@ -41,6 +41,7 @@ unittest_setup()
|
||||
fprintf(stderr, "SIMON_LIB_VERSION: %s\n", (char *) SIMON_LIB_VERSION);
|
||||
}
|
||||
|
||||
|
||||
unittest_teardown()
|
||||
{
|
||||
}
|
||||
@ -167,4 +168,5 @@ unittest(test_verify)
|
||||
unittest_main()
|
||||
|
||||
|
||||
// --------
|
||||
// -- END OF FILE --
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user