Merge pull request #11 from ZeusWPI/first-info-module

First info module
This commit is contained in:
redfast00 2020-09-11 19:54:05 +02:00 committed by GitHub
commit 1a1e993329
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 57 additions and 47 deletions

View file

@ -0,0 +1,7 @@
## Serial number
This module provides a serial number for other modules to use. It consists of
7 random letters/digits that are shown on a LCD display.
### Credits
Module developed by redfast00.

View file

@ -0,0 +1,50 @@
// (c) 2020, redfast00
// See the LICENSE file for conditions for copying
#include <obus_module.h>
#include <LiquidCrystal.h>
#define SERIAL_NUMBER_SIZE 7
uint8_t serial_number[SERIAL_NUMBER_SIZE];
// true when we need to update the LCD display
bool render_now = false;
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
void setup() {
Serial.begin(115200);
lcd.begin(16, 2);
lcd.clear();
obus_module::setup(OBUS_TYPE_INFO, 1);
}
obus_can::message message;
void loop() {
obus_module::loopInfo(&message, info_generator);
if (render_now) {
render_now = false;
lcd.home();
lcd.clear();
lcd.print("Serial Number");
lcd.setCursor(0, 1);
for (int i = 0; i < SERIAL_NUMBER_SIZE; i++) {
lcd.write(serial_number[i]);
}
}
}
int info_generator(uint8_t* buffer) {
for (int i = 0; i < SERIAL_NUMBER_SIZE; i++) {
uint8_t generated = random(26 + 10);
if (generated < 26)
serial_number[i] = 'A' + generated;
else
serial_number[i] = '0' + (generated - 26);
}
memcpy(buffer, serial_number, SERIAL_NUMBER_SIZE);
render_now = true;
return SERIAL_NUMBER_SIZE;
}

View file

@ -1,6 +0,0 @@
## Testmodule info
This is a simple info module
### Credits
Module developed by redfast00.

View file

@ -1,41 +0,0 @@
// (c) 2020, redfast00
// See the LICENSE file for conditions for copying
#include <obus_module.h>
#include <LiquidCrystal.h>
uint8_t serial_number[7];
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
void setup() {
Serial.begin(115200);
obus_module::setup(OBUS_TYPE_INFO, OBUS_INFO_ID_DEVELOPMENT);
info_generator(serial_number);
lcd.begin(16, 2);
lcd.clear();
}
obus_can::message message;
void loop() {
bool is_message_valid = obus_module::loopInfo(&message, info_generator);
lcd.home();
for (int i = 0; i < 7; i++) {
lcd.write(serial_number[i]);
}
}
int info_generator(uint8_t* buffer) {
serial_number[0] = random('A', 'Z');
serial_number[1] = random('A', 'Z');
serial_number[2] = random('A', 'Z');
serial_number[3] = random('0', '9');
serial_number[4] = random('0', '9');
serial_number[5] = random('A', 'Z');
serial_number[6] = random('0', '9');
memcpy(buffer, serial_number, 7);
lcd.clear();
return 7;
}