-
-
Notifications
You must be signed in to change notification settings - Fork 345
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR updates all the main Sming samples to try and demonstrate best practice when coding Sming applications. Specifically: - Initialise timers using templated methods where possible as this provides static range check on values - Using `SimpleTimer` is sufficient in most cases. This is both more efficient and avoids complication where compiler cannot distinguish between delegates and callback functions. - Use timer `startOnce()` method rather than `start(false)` - Use C++ iterators in preference to C-style loops `for(int i=0; i<list.count(); ++i) {...}` - Ensure consistent use of `WIFI_SSID` and `WIFI_PASSWORD` - Use `Serial` methods in preference to `debug_x` where intent is not actually for debugging - Use anonymous namespaces and remove redundant static declarations - Avoid nested `if` statements - Place `init()` function at end of main application source file - Reduce variable scope (declare at point of first use) - static/global variables do not require explicit initialisation to 0 Sample-specific changes: - Revise `HttpServer_AJAX` so that GPIO numbers are consistent with web code - Update Basic_Ssl keys, requires Bearssl - Update Basic_DateTime sample - Simplify code using LineBuffer - Accept either numeric timestamp or HTTP date string. Note: ISO8601 string conversion not currently supported by `DateTime`. - Don't emulate console via telnet, use default CLI - Rewrite Basic_Neopixel sample - Enumerate color values - Reduce global variables and duplicated code - Verify logic flow using Host - Rewrite Display_TM1637 as state machine (coroutine) - Fix Basic_Storage, didn't actually use RAM as indicated - Add Host `Print` stream support, update `Basic_Utility` sample Other changes - Update `jerryscript` library to latest. CI improvements and removes deprecation warnings. - Fix bad memory casts in si4432 library. Also builds for other architectures than esp8266, so remove SOC restrictions. - Fix unused variable warning in `CommandProcessing` library
- Loading branch information
Showing
113 changed files
with
1,878 additions
and
1,464 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
Sming/Arch/Host/Components/hostlib/include/hostlib/Streams.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* Streams.h - Print support for host output | ||
* | ||
* Copyright 2024 mikee47 <[email protected]> | ||
* | ||
* This file is part of the Sming Framework Project | ||
* | ||
* This library is free software: you can redistribute it and/or modify it under the terms of the | ||
* GNU General Public License as published by the Free Software Foundation, version 3 or later. | ||
* | ||
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | ||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
* See the GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along with SHEM. | ||
* If not, see <https://www.gnu.org/licenses/>. | ||
* | ||
****/ | ||
|
||
#pragma once | ||
|
||
#include <unistd.h> | ||
|
||
namespace Host | ||
{ | ||
class OutputStream : public Print | ||
{ | ||
public: | ||
OutputStream(int fileno) : fileno(fileno) | ||
{ | ||
} | ||
|
||
virtual size_t write(uint8_t c) override | ||
{ | ||
return write(&c, 1); | ||
} | ||
|
||
size_t write(const uint8_t* buffer, size_t size) override | ||
{ | ||
return ::write(fileno, buffer, size); | ||
} | ||
|
||
private: | ||
int fileno; | ||
}; | ||
|
||
OutputStream standardOutput(STDOUT_FILENO); | ||
OutputStream standardError(STDERR_FILENO); | ||
|
||
}; // namespace Host |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 13 additions & 12 deletions
25
Sming/Libraries/CS5460/samples/generic/app/application.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,31 @@ | ||
#include <SmingCore.h> | ||
#include <CS5460.h> | ||
|
||
namespace | ||
{ | ||
CS5460 powerMeter(PIN_NDEFINED, PIN_NDEFINED, PIN_NDEFINED, PIN_NDEFINED); | ||
|
||
Timer printVoltageTimer; | ||
SimpleTimer printVoltageTimer; | ||
|
||
void printVoltage() | ||
{ | ||
debugf("Measured RMS voltage is: %f", powerMeter.getRMSVoltage()); | ||
Serial << _F("Measured RMS voltage is: ") << powerMeter.getRMSVoltage() << endl; | ||
} | ||
|
||
} // namespace | ||
|
||
void init() | ||
{ | ||
Serial.begin(SERIAL_BAUD_RATE, SERIAL_8N1, | ||
SERIAL_FULL); // 115200 by default, GPIO1,GPIO3, see Serial.swap(), HardwareSerial | ||
Serial.begin(SERIAL_BAUD_RATE); | ||
Serial.systemDebugOutput(true); | ||
|
||
powerMeter.init(); | ||
powerMeter.setCurrentGain(190.84); //0.25 / shunt (0.00131) | ||
powerMeter.setVoltageGain(500); //0.25V (Veff max) * dividerGain | ||
uint32_t conf = 0; | ||
conf = powerMeter.readRegister(CONFIG_REGISTER); | ||
conf |= ENABLE_VOLTAGE_HPF; | ||
conf |= ENABLE_CURRENT_HPF; | ||
powerMeter.setCurrentGain(190.84); // 0.25 / shunt (0.00131) | ||
powerMeter.setVoltageGain(500); // 0.25V (Veff max) * dividerGain | ||
|
||
uint32_t conf = powerMeter.readRegister(CONFIG_REGISTER); | ||
conf |= ENABLE_VOLTAGE_HPF | ENABLE_CURRENT_HPF; | ||
powerMeter.writeRegister(CONFIG_REGISTER, conf); | ||
powerMeter.startMultiConvert(); | ||
|
||
printVoltageTimer.initializeMs(1000, printVoltage).start(); | ||
printVoltageTimer.initializeMs<1000>(printVoltage).start(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule jerryscript
updated
5 files
+21 −0 | .github/workflows/ci-dispatch.yml | |
+9 −0 | .github/workflows/ci-push.yml | |
+1 −1 | component.mk | |
+13 −0 | jerryscript.patch | |
+7 −1 | src/include/Jerryscript/Types.h |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.