C++ style classes in SPIN
Jon87
Posts: 14
My current project shows a menu on a tv and uses a remote control to control X10 devices on or off etc.
The next step is to allow the user to add X10 devices through the menu. The main problem i see is that each X10 device will have a name, a room, a number (1 to 16) and a type (appliance or lamp). All these values need to be linked somehow
for example, if the user wants to control a microwave with X10, they would enter "microwave", select kitchen, select number 3 and select appliance.
I would then add "microwave" to the menu and if i select it, i'll have the option to turn it on or off(using the number 3 which is linked to "microwave")
I'm not 100% sure but i think in C++, a class would be used to achieve this
Any help would be greatly appreciated
Cheers
Jon
The next step is to allow the user to add X10 devices through the menu. The main problem i see is that each X10 device will have a name, a room, a number (1 to 16) and a type (appliance or lamp). All these values need to be linked somehow
for example, if the user wants to control a microwave with X10, they would enter "microwave", select kitchen, select number 3 and select appliance.
I would then add "microwave" to the menu and if i select it, i'll have the option to turn it on or off(using the number 3 which is linked to "microwave")
I'm not 100% sure but i think in C++, a class would be used to achieve this
Any help would be greatly appreciated
Cheers
Jon
Comments
What I'm saying is that you can implement your menu items by using an object, but it may not be as easy as you think and may not save you much in the way of effort. You may be better off just using an array for each type of datum (like name, room, etc.) in parallel and integrating this into your main program.
CON
· MAX_NAME_SIZE = 20
· MAX_ROOMS···· = 15
· MAX_DEVICES·· = 50
DAT
· RoomNames···· byte 0[noparse][[/noparse]MAX_NAME_SIZE*MAX_ROOMS]
· DeviceNames·· byte 0[noparse][[/noparse]MAX_NAME_SIZE*MAX_DEVICES]
· DeviceRooms·· byte 0]MAX_DEVICES]
· DeviceTypes·· byte 0[noparse][[/noparse]MAX_DEVICES]
· DeviceNumbers byte 0[noparse][[/noparse]MAX_DEVICES]
· DeviceStates· byte 0[noparse][[/noparse]MAX_DEVICES]
The names should be null-terminated, and you would access entries as follows:
· Room := DeviceRooms[noparse][[/noparse]Index]
· Type := DeviceTypes[noparse][[/noparse]Index]
· Number := DeviceNumbers[noparse][[/noparse]Index]
· State := DeviceStates[noparse][[/noparse]Index]
· DeviceName := @DeviceNames + (Index * MAX_NAME_SIZE)
· RoomName := @RoomNames + (Room * MAX_NAME_SIZE)
Dave
SPIN objects are not objects in the sense this term is used in C++. In other languages SPIN objects would be called "program units", "modules" or "packages" - they provide encapsulation of code and data and define an interface but are not themeselves a data type.
If you are coming from C++ you may get a better grip on SPIN if you think of it as a modular language rather than an object-oriented one.
Ross.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Catalina - a FREE C compiler for the Propeller - see Catalina