Structure type .AsAlias list

Discuss the Firewing development environment

Structure type .AsAlias list

Postby Timbo » Sun May 24, 2015 10:19 am

I'm using a structure

Code: Select all
// Main Vars exposed to the outside world

Public Structure AllaisingArray_t                                                // All these read only
   VarArray(20) as byte
   WaterLevel as VarArray(0).AsUshort                                            // Water level as % 0-100
   CurrentNCVolume as VarArray(2).AsUshort                                       // Volume as a % to 0.01
   TotalCondeVolume as VarArray(4).AsUshort                                      // Current running volume
   CurrentStage as VarArray(6)                                                   // Current Stage Need to add values
   NCTrueValue as VarArray(7).AsUshort                                           // Last proper NC value following a full cycle
   CurrentRawLevel as VarArray(9).AsUshort                                       // Raw value of the level
   BottomOptoRaw as VarArray(11).AsUshort                                        // Last raw value of bottom opto
   TopOptoRaw as VarArray(13).AsUshort                                           // Last raw value of top opto
   BottomOpto AS VarArray(15)                                                    // 0 or 1 value of the status of the bottom opto 1 = water is seen
   TopOpto as VarArray(16)                                                       // 0 or 1 value of the status of the top opto 1 = water is seen
End Structure                                                                   

Public Dim NC_Status as AllaisingArray_t


But would like to add boolean or even bit

In the example above I have a byte in place of a bit but lines like

NC_Status.BottomOpto = LowLevelFlag

Throw up an "Incompatible type"

I know I could use
if LowLevelFlag = 1 then
NC_Status.BottomOpto = 1
Else
NC_Status.BottomOpto = 0
End if

But would love it to be a little more elegant. Also is there a list somewhere with a list of the .AsAlias types allowed?
Timbo
 
Posts: 93
Joined: Fri May 03, 2013 7:51 pm

Re: Structure type .AsAlias list

Postby Coccoliso » Sun May 24, 2015 5:06 pm

Hello Timbo,
You can use

Code: Select all
 
NC_Status.BottomOpto = CByte(LowLevelFlag)

Promotional modifier are here http://www.firewing.info/pmwiki.php?n=Reference.TypesModifiersConstants
You can refer to conversion functions here http://www.firewing.info/pmwiki.php?n=Reference.Conversion
User avatar
Coccoliso
 
Posts: 177
Joined: Sat Sep 27, 2014 10:02 am

Re: Structure type .AsAlias list

Postby Jerry Messina » Sun May 24, 2015 6:45 pm

If you don't want to reserve a byte for each flag, then another way is to pack your bits/booleans into a byte, similar to using a union...

Code: Select all
Public Structure AllaisingArray_t
   <other vars>
    flags       as VarArray(15)            // reserve a byte (holds eight bit-level vars)
    BottomOpto  as flags.bits(0)       // bit var
    TopOpto     as flags.bits(1)        // bit var
    WaterIsSeen as flags.booleans(2)   // boolean
End Structure

dim LowLevelFlag as bit       

NC_Status.flags = 0      // clear all flags

NC_Status.TopOpto = LowLevelFlag
NC_Status.BottomOpto = 0

if (NC_Status.TopOpto = 1) then
   NC_Status.WaterIsSeen = true
else
   NC_Status.WaterIsSeen = false
end if
Jerry Messina
 
Posts: 280
Joined: Thu Feb 14, 2013 10:16 am


Return to Development Environment

Who is online

Users browsing this forum: No registered users and 1 guest

cron

x