Where to put code for hardware configuration in movesense Firmware Application/Whiteboard? - movesense

I want to configure the max30003 chip only once at the beginning of the measurement. But I dont understand the structure, when my code is executed. I have a Modul "TestModul" in App.cpp by MOVESENSE_PROVIDER_DEF.
In the cpp of TestModul I have some functions to change the registers of max30003 as described in the documentation https://bitbucket.org/suunto/movesense-docs/wiki/EmbeddedSoftware/api/components/max3000x.
Are they going to be executed, everytime the modul is executed? Where do i have to put them? Init / Start Modul in testmodul.cpp ? When is the modul executed? Is there something like a main function?
Code og testmodul.hpp
private:
// INIT MODUL
virtual bool initModule() OVERRIDE;
// DEINIT MODUL
virtual void deinitModule() OVERRIDE;
// START MODUL
virtual bool startModule() OVERRIDE;
// STOP MODUL
virtual void stopModule() OVERRIDE { mModuleState = WB_RES::ModuleStateValues::STOPPED; }
// WB Provider onGETREQUEST
virtual void onGetRequest(..) OVERRIDE;
// WB Client onPutResult
virtual void onPutResult(..) OVERRIDE;
void writeMAX3000xRegister();
};

If you add your setup code in startModule() it will be run when the sensor starts after the framework services have started up.
Full Disclaimer: I work for the Movesense team

Related

How to re-register refit handlers in MAUI

In my MAUI, I register custom auth handlers using the following code snippet.
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.UseMauiCompatibility()
.UseMauiCommunityToolkit()
.RegisterRefitClients()
return builder.Build();
}
}
And my RegisterRefitClients extension method looks like this.
public static MauiAppBuilder RegisterRefitClients(this MauiAppBuilder mauiAppBuilder)
{
mauiAppBuilder.Services.AddRefitClient<IMyApiService>()
.ConfigureHttpClient(c => c.BaseAddress = new Uri(Configuration.BASE_URL))
.AddHttpMessageHandler<AuthHeaderHandler>();
return mauiAppBuilder;
}
Here, the thing is, Configuration.BASE_URL can change at run time. By default, it always points to our production server. But the testers can change it to staging/dev server at run time. I want to invoke this method at run time, in order to set custom auth handler for the newly changed staging server.
But I cannot get the MauiAppBuilder instance anywhere in the app once it is initiated.
How do I call the RegisterRefitClients at run time?
RegisterRefitClients can not be called when the program start running. .NET MAUI enables apps to be initialized from a single location. The MauiProgram class is the entry point to the application, setting up configuration and wiring up services the application will use. Once the program starts, you can not change the MauiProgram.

Simple Audio Player in Xamarin forms project doesn't work

I've just installed a package from nuget package manager Simple Audio Player and I wanted to play a sound or audio file but it doesn't work. In preferences of this project I accepted permission for r audio record and sti;; the same problem the code:
public MainPage()
{
InitializeComponent();
ISimpleAudioPlayer simpleAudioPlayer = CrossSimpleAudioPlayer.CreateSimpleAudioPlayer();;
Stream beepStream = GetType().Assembly.GetManifestResourceStream("App1.Beep.mp3");
ARandomMethod();
}
private void ARandomMethod()
{
if(sth happens)
{
simpleAudioPlayer.Play();
}
}
The error:
1)
Severity Code Description Project File Line Suppression State
Error NU1202 Package
Xam.Plugin.SimpleAudioPlayer.WPF 1.6.0 is not compatible with monoandroid13.0 (MonoAndroid,Version=v13.0). Package
Xam.Plugin.SimpleAudioPlayer.WPF 1.6.0 supports: net45
(.NETFramework,Version=v4.5) NewTimer.Android
C:\Users\PC\source\repos\NewTimer\NewTimer
\NewTimer.Android\NewTimer.Android.csproj 1
2)
Severity Code Description Project File Line Suppression State
Error CS0103 The name 'simpleAudioPlayer' does not exist in the current context NewTimer C:\Users\PC\source\repos\NewTimer\NewTimer\NewTimer\MainPage.xaml.cs 86 Active
How do I solve this problem to play sound or music using Simple Audio player?
this is a basic C# error. You are declaring a local variable inside a method, then trying to use it in another method. If you want to reference an object from multiple methods, you have to declare it at the class level so it remains in scope.
// declare this at the class level so it remains in scope
ISimpleAudioPlayer simpleAudioPlayer
public MainPage()
{
InitializeComponent();
simpleAudioPlayer = CrossSimpleAudioPlayer.CreateSimpleAudioPlayer();;

Unity Netcode's ClientRpc is not being sent across the network

I copy and pasted Unity Netcode's example code from https://docs-multiplayer.unity3d.com/docs/advanced-topics/message-system/clientrpc to test it out. This is my exact code:
public class Test : MonoBehaviour
{
public TMP_Text text;
void Update()
{
if (Input.GetKeyDown(KeyCode.P))
{
PongClientRpc(Time.frameCount, "hello, world"); // Server -> Client
}
}
[ClientRpc]
void PongClientRpc(int somenumber, string sometext)
{
text.text = $"{somenumber} : {sometext}";
Debug.Log(text.text);
}
}
What I've found is that the function just acts as a normal function whether it's called on the host application or client application, and it is never transmitted across the network. My expectation is that when it is called on the host application, the RPC would be transmitted to the client application and executed there as well, thus reflecting a change in the TMP_Text object, but clearly this is not the case.
Just to check all the boxes, this script is attached to a GameObject that also has a NetworkObject component. For good measure, I tested the TMP_Text object both with and without a NetworkObject component attached. In all cases, any object with a NetworkObject component was properly added to the NetworkManager's network prefabs list.
I'm starting to question if I even understand what an RPC is or how it's supposed to work. Any insights would be greatly appreciated!
This class needs to be derived from NetworkBehavior not MonoBehaviour else it won't be networked.
Make sure to add using Unity.Netcode; at the top of the class.

UPROPOERTY variables not showing in details

I´ve been trying to show some variables that I created in a C++ class and then create a Blueprint class based on it. But when I see the details of the object or try to find this variables in the Blueprints they do not show up.
I´ve basically copy and paste code from UE4 documentation see here: https://docs.unrealengine.com/en-us/Programming/Introduction, but the variables are not showing up for me.
// MyActor.cpp
#include "MyActor.h"
// Sets default values
AMyActor::AMyActor()
{
//PrimaryActorTick.bCanEverTick = true;
TotalDamage = 200.0f;
}
// Called when the game starts or when spawned
void AMyActor::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void AMyActor::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
// MyActor.h
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "MyActor.generated.h"
UCLASS()
class MYPROJECT3_API AMyActor : public AActor
{
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere)
float TotalDamage;
// Sets default values for this actor's properties
AMyActor();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
};
I want to modify this variables from the Event Graph. Please help me find what I did wrong, if you need anymore information I will gladly provide it to you.
Use BlueprintReadWrite or BlueprintReadOnly
UPROPERTY(EditAnywhere, BlueprintReadWrite)
float TotalDamage;
This just happened to me and feels like this is what might have happened to Juan Esteban as well, if you think your code is correct (and in my case it was):
"Hot Reloading" of the project was "stuck" in Unreal (i.e. changes made to the project didn't reflect in the editor), despite rebuilding the project and running "Refresh Visual Studio Project" from the file menu.
So... restarting Unreal actually fixed it.

stm32 and external flash (w25q) connection problem

I want to read/write from external flash (Winbond W25Q16BV) with STM32 micro (stm32F030F4). but running process halt on 'HAL_SPI_Init()' function.
I checked the debug process, and found HAL_SPI_STATE_BUSY.
but i don't know why?
I am using STM32CubeMX to generate main project and Keil IDE to write and debug.
SPI_HandleTypeDef hspi1;
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_SPI1_Init(void);
uint8_t spiData[2];
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_SPI1_Init();
MX_FATFS_Init();
SPI_HandleTypeDef my_hspi;
HAL_SPI_Init(&my_hspi);
HAL_FLASH_Unlock();
HAL_GPIO_WritePin(GPIOA,GPIO_PIN_1,GPIO_PIN_SET); // CS to HIGH
HAL_Delay(10);
//Read data
HAL_GPIO_WritePin(GPIOA,GPIO_PIN_1,GPIO_PIN_RESET); // CS to low
spiData[0]=0x05;
//transmit register address
HAL_SPI_Transmit(&my_hspi,spiData,1,10);
//read
HAL_SPI_Receive(&my_hspi,&spiData[1],1,10);
...
Here is our schematic:
Unfortunately, I did not find a good example/instruction of how to use external SPI libraries. Any help in this problem is highly appreciated.
I am not able to comment on the software, but according to your comment you want to enable the reading and writing of the flash.
The Write Protect (/WP) pin can be used to prevent the Status Register from being written.
The /WP pin is active low (GND). (Write disable)
The /WP pin is inactive high (VCC). (Write enable)
Its design only allows reading data.
If you want to read and write data, /WP must be connected to Vcc.
You have not set any parameters for the my_hspi struct so your HAL driver doesn't know what he has to do.
Look at the definition of the struct. There are a lot of comments what the different struct elements are used for. For initialization the my_hspi.init part will be most interesting.
Also you have to the the my_hspi.Instance to the desired SPI Channel.
You can generate an example configuration using the free STM32 Cube Mx Software.