From 0b47f61a0cd7f27ebae75e55179f0be651f9d0e9 Mon Sep 17 00:00:00 2001 From: Eliott-Guevel Date: Tue, 24 Oct 2023 09:54:09 +0200 Subject: [PATCH 1/6] Added more components for the Molecule GPS example, as well as tests and a script to stop the current launched component in order to swap to another one --- src/Molecule-Examples/MolGNSSGalileo.class.st | 81 +++++++++++++++++++ src/Molecule-Examples/MolGPSDataImpl.class.st | 21 +++-- .../MolGPSExampleLauncher.class.st | 70 ++++++++++++++-- src/Molecule-Examples/MolGPSHardware.class.st | 17 ++-- src/Molecule-Examples/MolGSM.class.st | 81 +++++++++++++++++++ src/Molecule-Examples/MolWiFi.class.st | 81 +++++++++++++++++++ 6 files changed, 326 insertions(+), 25 deletions(-) create mode 100644 src/Molecule-Examples/MolGNSSGalileo.class.st create mode 100644 src/Molecule-Examples/MolGSM.class.st create mode 100644 src/Molecule-Examples/MolWiFi.class.st diff --git a/src/Molecule-Examples/MolGNSSGalileo.class.st b/src/Molecule-Examples/MolGNSSGalileo.class.st new file mode 100644 index 00000000..c2aabf51 --- /dev/null +++ b/src/Molecule-Examples/MolGNSSGalileo.class.st @@ -0,0 +1,81 @@ +Class { + #name : #MolGNSSGalileo, + #superclass : #MolAbstractComponentImpl, + #traits : 'MolGPSData + MolGPSDataServices', + #classTraits : 'MolGPSData classTrait + MolGPSDataServices classTrait', + #instVars : [ + 'accuracy', + 'sendCurrentPositionThread' + ], + #category : #'Molecule-Examples-GPS Example' +} + +{ #category : #services } +MolGNSSGalileo >> accuracy [ + + ^ accuracy +] + +{ #category : #services } +MolGNSSGalileo >> accuracy: anObject [ + + accuracy := anObject +] + +{ #category : #services } +MolGNSSGalileo >> componentActivate [ + "Start a thread to simulate sending of the geo position and accuracy precision each second" + + sendCurrentPositionThread := [ + [ true ] whileTrue: [ + (Delay forMilliseconds: 50) wait. + self getMolGPSDataEventsNotifier + currentPositionChanged: + self getRandomizedGNSSGalileoPosition. + self increaseAccuracy ] ] forkAt: + Processor userBackgroundPriority +] + +{ #category : #services } +MolGNSSGalileo >> componentInitialize [ + "Set starting accuracy" + + self accuracy: 1000 +] + +{ #category : #services } +MolGNSSGalileo >> componentPassivate [ + + sendCurrentPositionThread ifNotNil: [ :e | e terminate ]. + sendCurrentPositionThread := nil +] + +{ #category : #services } +MolGNSSGalileo >> getAccuracyRadiusInMeters [ + "Get and return the accuracy of the GPS depending quality of signal and quantity of connected satellites" + + ^ self accuracy +] + +{ #category : #'component accessing' } +MolGNSSGalileo >> getMolGPSDataEventsNotifier [ + ^self eventsNotifiers at: MolGPSDataEvents ifAbsent: [^MolNotFoundEventsNotifier new interface: MolGPSDataEvents name: nil]. +] + +{ #category : #services } +MolGNSSGalileo >> getRandomizedGNSSGalileoPosition [ + + | random | + random := Random new. + ^ (random next) * 2 @ (random next) * 2 +] + +{ #category : #services } +MolGNSSGalileo >> increaseAccuracy [ + + | nextAccuracy | + self accuracy > 1 ifTrue: [ + nextAccuracy := self accuracy - (0.1 * self accuracy). "10% better precision at each times" + nextAccuracy < 1 ifTrue: [ "stay to 1" nextAccuracy := 1 ]. + self accuracy: nextAccuracy ] +] diff --git a/src/Molecule-Examples/MolGPSDataImpl.class.st b/src/Molecule-Examples/MolGPSDataImpl.class.st index 675d8be5..6e9d9be9 100644 --- a/src/Molecule-Examples/MolGPSDataImpl.class.st +++ b/src/Molecule-Examples/MolGPSDataImpl.class.st @@ -23,18 +23,17 @@ MolGPSDataImpl >> accuracy: anObject [ ] { #category : #'life cycle' } -MolGPSDataImpl >> componentActivate [ - - "Start a thread to simulate sending of the geo position each seconds and accuracy precision" +MolGPSDataImpl >> componentActivate [ + "Start a thread to simulate sending of the geo position and accuracy precision each second" + sendCurrentPositionThread := [ - - [true] whileTrue:[ - (Delay forMilliseconds: 50) wait. - self getMolGPSDataEventsNotifier currentPositionChanged: (self getRandomizedGPSPosition). - self increaseAccuracy. - ]. - - ] forkAt: Processor userBackgroundPriority. + [ true ] whileTrue: [ + (Delay forMilliseconds: 50) wait. + self getMolGPSDataEventsNotifier + currentPositionChanged: + self getRandomizedGPSPosition. + self increaseAccuracy ] ] forkAt: + Processor userBackgroundPriority ] { #category : #'life cycle' } diff --git a/src/Molecule-Examples/MolGPSExampleLauncher.class.st b/src/Molecule-Examples/MolGPSExampleLauncher.class.st index d73daaa5..0e26804e 100644 --- a/src/Molecule-Examples/MolGPSExampleLauncher.class.st +++ b/src/Molecule-Examples/MolGPSExampleLauncher.class.st @@ -22,15 +22,18 @@ Class { { #category : #scripts } MolGPSExampleLauncher class >> start [ + - - (UIManager default confirm: 'This example displays results in a Transcript, do you want to open a transcript window ?' label: 'Molecule - GPS Example') ifTrue:[Transcript open]. - + (UIManager default + confirm: + 'This example displays results in a Transcript, do you want to open a transcript window ?' + label: 'Molecule - GPS Example') ifTrue: [ Transcript open ]. + "Start GPSDataImpl component (a Component with MolGPSData Type)" MolGPSDataImpl start. - + "Start GPSMapImpl component (a Component with MolGPSMap Type)" - MolGPSMapImpl start. + MolGPSMapImpl start ] { #category : #scripts } @@ -41,6 +44,36 @@ MolGPSExampleLauncher class >> stop [ MolComponentManager cleanUp ] +{ #category : #private } +MolGPSExampleLauncher class >> stopCurrentLaunchedComponent [ + "stops every possible component if it's launched" + + | manager component | + manager := MolComponentManager default. + + component := manager locatorServices + searchComponentTypeImplementorFor: MolGPSData. + component class stop +] + +{ #category : #scripts } +MolGPSExampleLauncher class >> swapGNSSGalileo [ + "Swap current component by MolGNSSGalileo" + +