Skip to content

Commit

Permalink
Merge pull request #117 from OpenSmock/gps-example-dev
Browse files Browse the repository at this point in the history
Gps example dev
  • Loading branch information
labordep authored Oct 24, 2023
2 parents 7850b5b + 01a18f3 commit fa876e4
Show file tree
Hide file tree
Showing 25 changed files with 595 additions and 323 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
Class {
#name : #PyMolApp,
#name : #MolGeoPosCartographyApp,
#superclass : #BlElement,
#instVars : [
'map',
'switch'
],
#category : #'Molecule-Examples-Pyramid-Incubator'
#category : #'Molecule-Examples-GeoPosMap-Incubator'
}

{ #category : #'instance creation' }
PyMolApp class >> open [
MolGeoPosCartographyApp class >> open [

<script>
| element |
Expand All @@ -18,24 +18,26 @@ PyMolApp class >> open [
]

{ #category : #initialization }
PyMolApp >> initialize [
MolGeoPosCartographyApp >> initialize [

| rope1 rope2 label1 label2 |
super initialize.
self size: 400 @ 470.

switch := PyMolSwitch new.
switch := MolSwitchButtonElement new.
switch position: 152.5 @ 420.

switch whenOffDo: [
MolGPSDataImpl stop.
MolGPSHardware start ].
MolGNSSGPS stop.
MolGNSSGPSInaccurate start ].

switch whenOnDo: [
MolGPSHardware stop.
MolGPSDataImpl start ].
MolGNSSGPSInaccurate stop.
MolGNSSGPS start ].

MolGPSHardware start.
PyMolMap start.
map := MolUtils instanceOf: PyMolMap.
MolGNSSGPSInaccurate start.
MolGeoPosMapReicever start.
map := MolUtils instanceOf: MolGeoPosMapReicever.

rope1 := 'Accurate GPS' asRopedText.
rope1 attribute: (BlFontSizeAttribute size: 20).
Expand All @@ -53,8 +55,8 @@ PyMolApp >> initialize [
self addChild: label2
]

{ #category : #'as yet unclassified' }
PyMolApp >> open [
{ #category : #initialization }
MolGeoPosCartographyApp >> open [

| space |
space := BlSpace new
Expand All @@ -68,8 +70,8 @@ PyMolApp >> open [
do: [ :evt | MolComponentManager cleanUp ].
space when: BlKeyDownEvent do: [ :evt |
evt key = KeyboardKey F12 ifTrue: [
(self canPerform: #pyramidOpenInEditor) ifTrue: [
self pyramidOpenInEditor ] ] ].
(self canPerform: #editWithPyramid) ifTrue: [
self editWithPyramid ] ] ].

space enqueueTask: (BlTaskAction new
action: [ space center ];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
Class {
#name : #PyMolMap,
#name : #MolGeoPosMapReicever,
#superclass : #BlElement,
#traits : 'MolGPSMap + MolGPSDataEvents + MolComponentImpl',
#classTraits : 'MolGPSMap classTrait + MolGPSDataEvents classTrait + MolComponentImpl classTrait',
#traits : 'MolGeoPosReceiverType + MolGeoPosEquipmentEvents + MolComponentImpl',
#classTraits : 'MolGeoPosReceiverType classTrait + MolGeoPosEquipmentEvents classTrait + MolComponentImpl classTrait',
#instVars : [
'pointerV',
'pointerH',
'pointer'
],
#category : #'Molecule-Examples-Pyramid-Incubator'
#category : #'Molecule-Examples-GeoPosMap-Incubator'
}

{ #category : #'pyramid-serialized-bloc' }
PyMolMap class >> pystonSpec [
MolGeoPosMapReicever class >> pystonSpec [
"This class has been generated using Pyramid.
By: YannLEGOFF
Expand Down Expand Up @@ -364,32 +364,32 @@ PyMolMap class >> pystonSpec [
]'
]

{ #category : #'as yet unclassified' }
PyMolMap >> buildElements [
{ #category : #initialization }
MolGeoPosMapReicever >> buildElements [

self hasChildren ifTrue: [ self removeChildren ].
self addChildren: self class pystonSpec materializeAsBlElement
]

{ #category : #'life cycle' }
PyMolMap >> componentActivate [
MolGeoPosMapReicever >> componentActivate [

self getMolGPSDataEventsSubscriber subscribe: self
self getMolGeoPosEquipmentEventsSubscriber subscribe: self
]

{ #category : #'life cycle' }
PyMolMap >> componentPassivate [
MolGeoPosMapReicever >> componentPassivate [

self space ifNotNil: [ :s | s close ].
self getMolGPSDataEventsSubscriber unsubscribe: self
self getMolGeoPosEquipmentEventsSubscriber unsubscribe: self
]

{ #category : #events }
PyMolMap >> currentPositionChanged: aGeoPosition [
MolGeoPosMapReicever >> currentPositionChanged: aGeoPosition [

| adjustedPosition radius |
adjustedPosition := aGeoPosition * 50 asPoint + 150 asPoint.
radius := self getMolGPSDataServicesProvider getAccuracyRadiusInMeters asPoint.
radius := self getMolGeoPosEquipmentServicesProvider getAccuracyRadiusInMeters asPoint.

pointerV position: adjustedPosition x @ 0.
pointerH position: 0 @ adjustedPosition y.
Expand All @@ -399,31 +399,31 @@ PyMolMap >> currentPositionChanged: aGeoPosition [
]

{ #category : #'component accessing' }
PyMolMap >> getMolGPSDataEventsSubscriber [
MolGeoPosMapReicever >> getMolGeoPosEquipmentEventsSubscriber [
| eventsSymbol eventsSubscriber itf |
itf := MolGPSDataEvents.
itf := MolGeoPosEquipmentEvents.
eventsSymbol := self eventsSubscribers at: itf ifAbsent: [^MolNotFoundEventsSubscriber new interface: itf name: nil].
eventsSymbol isCollection
ifTrue:
[eventsSubscriber := MolComponentManager default locatorServices
searchEventsSubscriberFor: MolGPSDataEvents named: eventsSymbol ].
searchEventsSubscriberFor: MolGeoPosEquipmentEvents named: eventsSymbol ].
^eventsSubscriber
]

{ #category : #'component accessing' }
PyMolMap >> getMolGPSDataServicesProvider [
MolGeoPosMapReicever >> getMolGeoPosEquipmentServicesProvider [
| servicesSymbol servicesProvider itf |

itf := MolGPSDataServices.
itf := MolGeoPosEquipmentServices.
servicesSymbol := self servicesProviders at: itf ifAbsent: [nil].
(servicesSymbol isNil or:[servicesSymbol isSymbol not]) ifTrue: [ ^ MolNotFoundServicesProvider new interface: itf name: nil ].

servicesProvider := MolComponentManager default locatorServices searchServicesProviderFor: MolGPSDataServices named: servicesSymbol.
servicesProvider := MolComponentManager default locatorServices searchServicesProviderFor: MolGeoPosEquipmentServices named: servicesSymbol.
^servicesProvider
]

{ #category : #'life cycle' }
PyMolMap >> initialize [
MolGeoPosMapReicever >> initialize [

super initialize.
self buildElements.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
Class {
#name : #PyMolSwitch,
#name : #MolSwitchButtonElement,
#superclass : #BlElement,
#instVars : [
'indicator',
'state',
'whenOffDo',
'whenOnDo'
],
#category : #'Molecule-Examples-Pyramid-Incubator'
#category : #'Molecule-Examples-GeoPosMap-Incubator'
}

{ #category : #'pyramid-serialized-bloc' }
PyMolSwitch class >> pystonSpec [
MolSwitchButtonElement class >> pystonSpec [
"This class has been generated using Pyramid.
By: YannLEGOFF
Expand Down Expand Up @@ -326,15 +326,15 @@ PyMolSwitch class >> pystonSpec [
]'
]

{ #category : #'as yet unclassified' }
PyMolSwitch >> buildElements [
{ #category : #initialization }
MolSwitchButtonElement >> buildElements [

self hasChildren ifTrue: [ self removeChildren ].
self addChildren: self class pystonSpec materializeAsBlElement
]

{ #category : #initialization }
PyMolSwitch >> initialize [
MolSwitchButtonElement >> initialize [

super initialize.
self buildElements.
Expand All @@ -346,13 +346,13 @@ PyMolSwitch >> initialize [
]

{ #category : #accessing }
PyMolSwitch >> state [
MolSwitchButtonElement >> state [

^ state
]

{ #category : #accessing }
PyMolSwitch >> state: aBoolean [
MolSwitchButtonElement >> state: aBoolean [

state = aBoolean ifTrue: [ ^ self ].
state := aBoolean.
Expand All @@ -372,25 +372,25 @@ PyMolSwitch >> state: aBoolean [
]

{ #category : #accessing }
PyMolSwitch >> whenOffDo [
MolSwitchButtonElement >> whenOffDo [

^ whenOffDo
]

{ #category : #accessing }
PyMolSwitch >> whenOffDo: aBlock [
MolSwitchButtonElement >> whenOffDo: aBlock [

whenOffDo:= aBlock
]

{ #category : #accessing }
PyMolSwitch >> whenOnDo [
MolSwitchButtonElement >> whenOnDo [

^ whenOnDo
]

{ #category : #accessing }
PyMolSwitch >> whenOnDo: aBlock [
MolSwitchButtonElement >> whenOnDo: aBlock [

whenOnDo := aBlock
]
1 change: 1 addition & 0 deletions src/Molecule-Examples-GeoPosMap-Incubator/package.st
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Package { #name : #'Molecule-Examples-GeoPosMap-Incubator' }
1 change: 0 additions & 1 deletion src/Molecule-Examples-Pyramid-Incubator/package.st

This file was deleted.

19 changes: 11 additions & 8 deletions src/Molecule-Examples/ManifestMoleculeExamples.class.st
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"
We give an overview of Molecule through two examples :
- Clock System
- GPS
- Geographical Position
#Clock System
Before running the example open the Transcript, the example results is showed on the Transcript window.
Expand All @@ -11,15 +11,18 @@ MolMyClockSystem startAlarmExample.
This system uses 4 components: a server time send global hour to a clock. The clock send local hour to alarms and to final user (which could be an UI). The final user can change the parameters of the system as alarm time or set manual time for the clock. The alarm is subscribed to clock time, and sounds when it is time.
This system provides a global example of the use of components.
#GPS
Before running the example open the Transcript, the example results is showed on the Transcript window.
#Geographical Position
The example results are showing on the Transcript window.
MolGeoPosExampleLauncher start.
More details about examples in the comment of MolGeoPosExampleLauncher.
We program a component application that connects to a Global Positioning System (GPS) and displays the GPS received position on a view map (just fictitious).
The GPS and Map are implemented as Molecule components.
MolGPSExampleLauncher start.
More details about examples in the comment of MolGPSExampleLauncher.
There are others available equipment as Galileo, GSM or WiFi, which provide geographical position.
First we program a component application that connects to a Global Positioning System (GPS) hardware and displays the GPS data on a view map (just fictitious).
The GPS data and view map are implemented as Molecule components.
In a second way, we reuse an existing non-component class in our Molecule application (MolGPSHardware).
We reuse an existing non-component class in our Molecule application (MolGNSSGPSInnacurate).
To do so, we augment this class with component behavior.
"
Class {
Expand Down
83 changes: 83 additions & 0 deletions src/Molecule-Examples/MolGNSSGPS.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
Class {
#name : #MolGNSSGPS,
#superclass : #MolAbstractComponentImpl,
#traits : 'MolGeoPosEquipmentType + MolGeoPosEquipmentServices',
#classTraits : 'MolGeoPosEquipmentType classTrait + MolGeoPosEquipmentServices classTrait',
#instVars : [
'accuracy',
'sendCurrentPositionThread'
],
#category : #'Molecule-Examples-Geographical Position Example'
}

{ #category : #accessing }
MolGNSSGPS >> accuracy [

^ accuracy
]

{ #category : #accessing }
MolGNSSGPS >> accuracy: anObject [

accuracy := anObject
]

{ #category : #'life cycle' }
MolGNSSGPS >> componentActivate [
"Start a thread to simulate sending of the geo position and accuracy precision each second"

sendCurrentPositionThread := [
[ true ] whileTrue: [
(Delay forMilliseconds: 50) wait.
self getMolGeoPosEquipmentEventsNotifier
currentPositionChanged:
self getRandomizedGPSPosition.
self increaseAccuracy ] ] forkAt:
Processor userBackgroundPriority
]

{ #category : #'life cycle' }
MolGNSSGPS >> componentInitialize [

"Set starting accuracy"

self accuracy: 1000
]

{ #category : #'life cycle' }
MolGNSSGPS >> componentPassivate [

sendCurrentPositionThread ifNotNil:[ :e | e terminate ].
sendCurrentPositionThread := nil.
]

{ #category : #services }
MolGNSSGPS >> getAccuracyRadiusInMeters [
"Get and return the accuracy of the GPS depending quality of signal and quantity of connected satellites"

^self accuracy
]

{ #category : #'component accessing' }
MolGNSSGPS >> getMolGeoPosEquipmentEventsNotifier [
^self eventsNotifiers at: MolGeoPosEquipmentEvents ifAbsent: [^MolNotFoundEventsNotifier new interface: MolGeoPosEquipmentEvents name: nil].
]

{ #category : #private }
MolGNSSGPS >> getRandomizedGPSPosition [

| random |
random := Random new.
^ random next @ random next
]

{ #category : #private }
MolGNSSGPS >> 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
]
]
Loading

0 comments on commit fa876e4

Please sign in to comment.